Skip to content

Commit

Permalink
Upgrade to readability@v0.1.1; refactor input processing loop; fix er…
Browse files Browse the repository at this point in the history
…r msg when failing to open a url with browser/lynx
  • Loading branch information
giulianopz committed Aug 18, 2024
1 parent b8afb4c commit fb51c3f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
18 changes: 18 additions & 0 deletions internal/display/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log"
"os"
"runtime/debug"
"sort"
"strings"
"sync"
Expand Down Expand Up @@ -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)
}()
}
}
6 changes: 4 additions & 2 deletions internal/display/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
}
Expand All @@ -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")
}
}
}
Expand Down

0 comments on commit fb51c3f

Please sign in to comment.