Adding utilities file

Gonna keep reusing these text scanning and screen clearing functions as
much as I can
This commit is contained in:
raul 2024-03-11 21:46:09 +01:00
parent 707556cb5a
commit 3e8313b118
1 changed files with 24 additions and 0 deletions

View File

@ -1,8 +1,11 @@
package main package main
import ( import (
"bufio"
"fmt" "fmt"
"os" "os"
"runtime"
"strings"
) )
func catchErr(err error) (errHappened bool) { func catchErr(err error) (errHappened bool) {
@ -14,3 +17,24 @@ func catchErr(err error) (errHappened bool) {
} }
return errHappened return errHappened
} }
func clear() {
fmt.Print("\033[H\033[2J")
}
func scanLine() (line string) {
switch runtime.GOOS {
case "linux":
in := bufio.NewReader(os.Stdin)
lineNew, err := in.ReadString('\n')
catchErr(err)
line = strings.Trim(lineNew, "\n")
case "windows":
in := bufio.NewReader(os.Stdin)
lineNew, err := in.ReadString('\r')
catchErr(err)
line = strings.Trim(lineNew, "\r")
}
return line
}