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 (
// cliLineWrap enables or disables line wrapping
func cliLineWrap(enabled bool) {
if enabled {
fmt.Print("\x1b[?7h")
cliPrint("\x1b[?7h")
} else {
fmt.Print("\x1b[?7l")
cliPrint("\x1b[?7l")
}
}
// cliReset resets the terminal to the defaults
func cliReset() {
cliLineWrap(true)
fmt.Print("\x1bc")
cliPrint("\x1bc")
}
// cliClear clears the screen
......@@ -31,17 +31,17 @@ func cliClear() {
// cliClear clears the screen downwards beginning at the cursor position
func cliClearDown() {
fmt.Print("\x1b[J")
cliPrint("\x1b[J")
}
// cliClear clears the screen right beginning at the cursor position
func cliClearRight() {
fmt.Print("\x1b[K")
cliPrint("\x1b[K")
}
// cliHome sets the cursor to the origin
func cliHome() {
fmt.Print("\x1b[;H")
cliPrint("\x1b[;H")
}
// cliPrompt reads a line from stdin
......@@ -59,17 +59,17 @@ func cliPrompt() string {
// cliStatus writes the current status to the screen
func cliStatus(status string) {
cliHome()
fmt.Println()
cliPrintln()
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
func cliStatusError(status string) {
cliHome()
fmt.Println()
cliPrintln()
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
......@@ -95,22 +95,22 @@ func cliTable(highlight int, columns ...[]string) {
for i := 0; i < lines; i++ {
for n, c := range columns {
if i == highlight {
fmt.Printf("\x1b[%vm", 31) // red line
cliPrintf("\x1b[%vm", 31) // red line
} else {
fmt.Printf("\x1b[%vm", ((n+1)%2)*34) // blue columns
cliPrintf("\x1b[%vm", ((n+1)%2)*34) // blue columns
}
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 {
fmt.Print(strings.Repeat(" ", 1+space[n]))
cliPrint(strings.Repeat(" ", 1+space[n]))
}
}
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
......@@ -142,3 +142,14 @@ func cliRealCount(in string) (glyphs int) {
}
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) {
logicVarLazy.listGet(0) // downloads all user pages as par = len(users)
cliHome()
fmt.Println()
cliPrintln()
cliStatus("sorting ...")
sort.Sort(&videoSort{logicVarLazy.listCached()})
......@@ -331,7 +331,7 @@ commands:
to other executable programs in $PATH. The video url will be passed as
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
......
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