25 lines
502 B
Go
25 lines
502 B
Go
// ANSI Terminal Escape Codes and helpers
|
|
package terminal
|
|
|
|
import "fmt"
|
|
|
|
const ClearLine = "\x1b[K"
|
|
const ClearScreen = "\x1b[2J"
|
|
|
|
const HideCursor = "\x1b[?25l"
|
|
const ShowCursor = "\x1b[?25h"
|
|
const ResetCursor = "\x1b[H"
|
|
|
|
func Code (s string) string {
|
|
return fmt.Sprintf("\x1b[%s", s)
|
|
}
|
|
|
|
|
|
// 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
|
|
y += 1
|
|
|
|
return Code(fmt.Sprintf("%d;%dH", y, x))
|
|
} |