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
9a4f3bfe
Commit
9a4f3bfe
authored
Jul 07, 2016
by
Jonny Schäfer
Browse files
add variable size (experimental); fix sorting on streamed videos
parent
b624af94
Changes
5
Show whitespace changes
Inline
Side-by-side
cli.go
View file @
9a4f3bfe
...
@@ -106,8 +106,10 @@ func cliTable(highlight int, columns ...[]string) {
...
@@ -106,8 +106,10 @@ func cliTable(highlight int, columns ...[]string) {
fmt
.
Print
(
strings
.
Repeat
(
" "
,
1
+
space
[
n
]))
fmt
.
Print
(
strings
.
Repeat
(
" "
,
1
+
space
[
n
]))
}
}
}
}
if
i
!=
lines
-
1
{
fmt
.
Println
()
fmt
.
Println
()
}
}
}
fmt
.
Print
(
"
\x1b
[0m"
)
fmt
.
Print
(
"
\x1b
[0m"
)
}
}
...
...
logic.go
View file @
9a4f3bfe
...
@@ -45,13 +45,13 @@ const (
...
@@ -45,13 +45,13 @@ const (
)
)
var
(
var
(
logicVarLineCount
=
30
logicVarWindow
=
logicWindowNone
logicVarWindow
=
logicWindowNone
logicVarVideos
[]
*
videoContainer
=
[]
*
videoContainer
{}
logicVarVideos
[]
*
videoContainer
=
[]
*
videoContainer
{}
logicVarLazy
=
&
listLazy
{}
logicVarLazy
=
&
listLazy
{}
logicVarUsers
=
[]
string
{}
logicVarUsers
=
[]
string
{}
logicVarUser
=
""
logicVarUser
=
""
logicVarSearch
=
""
logicVarSearch
=
""
logicVarCurrentPage
=
0
)
)
// logicAction parses the input string and performs the given action
// logicAction parses the input string and performs the given action
...
@@ -91,6 +91,13 @@ func logicTrim(trim string) string {
...
@@ -91,6 +91,13 @@ func logicTrim(trim string) string {
return
trim
return
trim
}
}
// logicOnWinch reloads the page if the window size was changed
func
logicOnWinch
()
{
cliClear
()
logicLoadPage
(
logicVarCurrentPage
)
cliHome
()
}
// logicSearch searches for the given video title
// logicSearch searches for the given video title
func
logicSearch
(
title
string
)
{
func
logicSearch
(
title
string
)
{
upd
:=
func
(
state
int
)
[]
*
videoContainer
{
upd
:=
func
(
state
int
)
[]
*
videoContainer
{
...
@@ -106,8 +113,8 @@ func logicSearchPage(title string, page int) {
...
@@ -106,8 +113,8 @@ func logicSearchPage(title string, page int) {
cliStatus
(
"page "
+
strconv
.
Itoa
(
page
)
+
" | "
+
title
)
cliStatus
(
"page "
+
strconv
.
Itoa
(
page
)
+
" | "
+
title
)
logicVarWindow
=
logicWindowSearch
logicVarWindow
=
logicWindowSearch
logicVarSearch
=
title
logicVarSearch
=
title
linecount
:=
termLines
()
-
2
list
:=
logicVarLazy
.
listSlice
(
page
*
l
ogicVarL
ine
C
ount
,
(
page
+
1
)
*
l
ogicVarL
ine
C
ount
)
list
:=
logicVarLazy
.
listSlice
(
page
*
line
c
ount
,
(
page
+
1
)
*
line
c
ount
)
if
list
==
nil
{
if
list
==
nil
{
cliStatusError
(
"network error: unable to load data"
)
cliStatusError
(
"network error: unable to load data"
)
...
@@ -155,6 +162,13 @@ func logicPage(page string) {
...
@@ -155,6 +162,13 @@ func logicPage(page string) {
pnum
,
err
:=
strconv
.
Atoi
(
page
)
pnum
,
err
:=
strconv
.
Atoi
(
page
)
errorCare
(
err
)
errorCare
(
err
)
logicLoadPage
(
pnum
)
}
// logicLoadPage calls the relevant function according to the
// window state
func
logicLoadPage
(
pnum
int
)
{
logicVarCurrentPage
=
pnum
// save for list redraw
switch
logicVarWindow
{
switch
logicVarWindow
{
case
logicWindowSearch
:
case
logicWindowSearch
:
logicSearchPage
(
logicVarSearch
,
pnum
)
logicSearchPage
(
logicVarSearch
,
pnum
)
...
...
term.go
View file @
9a4f3bfe
...
@@ -4,11 +4,14 @@ import (
...
@@ -4,11 +4,14 @@ import (
"golang.org/x/crypto/ssh/terminal"
"golang.org/x/crypto/ssh/terminal"
"io"
"io"
"os"
"os"
"os/signal"
"syscall"
)
)
var
(
var
(
termTerminal
*
terminal
.
Terminal
termTerminal
*
terminal
.
Terminal
termRestore
*
terminal
.
State
termRestore
*
terminal
.
State
termOnWinch
func
()
)
)
func
init
()
{
func
init
()
{
...
@@ -25,6 +28,18 @@ func init() {
...
@@ -25,6 +28,18 @@ func init() {
errorCare
(
err
)
errorCare
(
err
)
termTerminal
=
terminal
.
NewTerminal
(
stdio
,
""
)
termTerminal
=
terminal
.
NewTerminal
(
stdio
,
""
)
c
:=
make
(
chan
os
.
Signal
,
1
)
signal
.
Notify
(
c
,
syscall
.
SIGWINCH
)
go
func
()
{
for
{
<-
c
if
termOnWinch
!=
nil
{
termOnWinch
()
}
}
}()
}
}
// termReadLine reads a line from stdin
// termReadLine reads a line from stdin
...
@@ -32,6 +47,18 @@ func termReadLine() (string, error) {
...
@@ -32,6 +47,18 @@ func termReadLine() (string, error) {
return
termTerminal
.
ReadLine
()
return
termTerminal
.
ReadLine
()
}
}
// termLine returns the number of available terminal lines
func
termLines
()
int
{
_
,
h
,
err
:=
terminal
.
GetSize
(
int
(
os
.
Stdin
.
Fd
()))
errorCare
(
err
)
return
h
}
// termWinch calls the given function if the window size changes
func
termWinch
(
run
func
())
{
termOnWinch
=
run
}
// termClose restores the terminal to its original state
// termClose restores the terminal to its original state
func
termClose
()
{
func
termClose
()
{
if
termRestore
!=
nil
{
if
termRestore
!=
nil
{
...
...
tubus.go
View file @
9a4f3bfe
...
@@ -4,6 +4,7 @@ func main() {
...
@@ -4,6 +4,7 @@ func main() {
cliReset
()
cliReset
()
cliClear
()
cliClear
()
cliLineWrap
(
false
)
cliLineWrap
(
false
)
termWinch
(
logicOnWinch
)
cliStatus
(
"type :help for help"
)
cliStatus
(
"type :help for help"
)
for
{
for
{
logicAction
(
cliPrompt
())
logicAction
(
cliPrompt
())
...
...
video.go
View file @
9a4f3bfe
...
@@ -115,6 +115,8 @@ func videoIsYounger(young, old *videoContainer) bool {
...
@@ -115,6 +115,8 @@ func videoIsYounger(young, old *videoContainer) bool {
// videoDateToSeconds calculates the number of past seconds since the given date
// videoDateToSeconds calculates the number of past seconds since the given date
func
videoDateToSeconds
(
date
string
)
int
{
func
videoDateToSeconds
(
date
string
)
int
{
date
=
strings
.
TrimPrefix
(
date
,
"Streamed "
)
split
:=
strings
.
Split
(
date
,
" "
)
split
:=
strings
.
Split
(
date
,
" "
)
if
len
(
split
)
<
2
{
if
len
(
split
)
<
2
{
return
0
return
0
...
...
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