Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Jonny Schäfer
tubus
Commits
f6d95a25
Commit
f6d95a25
authored
Nov 08, 2016
by
Jonny Schäfer
Browse files
Fix terminal bug by adding print aliases
parent
040ee69c
Changes
2
Show whitespace changes
Inline
Side-by-side
cli.go
View file @
f6d95a25
...
...
@@ -10,16 +10,16 @@ import (
// cliLineWrap enables or disables line wrapping
func
cliLineWrap
(
enabled
bool
)
{
if
enabled
{
fmt
.
Print
(
"
\x1b
[?7h"
)
cli
Print
(
"
\x1b
[?7h"
)
}
else
{
fmt
.
Print
(
"
\x1b
[?7l"
)
cli
Print
(
"
\x1b
[?7l"
)
}
}
// cliReset resets the terminal to the defaults
func
cliReset
()
{
cliLineWrap
(
true
)
fmt
.
Print
(
"
\x1b
c"
)
cli
Print
(
"
\x1b
c"
)
}
// 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"
)
cli
Print
(
"
\x1b
[J"
)
}
// cliClear clears the screen right beginning at the cursor position
func
cliClearRight
()
{
fmt
.
Print
(
"
\x1b
[K"
)
cli
Print
(
"
\x1b
[K"
)
}
// cliHome sets the cursor to the origin
func
cliHome
()
{
fmt
.
Print
(
"
\x1b
[;H"
)
cli
Print
(
"
\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
()
cli
Println
()
cliClearRight
()
// erase status
fmt
.
Println
(
"
\x1b
[44;37m"
+
status
+
"
\x1b
[0m"
)
cli
Println
(
"
\x1b
[44;37m"
+
status
+
"
\x1b
[0m"
)
}
// cliStatus writes the current error status to the screen
func
cliStatusError
(
status
string
)
{
cliHome
()
fmt
.
Println
()
cli
Println
()
cliClearRight
()
// erase status
fmt
.
Println
(
"
\x1b
[1;41;37m"
+
status
+
"
\x1b
[0m"
)
cli
Println
(
"
\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
cli
Printf
(
"
\x1b
[%vm"
,
31
)
// red line
}
else
{
fmt
.
Printf
(
"
\x1b
[%vm"
,
((
n
+
1
)
%
2
)
*
34
)
// blue columns
cli
Printf
(
"
\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
cli
Print
(
c
[
i
]
+
strings
.
Repeat
(
" "
,
1
+
space
[
n
]
-
cliRealCount
(
c
[
i
])))
// not good
}
else
{
fmt
.
Print
(
strings
.
Repeat
(
" "
,
1
+
space
[
n
]))
cli
Print
(
strings
.
Repeat
(
" "
,
1
+
space
[
n
]))
}
}
if
i
!=
lines
-
1
{
fmt
.
Println
()
cli
Println
()
}
}
fmt
.
Print
(
"
\x1b
[0m"
)
cli
Print
(
"
\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
"
)
...
)
}
logic.go
View file @
f6d95a25
...
...
@@ -294,7 +294,7 @@ func logicNew(none string) {
logicVarLazy
.
listGet
(
0
)
// downloads all user pages as par = len(users)
cliHome
()
fmt
.
Println
()
cli
Println
()
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
)
cli
Println
(
strings
.
Replace
(
help
,
"
\n
"
,
"
\r\n
"
,
-
1
)
)
}
// logicUnknown shows a message if the command could not be parsed
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment