diff --git a/app.go b/app.go index 253ac1f..017a201 100644 --- a/app.go +++ b/app.go @@ -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) } } } diff --git a/complete.go b/complete.go index e98e007..ab04e72 100644 --- a/complete.go +++ b/complete.go @@ -82,6 +82,7 @@ var ( "wrapscan", "nowrapscan", "wrapscan!", + "period", "scrolloff", "tabstop", "filesep", diff --git a/doc.go b/doc.go index 7eb8deb..336995e 100644 --- a/doc.go +++ b/doc.go @@ -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") diff --git a/docstring.go b/docstring.go index 1b28961..2ec4351 100644 --- a/docstring.go +++ b/docstring.go @@ -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") diff --git a/eval.go b/eval.go index 65078e9..b5220d5 100644 --- a/eval.go +++ b/eval.go @@ -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 { diff --git a/opts.go b/opts.go index 5b19a79..6dd582a 100644 --- a/opts.go +++ b/opts.go @@ -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"