mirror of
https://github.com/walles/moar.git
synced 2024-09-11 12:15:43 +03:00
Merge d22af869d0
into 37cf840879
This commit is contained in:
commit
978b51ea3a
3
go.mod
3
go.mod
@ -4,12 +4,13 @@ go 1.20
|
||||
|
||||
require (
|
||||
github.com/alecthomas/chroma/v2 v2.12.0
|
||||
github.com/fsnotify/fsnotify v1.7.0
|
||||
github.com/google/go-cmp v0.5.9
|
||||
github.com/klauspost/compress v1.17.4
|
||||
github.com/sirupsen/logrus v1.8.1
|
||||
github.com/ulikunitz/xz v0.5.11
|
||||
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc
|
||||
golang.org/x/sys v0.1.0
|
||||
golang.org/x/sys v0.4.0
|
||||
golang.org/x/term v0.0.0-20210503060354-a79de5458b56
|
||||
gotest.tools/v3 v3.3.0
|
||||
)
|
||||
|
6
go.sum
6
go.sum
@ -7,6 +7,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dlclark/regexp2 v1.10.0 h1:+/GIL799phkJqYW+3YbOd8LCcbHzT0Pbo8zl70MHsq0=
|
||||
github.com/dlclark/regexp2 v1.10.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
|
||||
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/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
@ -41,8 +43,8 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
|
||||
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18=
|
||||
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20210503060354-a79de5458b56 h1:b8jxX3zqjpqb2LklXPzKSGJhzyxCOZSz8ncv8Nv+y7w=
|
||||
golang.org/x/term v0.0.0-20210503060354-a79de5458b56/go.mod h1:tfny5GFUkzUvx4ps4ajbZsCe5lw1metzhBm9T3x7oIY=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
|
37
m/reader.go
37
m/reader.go
@ -12,6 +12,7 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/fsnotify/fsnotify"
|
||||
"github.com/walles/moar/m/linenumbers"
|
||||
|
||||
"github.com/alecthomas/chroma/v2"
|
||||
@ -239,11 +240,39 @@ func (reader *Reader) tailFile() error {
|
||||
|
||||
log.Debugf("Tailing file %s", *fileName)
|
||||
|
||||
watcher, err := fsnotify.NewWatcher()
|
||||
if err != nil {
|
||||
log.Debugf("Failed to create watcher for %s, giving up: %s", *fileName, err.Error())
|
||||
return nil
|
||||
}
|
||||
err = watcher.Add(*fileName)
|
||||
if err != nil {
|
||||
log.Debugf("Failed to add %s to watcher for tailing, giving up: %s", *fileName, err.Error())
|
||||
return nil
|
||||
}
|
||||
|
||||
// Make sure to not miss any events while we were setting up the watcher
|
||||
firstLap := true
|
||||
|
||||
for {
|
||||
// NOTE: We could use something like
|
||||
// https://github.com/fsnotify/fsnotify instead of sleeping and polling
|
||||
// here.
|
||||
time.Sleep(1 * time.Second)
|
||||
if !firstLap {
|
||||
select {
|
||||
case event, ok := <-watcher.Events:
|
||||
if !ok {
|
||||
log.Debug("Watcher closed, giving up on tailing")
|
||||
return nil
|
||||
}
|
||||
log.Trace("File event received: ", event.String())
|
||||
case err, ok := <-watcher.Errors:
|
||||
if !ok {
|
||||
log.Debug("Watcher closed, giving up on tailing")
|
||||
return nil
|
||||
}
|
||||
log.Debugf("Watcher error, giving up on tailing: %s", err.Error())
|
||||
return nil
|
||||
}
|
||||
}
|
||||
firstLap = false
|
||||
|
||||
fileStats, err := os.Stat(*fileName)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user