diff options
| author | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-07-22 10:24:21 +0300 |
|---|---|---|
| committer | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-07-22 10:24:21 +0300 |
| commit | 1f15111c6e44ea7e855fadc187a19234640e161c (patch) | |
| tree | 978254e246e5cba565463549f2715513a48c5762 /go-src/csi | |
| parent | 4f9a8920b080e6aee7e19e394654bf879c5759e2 (diff) | |
| download | ctfc-1f15111c6e44ea7e855fadc187a19234640e161c.tar ctfc-1f15111c6e44ea7e855fadc187a19234640e161c.tar.gz ctfc-1f15111c6e44ea7e855fadc187a19234640e161c.zip | |
Improved structure and added comments
Diffstat (limited to 'go-src/csi')
| -rw-r--r-- | go-src/csi/csi.go | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/go-src/csi/csi.go b/go-src/csi/csi.go new file mode 100644 index 0000000..100db59 --- /dev/null +++ b/go-src/csi/csi.go @@ -0,0 +1,90 @@ +package csi + +import ( + "fmt" + "os" + "os/exec" + "runtime" +) + +const ( + ansiCUUf = "\033[%vA" // Cursor (move) Up, formatted version (expects to be given a number) + ansiCUDf = "\033[%vB" // Cursor (move) Down, formated version (expects to be given a number) + ansiCUFf = "\033[%vC" // Cursor (move) Forward (to the right), formatted version (expects to be given a number) + + ansiCUU = "\033[A" // Cursor (move) Up + ansiCUD = "\033[B" // Cursor (move) Down + ansiCUF = "\033[C" // Cursor (move) Forward (to the right) + ansiCNL = "\033[E" // Cursor (move) Next Line + ansiED = "\033[2J" // Erase in Display (clears entire screen) + ansiEL = "\033[K" // Erase in Line (clears from cursor to end of line) + + ansiSCP = "\033[s" // Save Current Cursor Position + ansiRCP = "\033[u" // Restore Saved Cursor Position +) + +func MoveCursorUpN(times int) { + fmt.Printf(ansiCUUf, times) +} + +func MoveCursorDownN(times int) { + fmt.Printf(ansiCUDf, times) +} + +func MoveCursorRightN(times int) { + fmt.Printf(ansiCUFf, times) +} + +func MoveCursorUp() { + fmt.Print(ansiCUU) +} + +func MoveCursorDown() { + fmt.Print(ansiCUD) +} + +func MoveCursorRight() { + fmt.Printf(ansiCUF) +} + +func MoveCursorToBeginningOfLine() { + fmt.Print(ansiCNL) +} + +func ClearLine() { + fmt.Print(ansiEL) +} + +var blockClearing = false + +func ClearScreen() { + if blockClearing { + blockClearing = false + return + } + + if runtime.GOOS == "windows" { + cmd := exec.Command("cmd", "/c", "cls") + cmd.Stdout = os.Stdout + cmd.Run() + } else { + fmt.Println(ansiED) + } +} + +// The next time that ClearScreen is called, it won't clear the screen +func BlockClearScreenNextTime() { + blockClearing = true +} + +func EraseToEndOfLine() { + fmt.Print(ansiEL) +} + +func SaveCursorPosition() { + fmt.Print(ansiSCP) +} + +func RestoreCursorPosition() { + fmt.Print(ansiRCP) +} |
