Do some minor linting fixes
All checks were successful
timw4mail/gilo/pipeline/head This commit looks good

This commit is contained in:
Timothy Warren 2021-05-20 11:45:15 -04:00
parent c378b712d3
commit 1b9c1744aa
3 changed files with 16 additions and 14 deletions

View File

@ -1,19 +1,22 @@
// Package gilo Point struct // Package gilo Point struct
package gilo package gilo
// Point an x,y coordinate
type Point struct { type Point struct {
X int X int
Y int Y int
} }
// DefaultPoint creates a Point at 0,0
func DefaultPoint() *Point { func DefaultPoint() *Point {
return &Point{0, 0} return &Point{0, 0}
} }
// NewPoint creates a new Point
func NewPoint(x, y int) *Point { func NewPoint(x, y int) *Point {
return &Point{x, y} return &Point{x, y}
} }
// Clone create a new point from an old one
func (p *Point) Clone() *Point { func (p *Point) Clone() *Point {
return &Point{p.X, p.Y} return &Point{p.X, p.Y}
} }

View File

@ -1,4 +1,4 @@
// ANSI Terminal Escape Codes and helpers // Package terminal ANSI Terminal Escape Codes and helpers
package terminal package terminal
import "fmt" import "fmt"
@ -10,10 +10,10 @@ import "fmt"
const EscPrefix = "\x1b[" const EscPrefix = "\x1b["
const ( const (
// Clears the line after the escape sequence // ClearLine Clears the line after the escape sequence
ClearLine = EscPrefix + "K" ClearLine = EscPrefix + "K"
// Clears the entire screen // ClearScreen Clears the entire screen
ClearScreen = EscPrefix + "2J" ClearScreen = EscPrefix + "2J"
) )
@ -22,16 +22,15 @@ const (
HideCursor = EscPrefix + "?25l" HideCursor = EscPrefix + "?25l"
ShowCursor = EscPrefix + "?25h" ShowCursor = EscPrefix + "?25h"
// Reports cursor location to stdout // LocateCursor Reports cursor location to stdout
LocateCursor = EscPrefix + "6n" LocateCursor = EscPrefix + "6n"
// Moves cursor to default position (1,1) // ResetCursor Moves cursor to default position (1,1)
ResetCursor = EscPrefix + "H" ResetCursor = EscPrefix + "H"
) )
// Color sequences // Color sequences
const ( const (
// Background
BGBlack = EscPrefix + "40m" BGBlack = EscPrefix + "40m"
BGRed = EscPrefix + "41m" BGRed = EscPrefix + "41m"
BGGreen = EscPrefix + "42m" BGGreen = EscPrefix + "42m"
@ -49,7 +48,6 @@ const (
BGBrightCyan = EscPrefix + "106m" BGBrightCyan = EscPrefix + "106m"
BGBrightWhite = EscPrefix + "107m" BGBrightWhite = EscPrefix + "107m"
// Foreground
FGBlack = EscPrefix + "30m" FGBlack = EscPrefix + "30m"
FGRed = EscPrefix + "31m" FGRed = EscPrefix + "31m"
FGGreen = EscPrefix + "32m" FGGreen = EscPrefix + "32m"
@ -67,7 +65,6 @@ const (
FGBrightCyan = EscPrefix + "96m" FGBrightCyan = EscPrefix + "96m"
FGBrightWhite = EscPrefix + "97m" FGBrightWhite = EscPrefix + "97m"
// Defaults
DefaultBGColor = EscPrefix + "49m" DefaultBGColor = EscPrefix + "49m"
DefaultFGColor = EscPrefix + "39m" DefaultFGColor = EscPrefix + "39m"
@ -79,19 +76,19 @@ const (
// !Helpers // !Helpers
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Generate RGB color ansi escape sequences // RGBColor Generate RGB color ansi escape sequences
func RGBColor(r, g, b int) string { func RGBColor(r, g, b int) string {
return Code("48;2;%d;%d;%dm", r, g, b) 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 { func Code(s string, a ...interface{}) string {
str := fmt.Sprintf(s, a...) str := fmt.Sprintf(s, a...)
return EscPrefix + str 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 { func MoveCursor(x int, y int) string {
// Allow 0-based indexing, the terminal code is 1-based // Allow 0-based indexing, the terminal code is 1-based
x += 1 x += 1

View File

@ -6,18 +6,20 @@ import (
"os" "os"
) )
// Screen the size of the screen in rows and columns
type Screen struct { type Screen struct {
Rows int Rows int
Cols 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 { func Size() *Screen {
cols := 80 cols := 80
rows := 24 rows := 24
var err interface{}
// Try the syscall first // 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 { if err == nil {
return &Screen{rows, cols} return &Screen{rows, cols}
} }