chore: bump go version, comments, small fixes

This commit is contained in:
Arek 2025-02-11 22:25:39 +01:00
parent 495a7cce20
commit 3d57868e9d
3 changed files with 17 additions and 3 deletions

View File

@ -34,6 +34,7 @@ func main() {
loop := func() {
ticker := time.NewTicker(250 * time.Millisecond)
defer ticker.Stop()
for {
term.GoHome()
front.PrintMe()

2
go.mod
View File

@ -1,3 +1,3 @@
module gol
go 1.19
go 1.21

View File

@ -2,13 +2,16 @@ package term
import "fmt"
// CursorFlag is used as a parameter to function TurnCursor and
// describes if cursor should be displayed or not.
type CursorFlag bool
const (
CursorOn CursorFlag = true
CursorOff CursorFlag = false
CursorOn CursorFlag = true // Cursor should be visible
CursorOff CursorFlag = false // Cursor should be hidden
)
// TurnCursor turns the cursor on and off according to the parameter.
func TurnCursor(onOff CursorFlag) {
if onOff == CursorOn {
fmt.Printf("\033[?25h")
@ -17,40 +20,50 @@ func TurnCursor(onOff CursorFlag) {
}
}
// ClearScreen clears current screen.
func ClearScreen() {
fmt.Printf("\033[2J")
}
// ResetTerminal resets terminal (ESC c)
func ResetTerminal() {
fmt.Printf("\033c")
}
// GoHome moves cursor to the home position (upper left corner)
func GoHome() {
fmt.Printf("\033[H")
}
// SaveCursor saves curent position of the SaveCursor
func SaveCursor() {
fmt.Printf("\033[s")
}
// RestoreCursor restore cursor to the position saved previously with SaveCursor().
func RestoreCursor() {
fmt.Printf("\033[u")
}
// EnableAlternateScreen switches the terminal to the alternative screen.
// The alternative screen doesn't have the scroll buffer.
func EnableAlternateScreen() {
fmt.Printf("\033[?1049h")
}
// DiableAlternateScreen switches the terminal to the primary screen.
func DisableAlternateScreen() {
fmt.Printf("\033[?1049l")
}
// StartFullscreen saves the cursor, enables alternate screen and clears it.
func StartFullscreen() {
SaveCursor()
EnableAlternateScreen()
ClearScreen()
}
// FinishFullscreen returns to the primary screen and restores the cursor.
func FinishFullscreen() {
DisableAlternateScreen()
RestoreCursor()