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

add variable size (experimental); fix sorting on streamed videos

parent b624af94
...@@ -106,7 +106,9 @@ func cliTable(highlight int, columns ...[]string) { ...@@ -106,7 +106,9 @@ func cliTable(highlight int, columns ...[]string) {
fmt.Print(strings.Repeat(" ", 1+space[n])) fmt.Print(strings.Repeat(" ", 1+space[n]))
} }
} }
fmt.Println() if i != lines - 1 {
fmt.Println()
}
} }
fmt.Print("\x1b[0m") fmt.Print("\x1b[0m")
} }
......
...@@ -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*logicVarLineCount, (page+1)*logicVarLineCount) list := logicVarLazy.listSlice(page*linecount, (page+1)*linecount)
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)
......
...@@ -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 {
......
...@@ -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())
......
...@@ -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
......
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