Adding utilities file
Gonna keep reusing these text scanning and screen clearing functions as much as I can
This commit is contained in:
parent
707556cb5a
commit
3e8313b118
24
tools.go
24
tools.go
|
@ -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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue