Add watch option
This commit is contained in:
5 files changed
+45
No files matched your search
@@ -185,6 +185,15 @@ func (e *setExpr) eval(app *app, args []string) {
|
||||
app.ui.sort()
|
||||
app.ui.loadFile(app, true)
|
||||
}
|
||||
case "watch", "nowatch", "watch!":
|
||||
err = applyBoolOpt(&gOpts.watch, e)
|
||||
if err == nil {
|
||||
if gOpts.watch {
|
||||
app.nav.startWatcher()
|
||||
} else {
|
||||
app.nav.stopWatcher()
|
||||
}
|
||||
}
|
||||
case "wrapscan", "nowrapscan", "wrapscan!":
|
||||
err = applyBoolOpt(&gOpts.wrapscan, e)
|
||||
case "wrapscroll", "nowrapscroll", "wrapscroll!":
|
||||
|
||||
@@ -4,6 +4,7 @@ go 1.18
|
||||
|
||||
require (
|
||||
github.com/djherbis/times v1.6.0
|
||||
github.com/fsnotify/fsnotify v1.7.0
|
||||
github.com/gdamore/tcell/v2 v2.7.4
|
||||
github.com/mattn/go-runewidth v0.0.15
|
||||
golang.org/x/sys v0.18.0
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
github.com/djherbis/times v1.6.0 h1:w2ctJ92J8fBvWPxugmXIv7Nz7Q3iDMKNx9v5ocVH20c=
|
||||
github.com/djherbis/times v1.6.0/go.mod h1:gOHeRAz2h+VJNZ5Gmc/o7iD9k4wW7NMVqieYCY99oc0=
|
||||
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
|
||||
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
|
||||
github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=
|
||||
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
|
||||
github.com/gdamore/tcell/v2 v2.7.4 h1:sg6/UnTM9jGpZU+oFYAsDahfchWAFW8Xx2yFinNSAYU=
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/djherbis/times"
|
||||
"github.com/fsnotify/fsnotify"
|
||||
)
|
||||
|
||||
type linkState byte
|
||||
@@ -466,6 +467,8 @@ type nav struct {
|
||||
previewLoading bool
|
||||
jumpList []string
|
||||
jumpListInd int
|
||||
watcher *fsnotify.Watcher
|
||||
watcherEvents <-chan fsnotify.Event
|
||||
}
|
||||
|
||||
func (nav *nav) loadDirInternal(path string) *dir {
|
||||
@@ -2065,3 +2068,31 @@ func (nav *nav) calcDirSize() error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (nav *nav) startWatcher() {
|
||||
if nav.watcher != nil {
|
||||
return
|
||||
}
|
||||
log.Printf("start watch")
|
||||
|
||||
watcher, err := fsnotify.NewWatcher()
|
||||
if err != nil {
|
||||
log.Printf("start watcher: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
nav.watcher = watcher
|
||||
nav.watcherEvents = watcher.Events
|
||||
}
|
||||
|
||||
func (nav *nav) stopWatcher() {
|
||||
if nav.watcher == nil {
|
||||
return
|
||||
}
|
||||
log.Printf("stop watch")
|
||||
|
||||
nav.watcher.Close()
|
||||
|
||||
nav.watcher = nil
|
||||
nav.watcherEvents = nil
|
||||
}
|
||||
@@ -64,6 +64,7 @@ var gOpts struct {
|
||||
smartcase bool
|
||||
smartdia bool
|
||||
waitmsg string
|
||||
watch bool
|
||||
wrapscan bool
|
||||
wrapscroll bool
|
||||
findlen int
|
||||
@@ -209,6 +210,7 @@ func init() {
|
||||
gOpts.smartcase = true
|
||||
gOpts.smartdia = false
|
||||
gOpts.waitmsg = "Press any key to continue"
|
||||
gOpts.watch = false
|
||||
gOpts.wrapscan = true
|
||||
gOpts.wrapscroll = false
|
||||
gOpts.findlen = 1
|
||||
|
||||
Reference in new issue
Block a user