Skip to content

Commit fb51c3f

Browse files
committed
Upgrade to readability@v0.1.1; refactor input processing loop; fix err msg when failing to open a url with browser/lynx
1 parent b8afb4c commit fb51c3f

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/giulianopz/newscanoe
33
go 1.22.3
44

55
require (
6-
github.com/giulianopz/go-readability v0.1.0
6+
github.com/giulianopz/go-readability v0.1.1
77
github.com/mmcdole/gofeed v1.2.1
88
golang.org/x/exp v0.0.0-20230321023759-10a507213a29
99
golang.org/x/sync v0.1.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ github.com/andybalholm/cascadia v1.3.2/go.mod h1:7gtRlve5FxPPgIgX36uWBX58OdBsSS6
66
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
77
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
88
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
9-
github.com/giulianopz/go-readability v0.1.0 h1:WPHDxFoayY33sq+O3jqBoM0WKTNCVCi0lCCEtaIw0O4=
10-
github.com/giulianopz/go-readability v0.1.0/go.mod h1:c2qwl84Zsa+uZ78CCfr1hsWYyQL1/usDx/EtIfmcha0=
9+
github.com/giulianopz/go-readability v0.1.1 h1:klT1mDvWEvUO06laSwqc3g8CMFOQFjLE0duhoyARccE=
10+
github.com/giulianopz/go-readability v0.1.1/go.mod h1:c2qwl84Zsa+uZ78CCfr1hsWYyQL1/usDx/EtIfmcha0=
1111
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
1212
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
1313
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=

internal/display/display.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"log"
77
"os"
8+
"runtime/debug"
89
"sort"
910
"strings"
1011
"sync"
@@ -472,3 +473,20 @@ func (d *display) RefreshScreen() {
472473

473474
fmt.Fprint(os.Stdout, buf.String())
474475
}
476+
477+
func (d *display) ListenToInput() {
478+
for {
479+
func() {
480+
defer func() {
481+
if r := recover(); r != nil {
482+
log.Default().Printf("recover from: %v\nstack trace: %v\n", r, string(debug.Stack()))
483+
d.setTmpBottomMessage(2*time.Second, "something bad happened: check the logs")
484+
}
485+
}()
486+
487+
d.RefreshScreen()
488+
input := d.ReadKeyStroke(os.Stdin.Fd())
489+
d.ProcessKeyStroke(input)
490+
}()
491+
}
492+
}

internal/display/input.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ func (d *display) whileReading(input byte) {
168168
if d.currentSection == ARTICLES_LIST {
169169
if !util.IsHeadless() {
170170
if err := util.OpenWithBrowser(string(d.raw[d.currentRow()])); err != nil {
171-
d.setTmpBottomMessage(2*time.Second, err.Error())
171+
log.Default().Println("cannot open url with browser", err)
172+
d.setTmpBottomMessage(2*time.Second, "cannot open url with browser: check logs")
172173
}
173174
}
174175
}
@@ -177,7 +178,8 @@ func (d *display) whileReading(input byte) {
177178
if d.currentSection == ARTICLES_LIST {
178179
if util.IsLynxPresent() {
179180
if err := util.OpenWithLynx(string(d.raw[d.currentRow()])); err != nil {
180-
d.setTmpBottomMessage(2*time.Second, err.Error())
181+
log.Default().Println("cannot open url with lynx", err)
182+
d.setTmpBottomMessage(2*time.Second, "cannot open url with lynx: check logs")
181183
}
182184
}
183185
}

0 commit comments

Comments
 (0)