Commit f6d95a25 authored by Jonny Schäfer's avatar Jonny Schäfer
Browse files

Fix terminal bug by adding print aliases

parent 040ee69c
...@@ -10,16 +10,16 @@ import ( ...@@ -10,16 +10,16 @@ import (
// cliLineWrap enables or disables line wrapping // cliLineWrap enables or disables line wrapping
func cliLineWrap(enabled bool) { func cliLineWrap(enabled bool) {
if enabled { if enabled {
fmt.Print("\x1b[?7h") cliPrint("\x1b[?7h")
} else { } else {
fmt.Print("\x1b[?7l") cliPrint("\x1b[?7l")
} }
} }
// cliReset resets the terminal to the defaults // cliReset resets the terminal to the defaults
func cliReset() { func cliReset() {
cliLineWrap(true) cliLineWrap(true)
fmt.Print("\x1bc") cliPrint("\x1bc")
} }
// cliClear clears the screen // cliClear clears the screen
...@@ -31,17 +31,17 @@ func cliClear() { ...@@ -31,17 +31,17 @@ func cliClear() {
// cliClear clears the screen downwards beginning at the cursor position // cliClear clears the screen downwards beginning at the cursor position
func cliClearDown() { func cliClearDown() {
fmt.Print("\x1b[J") cliPrint("\x1b[J")
} }
// cliClear clears the screen right beginning at the cursor position // cliClear clears the screen right beginning at the cursor position
func cliClearRight() { func cliClearRight() {
fmt.Print("\x1b[K") cliPrint("\x1b[K")
} }
// cliHome sets the cursor to the origin // cliHome sets the cursor to the origin
func cliHome() { func cliHome() {
fmt.Print("\x1b[;H") cliPrint("\x1b[;H")
} }
// cliPrompt reads a line from stdin // cliPrompt reads a line from stdin
...@@ -59,17 +59,17 @@ func cliPrompt() string { ...@@ -59,17 +59,17 @@ func cliPrompt() string {
// cliStatus writes the current status to the screen // cliStatus writes the current status to the screen
func cliStatus(status string) { func cliStatus(status string) {
cliHome() cliHome()
fmt.Println() cliPrintln()
cliClearRight() // erase status cliClearRight() // erase status
fmt.Println("\x1b[44;37m" + status + "\x1b[0m") cliPrintln("\x1b[44;37m" + status + "\x1b[0m")
} }
// cliStatus writes the current error status to the screen // cliStatus writes the current error status to the screen
func cliStatusError(status string) { func cliStatusError(status string) {
cliHome() cliHome()
fmt.Println() cliPrintln()
cliClearRight() // erase status cliClearRight() // erase status
fmt.Println("\x1b[1;41;37m" + status + "\x1b[0m") cliPrintln("\x1b[1;41;37m" + status + "\x1b[0m")
} }
// cliList writes a table to the screen. The line can be highlighted by // cliList writes a table to the screen. The line can be highlighted by
...@@ -95,22 +95,22 @@ func cliTable(highlight int, columns ...[]string) { ...@@ -95,22 +95,22 @@ func cliTable(highlight int, columns ...[]string) {
for i := 0; i < lines; i++ { for i := 0; i < lines; i++ {
for n, c := range columns { for n, c := range columns {
if i == highlight { if i == highlight {
fmt.Printf("\x1b[%vm", 31) // red line cliPrintf("\x1b[%vm", 31) // red line
} else { } else {
fmt.Printf("\x1b[%vm", ((n+1)%2)*34) // blue columns cliPrintf("\x1b[%vm", ((n+1)%2)*34) // blue columns
} }
if i < len(c) { if i < len(c) {
fmt.Print(c[i] + strings.Repeat(" ", 1+space[n]-cliRealCount(c[i]))) // not good cliPrint(c[i] + strings.Repeat(" ", 1+space[n]-cliRealCount(c[i]))) // not good
} else { } else {
fmt.Print(strings.Repeat(" ", 1+space[n])) cliPrint(strings.Repeat(" ", 1+space[n]))
} }
} }
if i != lines - 1 { if i != lines - 1 {
fmt.Println() cliPrintln()
} }
} }
fmt.Print("\x1b[0m") cliPrint("\x1b[0m")
} }
// cliTrimLength trims the given text to the rune count and indicates // cliTrimLength trims the given text to the rune count and indicates
...@@ -142,3 +142,14 @@ func cliRealCount(in string) (glyphs int) { ...@@ -142,3 +142,14 @@ func cliRealCount(in string) (glyphs int) {
} }
return return
} }
//cliPrint prints the input.
var cliPrint = fmt.Print
//cliPrintf prints the formatted input.
var cliPrintf = fmt.Printf
//cliPrintln prints the input and terminates the line with carriage return and line feed.
func cliPrintln(a ...interface{}) (n int, err error) {
return cliPrint(append(a, "\r\n")...)
}
...@@ -294,7 +294,7 @@ func logicNew(none string) { ...@@ -294,7 +294,7 @@ func logicNew(none string) {
logicVarLazy.listGet(0) // downloads all user pages as par = len(users) logicVarLazy.listGet(0) // downloads all user pages as par = len(users)
cliHome() cliHome()
fmt.Println() cliPrintln()
cliStatus("sorting ...") cliStatus("sorting ...")
sort.Sort(&videoSort{logicVarLazy.listCached()}) sort.Sort(&videoSort{logicVarLazy.listCached()})
...@@ -331,7 +331,7 @@ commands: ...@@ -331,7 +331,7 @@ commands:
to other executable programs in $PATH. The video url will be passed as to other executable programs in $PATH. The video url will be passed as
first command-line argument. first command-line argument.
` `
fmt.Println(help) cliPrintln(strings.Replace(help, "\n", "\r\n", -1))
} }
// logicUnknown shows a message if the command could not be parsed // logicUnknown shows a message if the command could not be parsed
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment