~chrisppy/beagles

4f71597df5058ed0421725eae91746c2c9e3ce9c — Chris Palmer 7 months ago 880621c
insert added feed into proper index on sub
4 files changed, 57 insertions(+), 16 deletions(-)

M go.mod
M go.sum
M ui/actions.go
M ui/tree.go
M go.mod => go.mod +1 -1
@@ 2,7 2,7 @@ module git.sr.ht/~chrisppy/beagles

go 1.15

replace gitlab.com/tslocum/cview v1.5.3 => git.sr.ht/~chrisppy/cview v0.0.0-20210214163646-af62019ee3b4
replace gitlab.com/tslocum/cview v1.5.3 => git.sr.ht/~chrisppy/cview v0.0.0-20210214173831-cf2c15f351a7

require (
	git.sr.ht/~adnano/go-gemini v0.1.13

M go.sum => go.sum +2 -2
@@ 1,7 1,7 @@
git.sr.ht/~adnano/go-gemini v0.1.13 h1:vzKkkVrOzMpfJ1AAeE/PChg0Rw5Zf+9HrnwsgVxXUT4=
git.sr.ht/~adnano/go-gemini v0.1.13/go.mod h1:If1VxEWcZDrRt5FeAFnGTcM2Ud1E3BXs3VJ5rnZWKq0=
git.sr.ht/~chrisppy/cview v0.0.0-20210214163646-af62019ee3b4 h1:CaPuVvHlsqLrP+9+kCUJFe3TE8jPU+0wMCgGVmdlWWE=
git.sr.ht/~chrisppy/cview v0.0.0-20210214163646-af62019ee3b4/go.mod h1:lCEqP/zDhBihNbyiEn59LgOCk09ejefHaS7kNZ57Nmc=
git.sr.ht/~chrisppy/cview v0.0.0-20210214173831-cf2c15f351a7 h1:OKIPsl2z9OsQDm8jnQfbwJDl0GakXJLhtBnTkbT6PW0=
git.sr.ht/~chrisppy/cview v0.0.0-20210214173831-cf2c15f351a7/go.mod h1:lCEqP/zDhBihNbyiEn59LgOCk09ejefHaS7kNZ57Nmc=
git.sr.ht/~chrisppy/go-barefeed v0.1.0 h1:kyf1sJx4uGLesiXagd4sCP9C8+TPge+y/VxFTX6dI4E=
git.sr.ht/~chrisppy/go-barefeed v0.1.0/go.mod h1:V/4QgRdPISXxrbyn/0YNdrh1qR2PHk8hdcIJsdmJFlQ=
git.sr.ht/~chrisppy/go-opml v1.0.0 h1:Vf7UHZSXCiilzDBhfYT4RHo9ijmwiNkNxhXkyy3GLoM=

M ui/actions.go => ui/actions.go +2 -2
@@ 637,7 637,7 @@ func (i *UI) updateFeed(args []string) {
	i.app.update(func() {
		for _, item := range nitems.Sort() {
			i.list.insert(item)
			i.sub.insert(item, i.hideRead, false)
			i.sub.insert(item, i.hideRead, 0)
			if i.Config.Podcast.AutoDownload {
				if err := item.Download(i.DownloadDataHome, i.DB.Feeds); err != nil {
					i.Logger.Errorln(err.Error())


@@ 673,7 673,7 @@ func (i *UI) addFeed(args []string) {

			if node, _ := i.sub.find(v.FeedURL, i.sub.getRoot().GetChildren()); node == nil {
				f := i.DB.Feeds[v.FeedURL]
				i.sub.add(f, i.DB.Items, i.hideRead)
				i.sub.insertFeed(f, i.DB.Items, i.hideRead)
			}
		}


M ui/tree.go => ui/tree.go +52 -11
@@ 140,7 140,8 @@ func (w *tree) add(f *db.Feed, itemMap db.Items, hide bool) {
		return w.Dates[a].Sub(w.Dates[b]) > 0
	})

	node.SetText(getTitle(f.Title, unread, false, false))
	title := getTitle(f.Title, unread, false, false)
	node.SetText(title)
	node.SetColor(w.TextColor)
	node.SetReference(f.UpdateURL)
	node.SetChildren(items)


@@ 149,6 150,53 @@ func (w *tree) add(f *db.Feed, itemMap db.Items, hide bool) {
	w.getRoot().AddChild(node)
}

func (w *tree) insertFeed(f *db.Feed, itemMap db.Items, hide bool) {
	unread := 0
	node := tui.NewTreeNode("")
	items := make([]*tui.TreeNode, 0)
	for k := range f.Items {
		it := itemMap[k]

		n, read := w.convert(it)
		if read {
			if hide {
				continue
			}
		} else {
			unread++
		}

		items = append(items, n)
		w.ChildParent[it.Link] = node
	}

	if len(items) == 0 {
		return
	}

	sort.Slice(items, func(i, j int) bool {
		a := fmt.Sprintf("%v", items[i].GetReference())
		b := fmt.Sprintf("%v", items[j].GetReference())
		return w.Dates[a].Sub(w.Dates[b]) > 0
	})

	title := getTitle(f.Title, unread, false, false)
	node.SetText(title)
	node.SetColor(w.TextColor)
	node.SetReference(f.UpdateURL)
	node.SetChildren(items)
	node.Collapse()

	index := 0
	for i, ch := range w.getRoot().GetChildren() {
		if strings.ToLower(title) < strings.ToLower(ch.GetText()) {
			index = i
			break
		}
	}
	w.getRoot().InsertChild(node, index)
}

func getTitle(title string, unread int, increment bool, decrement bool) string {
	p := regexp.MustCompilePOSIX(` \(\*[0-9]*\)`)
	found := p.FindAllString(title, -1)


@@ 312,7 360,7 @@ func (w *tree) toggle() {
	n.Expand()
}

func (w *tree) insert(item *db.Item, hide bool, appendItem bool) {
func (w *tree) insert(item *db.Item, hide bool, index int) {
	node, _ := w.find(item.FeedURL, w.getRoot().GetChildren())
	if node == nil {
		return


@@ 326,14 374,7 @@ func (w *tree) insert(item *db.Item, hide bool, appendItem bool) {
	}

	node.SetText(getTitle(node.GetText(), 1, true, false))
	if appendItem {
		node.AddChild(n)
		return
	}

	ch := append([]*tui.TreeNode{n}, node.GetChildren()...)
	//node.ClearChildren()
	node.SetChildren(ch)
	node.InsertChild(n, index)
}

func (w *tree) find(key string, nodes []*tui.TreeNode) (*tui.TreeNode, int) {


@@ 359,7 400,7 @@ func (w *tree) removeFeedByKey(feed *db.Feed) string {

	ch := w.getRoot().GetChildren()
	ch = append(ch[:i], ch[i+1:]...)
	//w.getRoot().ClearChildren()

	w.getRoot().SetChildren(ch)
	size := len(ch)