diff --git a/go.mod b/go.mod index 49b475a..3c82859 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/giulianopz/newscanoe go 1.22.3 require ( - github.com/giulianopz/go-readability v0.1.0 + github.com/giulianopz/go-readability v0.1.1 github.com/mmcdole/gofeed v1.2.1 golang.org/x/exp v0.0.0-20230321023759-10a507213a29 golang.org/x/sync v0.1.0 diff --git a/go.sum b/go.sum index 0cbe6e4..e625bab 100644 --- a/go.sum +++ b/go.sum @@ -6,8 +6,8 @@ github.com/andybalholm/cascadia v1.3.2/go.mod h1:7gtRlve5FxPPgIgX36uWBX58OdBsSS6 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 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/giulianopz/go-readability v0.1.0 h1:WPHDxFoayY33sq+O3jqBoM0WKTNCVCi0lCCEtaIw0O4= -github.com/giulianopz/go-readability v0.1.0/go.mod h1:c2qwl84Zsa+uZ78CCfr1hsWYyQL1/usDx/EtIfmcha0= +github.com/giulianopz/go-readability v0.1.1 h1:klT1mDvWEvUO06laSwqc3g8CMFOQFjLE0duhoyARccE= +github.com/giulianopz/go-readability v0.1.1/go.mod h1:c2qwl84Zsa+uZ78CCfr1hsWYyQL1/usDx/EtIfmcha0= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= diff --git a/internal/display/display.go b/internal/display/display.go index dc52de2..cab6928 100644 --- a/internal/display/display.go +++ b/internal/display/display.go @@ -5,6 +5,7 @@ import ( "fmt" "log" "os" + "runtime/debug" "sort" "strings" "sync" @@ -472,3 +473,20 @@ func (d *display) RefreshScreen() { fmt.Fprint(os.Stdout, buf.String()) } + +func (d *display) ListenToInput() { + for { + func() { + defer func() { + if r := recover(); r != nil { + log.Default().Printf("recover from: %v\nstack trace: %v\n", r, string(debug.Stack())) + d.setTmpBottomMessage(2*time.Second, "something bad happened: check the logs") + } + }() + + d.RefreshScreen() + input := d.ReadKeyStroke(os.Stdin.Fd()) + d.ProcessKeyStroke(input) + }() + } +} diff --git a/internal/display/input.go b/internal/display/input.go index 0e1b779..053a85e 100644 --- a/internal/display/input.go +++ b/internal/display/input.go @@ -168,7 +168,8 @@ func (d *display) whileReading(input byte) { if d.currentSection == ARTICLES_LIST { if !util.IsHeadless() { if err := util.OpenWithBrowser(string(d.raw[d.currentRow()])); err != nil { - d.setTmpBottomMessage(2*time.Second, err.Error()) + log.Default().Println("cannot open url with browser", err) + d.setTmpBottomMessage(2*time.Second, "cannot open url with browser: check logs") } } } @@ -177,7 +178,8 @@ func (d *display) whileReading(input byte) { if d.currentSection == ARTICLES_LIST { if util.IsLynxPresent() { if err := util.OpenWithLynx(string(d.raw[d.currentRow()])); err != nil { - d.setTmpBottomMessage(2*time.Second, err.Error()) + log.Default().Println("cannot open url with lynx", err) + d.setTmpBottomMessage(2*time.Second, "cannot open url with lynx: check logs") } } }