Skip to content

Commit

Permalink
Refactor func to load article text displaying err msg in bottom bar i…
Browse files Browse the repository at this point in the history
…f it fails
  • Loading branch information
giulianopz committed Mar 29, 2023
1 parent ec307b9 commit ec89e75
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pkg/display/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,8 @@ func (d *Display) LoadFeed(url string) {
title := strings.TrimSpace(parsedFeed.Title)

if err := d.cache.AddFeed(parsedFeed, url); err != nil {
log.Default().Println(fmt.Errorf("cannot load feed from url: %w", err))
d.SetBottomMessage(fmt.Sprintf("cannot load feed from url: %s", url))
log.Default().Println(err)
d.SetTmpBottomMessage(3*time.Second, fmt.Sprintf("cannot load feed from url: %s", url))
return
}

Expand Down Expand Up @@ -457,13 +457,17 @@ func (d *Display) LoadArticleText(url string) {
resp, err := http.Get(i.Url)
if err != nil {
log.Default().Println(err)
d.SetTmpBottomMessage(3*time.Second, fmt.Sprintf("cannot load article from url: %s", url))
return
}
defer resp.Body.Close()

converter := md.NewConverter("", true, nil)
markdown, err := converter.ConvertReader(resp.Body)
if err != nil {
log.Default().Println(err)
d.SetTmpBottomMessage(3*time.Second, "cannot parse article text!")
return
}

d.resetRows()
Expand All @@ -472,14 +476,13 @@ func (d *Display) LoadArticleText(url string) {
for scanner.Scan() {

line := strings.TrimSpace(scanner.Text())

if line != "" {

if len(line) > d.width {

for i := 0; i < len(line); i += d.width {
end := i + d.width

end := i + d.width
if end > len(line) {
end = len(line)
}
Expand Down

0 comments on commit ec89e75

Please sign in to comment.