add 'period' option for periodic refresh

Related #73
This commit is contained in:
Gokcehan committed 2018-06-09 22:02:09 +03:00
1 parent e025c68130
commit 723357fe3d
6 files changed
+30

No files matched your search

+7
View File
@@ -9,6 +9,7 @@ import (
"os/exec"
"strconv"
"strings"
"time"
)
type cmdItem struct {
@@ -19,6 +20,7 @@ type cmdItem struct {
type app struct {
ui *ui
nav *nav
ticker *time.Ticker
quitChan chan bool
cmd *exec.Cmd
cmdIn io.WriteCloser
@@ -34,6 +36,7 @@ func newApp() *app {
return &app{
ui: ui,
nav: nav,
ticker: new(time.Ticker),
quitChan: make(chan bool, 1),
}
}
@@ -132,6 +135,10 @@ func (app *app) loop() {
case e := <-serverChan:
e.eval(app, nil)
app.ui.draw(app.nav)
case <-app.ticker.C:
app.nav.renew()
app.ui.loadFile(app.nav)
app.ui.draw(app.nav)
}
}
}
+1
View File
@@ -82,6 +82,7 @@ var (
"wrapscan",
"nowrapscan",
"wrapscan!",
"period",
"scrolloff",
"tabstop",
"filesep",
+1
View File
@@ -91,6 +91,7 @@ The following options can be used to customize the behavior of lf:
reverse boolean (default off)
smartcase boolean (default on)
wrapscan boolean (default on)
period integer (default 0)
scrolloff integer (default 0)
tabstop integer (default 8)
filesep string (default "\n")
+1
View File
@@ -95,6 +95,7 @@ The following options can be used to customize the behavior of lf:
reverse boolean (default off)
smartcase boolean (default on)
wrapscan boolean (default on)
period integer (default 0)
scrolloff integer (default 0)
tabstop integer (default 8)
filesep string (default "\n")
+18
View File
@@ -6,6 +6,7 @@ import (
"os"
"strconv"
"strings"
"time"
"unicode"
"unicode/utf8"
)
@@ -96,6 +97,23 @@ func (e *setExpr) eval(app *app, args []string) {
gOpts.wrapscan = false
case "wrapscan!":
gOpts.wrapscan = !gOpts.wrapscan
case "period":
n, err := strconv.Atoi(e.val)
if err != nil {
app.ui.printf("period: %s", err)
return
}
if n < 0 {
app.ui.print("period: value should be a non-negative number")
return
}
gOpts.period = n
if n == 0 {
app.ticker.Stop()
} else {
app.ticker.Stop()
app.ticker = time.NewTicker(time.Duration(gOpts.period) * time.Second)
}
case "scrolloff":
n, err := strconv.Atoi(e.val)
if err != nil {
+2
View File
@@ -32,6 +32,7 @@ var gOpts struct {
preview bool
smartcase bool
wrapscan bool
period int
scrolloff int
tabstop int
filesep string
@@ -56,6 +57,7 @@ func init() {
gOpts.preview = true
gOpts.smartcase = true
gOpts.wrapscan = true
gOpts.period = 0
gOpts.scrolloff = 0
gOpts.tabstop = 8
gOpts.filesep = "\n"