perf: display optimization

This commit is contained in:
2025-02-11 22:25:57 +01:00
parent 3d57868e9d
commit 11781c0789
3 changed files with 84 additions and 36 deletions

View File

@ -13,47 +13,48 @@ const (
// TurnCursor turns the cursor on and off according to the parameter.
func TurnCursor(onOff CursorFlag) {
if onOff == CursorOn {
fmt.Printf("\033[?25h")
} else {
fmt.Printf("\033[?25l")
switch onOff {
case CursorOn:
fmt.Print("\033[?25h")
case CursorOff:
fmt.Print("\033[?25l")
}
}
// ClearScreen clears current screen.
func ClearScreen() {
fmt.Printf("\033[2J")
fmt.Print("\033[2J")
}
// ResetTerminal resets terminal (ESC c)
func ResetTerminal() {
fmt.Printf("\033c")
fmt.Print("\033c")
}
// GoHome moves cursor to the home position (upper left corner)
func GoHome() {
fmt.Printf("\033[H")
fmt.Print("\033[H")
}
// SaveCursor saves curent position of the SaveCursor
func SaveCursor() {
fmt.Printf("\033[s")
fmt.Print("\033[s")
}
// RestoreCursor restore cursor to the position saved previously with SaveCursor().
func RestoreCursor() {
fmt.Printf("\033[u")
fmt.Print("\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")
fmt.Print("\033[?1049h")
}
// DiableAlternateScreen switches the terminal to the primary screen.
func DisableAlternateScreen() {
fmt.Printf("\033[?1049l")
fmt.Print("\033[?1049l")
}
// StartFullscreen saves the cursor, enables alternate screen and clears it.