Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
giulianopz committed Feb 21, 2024
2 parents 4a1d847 + e09c4f0 commit ab4f7b9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
14 changes: 14 additions & 0 deletions internal/display/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"log"
"os"
"sort"
"strings"
"sync"
"time"
"unicode/utf8"
Expand Down Expand Up @@ -287,6 +289,18 @@ func (d *display) appendToRaw(s string) {
d.raw = append(d.raw, []byte(s))
}

func (d *display) indexOf(url string) int {
sort.SliceStable(d.config.Feeds, func(i, j int) bool {
return strings.ToLower(d.config.Feeds[i].Name) < strings.ToLower(d.config.Feeds[j].Name)
})
for idx, f := range d.config.Feeds {
if f.Url == url {
return idx
}
}
return -1
}

func (d *display) appendToRendered(cells []*cell) {
d.rendered = append(d.rendered, cells)
}
Expand Down
26 changes: 24 additions & 2 deletions internal/display/loading.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,33 @@ func (d *display) addNewFeed() {
return
}

d.cache.Merge(d.config)

d.appendToRaw(url)

d.resetRows()

sort.SliceStable(d.config.Feeds, func(i, j int) bool {
return strings.ToLower(d.config.Feeds[i].Name) < strings.ToLower(d.config.Feeds[j].Name)
})
for _, f := range d.config.Feeds {
d.appendToRaw(f.Url)
}

d.renderFeedList()

idx := d.indexOf(url)
if idx == -1 {
log.Default().Println("cannot find url:", url)
d.setTmpBottomMessage(2*time.Second, "cannot find the find you added!")
return
}
idx++

d.current.cx = 1
d.current.cy = len(d.raw) % d.getContentWindowLen()
d.current.startoff = (len(d.raw) - 1) / d.getContentWindowLen() * d.getContentWindowLen()
max := d.getContentWindowLen()
d.current.cy = idx % max
d.current.startoff = idx / max * max

d.setBottomMessage(urlsListSectionMsg)
d.setTmpBottomMessage(2*time.Second, "new feed saved!")
Expand Down

0 comments on commit ab4f7b9

Please sign in to comment.