2021-03-25 12:46:53 -04:00
|
|
|
// ANSI Terminal Escape Codes and helpers
|
2021-03-24 16:23:17 -04:00
|
|
|
package terminal
|
2021-03-24 15:09:28 -04:00
|
|
|
|
|
|
|
import "fmt"
|
|
|
|
|
2021-03-24 15:20:57 -04:00
|
|
|
const ClearLine = "\x1b[K"
|
2021-03-24 15:09:28 -04:00
|
|
|
const ClearScreen = "\x1b[2J"
|
2021-03-24 15:20:57 -04:00
|
|
|
|
|
|
|
const HideCursor = "\x1b[?25l"
|
|
|
|
const ShowCursor = "\x1b[?25h"
|
2021-03-24 15:09:28 -04:00
|
|
|
const ResetCursor = "\x1b[H"
|
|
|
|
|
2021-03-25 13:19:22 -04:00
|
|
|
const KeyArrowUp = "\x1b[A"
|
|
|
|
const KeyArrowDown = "\x1b[B"
|
|
|
|
const KeyArrowRight = "\x1b[C"
|
|
|
|
const KeyArrowLeft = "\x1b[D"
|
|
|
|
|
2021-03-24 15:09:28 -04:00
|
|
|
func Code (s string) string {
|
|
|
|
return fmt.Sprintf("\x1b[%s", s)
|
2021-03-25 12:46:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 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))
|
2021-03-24 15:09:28 -04:00
|
|
|
}
|