diff --git a/internal/gilo/point.go b/internal/gilo/point.go index 3eafe38..b99b42c 100644 --- a/internal/gilo/point.go +++ b/internal/gilo/point.go @@ -1,19 +1,22 @@ // Package gilo Point struct package gilo +// Point an x,y coordinate type Point struct { X int Y int } - +// DefaultPoint creates a Point at 0,0 func DefaultPoint() *Point { return &Point{0, 0} } +// NewPoint creates a new Point func NewPoint(x, y int) *Point { return &Point{x, y} } +// Clone create a new point from an old one func (p *Point) Clone() *Point { return &Point{p.X, p.Y} } diff --git a/terminal/ansi.go b/terminal/ansi.go index 9095821..1c32f82 100644 --- a/terminal/ansi.go +++ b/terminal/ansi.go @@ -1,4 +1,4 @@ -// ANSI Terminal Escape Codes and helpers +// Package terminal ANSI Terminal Escape Codes and helpers package terminal import "fmt" @@ -10,10 +10,10 @@ import "fmt" const EscPrefix = "\x1b[" const ( - // Clears the line after the escape sequence + // ClearLine Clears the line after the escape sequence ClearLine = EscPrefix + "K" - // Clears the entire screen + // ClearScreen Clears the entire screen ClearScreen = EscPrefix + "2J" ) @@ -22,16 +22,15 @@ const ( HideCursor = EscPrefix + "?25l" ShowCursor = EscPrefix + "?25h" - // Reports cursor location to stdout + // LocateCursor Reports cursor location to stdout LocateCursor = EscPrefix + "6n" - // Moves cursor to default position (1,1) + // ResetCursor Moves cursor to default position (1,1) ResetCursor = EscPrefix + "H" ) // Color sequences const ( - // Background BGBlack = EscPrefix + "40m" BGRed = EscPrefix + "41m" BGGreen = EscPrefix + "42m" @@ -49,7 +48,6 @@ const ( BGBrightCyan = EscPrefix + "106m" BGBrightWhite = EscPrefix + "107m" - // Foreground FGBlack = EscPrefix + "30m" FGRed = EscPrefix + "31m" FGGreen = EscPrefix + "32m" @@ -67,7 +65,6 @@ const ( FGBrightCyan = EscPrefix + "96m" FGBrightWhite = EscPrefix + "97m" - // Defaults DefaultBGColor = EscPrefix + "49m" DefaultFGColor = EscPrefix + "39m" @@ -79,19 +76,19 @@ const ( // !Helpers // ---------------------------------------------------------------------------- -// Generate RGB color ansi escape sequences +// RGBColor Generate RGB color ansi escape sequences func RGBColor(r, g, b int) string { return Code("48;2;%d;%d;%dm", r, g, b) } -// Add the ANSI escape code prefix to the relevant escape code +// Code Add the ANSI escape code prefix to the relevant escape code func Code(s string, a ...interface{}) string { str := fmt.Sprintf(s, a...) return EscPrefix + str } -// Generate the escape sequence to move the terminal cursor to the 0-based coordinate +// MoveCursor Generate the escape sequence to move the terminal cursor to the 0-based coordinate func MoveCursor(x int, y int) string { // Allow 0-based indexing, the terminal code is 1-based x += 1 diff --git a/terminal/size.go b/terminal/size.go index 9d88a5b..cd355d2 100644 --- a/terminal/size.go +++ b/terminal/size.go @@ -6,18 +6,20 @@ import ( "os" ) +// Screen the size of the screen in rows and columns type Screen struct { Rows int Cols int } -// Get the size of the terminal in rows and columns +// Size Get the size of the terminal in rows and columns func Size() *Screen { cols := 80 rows := 24 + var err interface{} // Try the syscall first - cols, rows, err := term.GetSize(int(os.Stdin.Fd())) + cols, rows, err = term.GetSize(int(os.Stdin.Fd())) if err == nil { return &Screen{rows, cols} }