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) {
fmt.Print(strings.Repeat(" ", 1+space[n]))
}
}
fmt.Println()
if i != lines - 1 {
fmt.Println()
}
}
fmt.Print("\x1b[0m")
}
......
......@@ -45,13 +45,13 @@ const (
)
var (
logicVarLineCount = 30
logicVarWindow = logicWindowNone
logicVarVideos []*videoContainer = []*videoContainer{}
logicVarLazy = &listLazy{}
logicVarUsers = []string{}
logicVarUser = ""
logicVarSearch = ""
logicVarWindow = logicWindowNone
logicVarVideos []*videoContainer = []*videoContainer{}
logicVarLazy = &listLazy{}
logicVarUsers = []string{}
logicVarUser = ""
logicVarSearch = ""
logicVarCurrentPage = 0
)
// logicAction parses the input string and performs the given action
......@@ -91,6 +91,13 @@ func logicTrim(trim string) string {
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
func logicSearch(title string) {
upd := func(state int) []*videoContainer {
......@@ -106,8 +113,8 @@ func logicSearchPage(title string, page int) {
cliStatus("page " + strconv.Itoa(page) + " | " + title)
logicVarWindow = logicWindowSearch
logicVarSearch = title
list := logicVarLazy.listSlice(page*logicVarLineCount, (page+1)*logicVarLineCount)
linecount := termLines() - 2
list := logicVarLazy.listSlice(page*linecount, (page+1)*linecount)
if list == nil {
cliStatusError("network error: unable to load data")
......@@ -155,6 +162,13 @@ func logicPage(page string) {
pnum, err := strconv.Atoi(page)
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 {
case logicWindowSearch:
logicSearchPage(logicVarSearch, pnum)
......
......@@ -4,11 +4,14 @@ import (
"golang.org/x/crypto/ssh/terminal"
"io"
"os"
"os/signal"
"syscall"
)
var (
termTerminal *terminal.Terminal
termRestore *terminal.State
termOnWinch func()
)
func init() {
......@@ -25,6 +28,18 @@ func init() {
errorCare(err)
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
......@@ -32,6 +47,18 @@ func termReadLine() (string, error) {
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
func termClose() {
if termRestore != nil {
......
......@@ -4,6 +4,7 @@ func main() {
cliReset()
cliClear()
cliLineWrap(false)
termWinch(logicOnWinch)
cliStatus("type :help for help")
for {
logicAction(cliPrompt())
......
......@@ -115,6 +115,8 @@ func videoIsYounger(young, old *videoContainer) bool {
// videoDateToSeconds calculates the number of past seconds since the given date
func videoDateToSeconds(date string) int {
date = strings.TrimPrefix(date, "Streamed ")
split := strings.Split(date, " ")
if len(split) < 2 {
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