package main import ( "fmt" "github.com/pkg/term" ) type PieceType int const ( IPiece PieceType = iota JPiece LPiece SPiece ZPiece TPiece OPiece ) type Point struct { X, Y int } type Piece struct { Type PieceType RelX int RelY int Layout []Point Lock int } type Bag []Piece type Field [20][10]bool func (f Field) String() (output string) { var toprow [10]bool var top bool for _, row := range f { top = !top for i, block := range row { if top { toprow[i] = block continue } switch { case toprow[i] && block: output += "\u2588" case toprow[i] && !block: output += "\u2580" case !toprow[i] && block: output += "\u2584" default: output += " " } } if !top { output += "\n" } } return output } func main() { var f Field fmt.Print("\033[2J") // Clear screen for i := 0; i < 200; i++ { if (i+i/10)%2 == 0 { f[i/10][i%10] = true } } for { fmt.Print("\033[0;0H") // Position to 0,0 fmt.Println(f.String()) t, _ := term.Open("/dev/tty") term.RawMode(t) key := make([]byte, 3) t.Read(key) t.Restore() t.Close() switch key[0] { case 27: // Escape, read the arrow key pressed fmt.Print(string(key[2])) case 'q': fmt.Println("...that was exciting!") return } } }