diff --git a/.nanpa/salsa-old-jam.kdl b/.nanpa/salsa-old-jam.kdl new file mode 100644 index 0000000..5caff99 --- /dev/null +++ b/.nanpa/salsa-old-jam.kdl @@ -0,0 +1 @@ +patch type="added" "shortcuts to list items in menu and management" diff --git a/Makefile b/Makefile index 8084c40..387f675 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ SCDOC ?= scdoc all: neofeels doc -neofeels: +neofeels: **/*.go $(GO) build $(GOFLAGS) . ifeq (, $(shell which $(SCDOC) 2>/dev/null)) @@ -18,6 +18,3 @@ endif clean: rm neofeels doc/neofeels.1 - -.PHONY: all neofeels doc clean - diff --git a/app/backups.go b/app/backups.go index f8bc2c6..24c40a4 100644 --- a/app/backups.go +++ b/app/backups.go @@ -25,14 +25,14 @@ type Backups struct { func NewBackups() *Backups { os.MkdirAll(ttbp.PathUserBackups, 0700) backups, _ := os.ReadDir(ttbp.PathUserBackups) - list := []string{} + list := [][]vaxis.Segment{} for _, backup := range backups { timestamp, err := time.Parse("feels-backup-20060102-150405.tar.gz", backup.Name()) if err != nil { continue } // XXX: for some reason this gets fucked up with timezones??? - list = append(list, humanize.Time(timestamp.Local())) + list = append(list, []vaxis.Segment{{Text: humanize.Time(timestamp.Local())}}) } return &Backups{ diff --git a/app/browse.go b/app/browse.go index 809de3c..e41b57b 100644 --- a/app/browse.go +++ b/app/browse.go @@ -23,14 +23,14 @@ func NewBrowse() *Browse { posts = append(posts, ttbp.GetPostsForUser(user.Name)...) } posts = ttbp.SortPostsByRecent(posts) - list := []string{} + list := [][]vaxis.Segment{} for _, post := range posts { - list = append(list, fmt.Sprintf( + list = append(list, []vaxis.Segment{{Text: fmt.Sprintf( "~%-15s %s (%d words)", post.Author, post.LastEdited.Format("2006-01-02 15:04"), post.Words, - )) + )}}) } return &Browse{ diff --git a/app/bury.go b/app/bury.go index 3ba4f45..a51487b 100644 --- a/app/bury.go +++ b/app/bury.go @@ -23,13 +23,13 @@ type Bury struct { func NewBury() *Bury { user, _ := user.Current() posts := ttbp.GetPostsForUser(user.Username) - list := []string{} + list := [][]vaxis.Segment{} for _, post := range posts { - list = append(list, fmt.Sprintf( + list = append(list, []vaxis.Segment{{Text: fmt.Sprintf( "%s (%d words)", post.Date.Format("2006-01-02"), post.Words, - )) + )}}) } return &Bury{ diff --git a/app/config.go b/app/config.go index 23776bc..c716571 100644 --- a/app/config.go +++ b/app/config.go @@ -18,12 +18,12 @@ type Config struct { descriptions []string } -var configList = []string{ - "pager", - "publish to html", - "publish to gopher", - "default to nopub", - "default to html", +var configList = [][]vaxis.Segment{ + []vaxis.Segment{{Text: "pager"}}, + []vaxis.Segment{{Text: "publish to html"}}, + []vaxis.Segment{{Text: "publish to gopher"}}, + []vaxis.Segment{{Text: "default to nopub"}}, + []vaxis.Segment{{Text: "default to html"}}, } func NewConfig() *Config { @@ -112,7 +112,7 @@ func (config *Config) Event(state *ui.State, event vaxis.Event) (processed bool) func (config *Config) Draw(state *ui.State) { if config.config.Publishing { - config.list.SetItems(append(configList, "html publish directory")) + config.list.SetItems(append(configList, []vaxis.Segment{{Text: "html publish directory"}})) } else { config.list.SetItems(configList) } diff --git a/app/delete.go b/app/delete.go index 2a6285e..b3dd6cf 100644 --- a/app/delete.go +++ b/app/delete.go @@ -22,13 +22,13 @@ type Delete struct { func NewDelete() *Delete { user, _ := user.Current() posts := ttbp.GetPostsForUser(user.Username) - list := []string{} + list := [][]vaxis.Segment{} for _, post := range posts { - list = append(list, fmt.Sprintf( + list = append(list, []vaxis.Segment{{Text: fmt.Sprintf( "%s (%d words)", post.Date.Format("2006-01-02"), post.Words, - )) + )}}) } return &Delete{ diff --git a/app/management.go b/app/management.go index 93aee59..45f5108 100644 --- a/app/management.go +++ b/app/management.go @@ -23,15 +23,40 @@ type Management struct { func NewManagement(index int) *Management { return &Management{ title, - ui.NewList([]string{ - "read over feels", - "modify feels publishing", - "backup your feels", - "import a feels backup", - "bury some feels", - "delete feels by day", - "purge all feels", - "wipe feels account", + ui.NewList([][]vaxis.Segment{ + { + {Text: "r", Style: vaxis.Style{Attribute: vaxis.AttrReverse}}, + {Text: "ead over feels"}, + }, + { + {Text: "m", Style: vaxis.Style{Attribute: vaxis.AttrReverse}}, + {Text: "odify feels publishing"}, + }, + { + {Text: "b", Style: vaxis.Style{Attribute: vaxis.AttrReverse}}, + {Text: "ackup your feels"}, + }, + { + {Text: "i", Style: vaxis.Style{Attribute: vaxis.AttrReverse}}, + {Text: "mport a feels backup"}, + }, + { + {Text: "b"}, + {Text: "u", Style: vaxis.Style{Attribute: vaxis.AttrReverse}}, + {Text: "ry some feels"}, + }, + { + {Text: "d", Style: vaxis.Style{Attribute: vaxis.AttrReverse}}, + {Text: "elete feels by day"}, + }, + { + {Text: "p", Style: vaxis.Style{Attribute: vaxis.AttrReverse}}, + {Text: "urge all feels"}, + }, + { + {Text: "w", Style: vaxis.Style{Attribute: vaxis.AttrReverse}}, + {Text: "ipe feels account"}, + }, }, index), "↑↓/kj move ↵ enter q return", } @@ -50,6 +75,22 @@ func (management *Management) Event(state *ui.State, event vaxis.Event) (process management.list.End() case "Home", "g": management.list.Home() + case "r": + management.list.SetIndex(0) + case "m": + management.list.SetIndex(1) + case "b": + management.list.SetIndex(2) + case "i": + management.list.SetIndex(3) + case "u": + management.list.SetIndex(4) + case "d": + management.list.SetIndex(5) + case "p": + management.list.SetIndex(6) + case "w": + management.list.SetIndex(7) case "0", "1", "2", "3", "4", "5", "6", "7": i, _ := strconv.Atoi(key.String()) management.list.SetIndex(i) diff --git a/app/menu.go b/app/menu.go index fb00861..e1fcf67 100644 --- a/app/menu.go +++ b/app/menu.go @@ -30,16 +30,48 @@ const title = ` ___ __ func NewMainMenu(index int) *MainMenu { return &MainMenu{ title, - ui.NewList([]string{ - "record some feels", - "manage your feels", - "check out your neighbors", - "browse global feels", - "visit your subscriptions", - "scribble some graffiti", - "change your settings", - "see credits", - "read documentation", + ui.NewList([][]vaxis.Segment{ + { + {Text: "r", Style: vaxis.Style{Attribute: vaxis.AttrReverse}}, + {Text: "ecord some feels"}, + }, + { + {Text: "m", Style: vaxis.Style{Attribute: vaxis.AttrReverse}}, + {Text: "anage your feels"}, + }, + { + {Text: "check out your "}, + {Text: "n", Style: vaxis.Style{Attribute: vaxis.AttrReverse}}, + {Text: "eighbors"}, + }, + { + {Text: "b", Style: vaxis.Style{Attribute: vaxis.AttrReverse}}, + {Text: "rowse global feels"}, + }, + { + {Text: "visit your "}, + {Text: "s", Style: vaxis.Style{Attribute: vaxis.AttrReverse}}, + {Text: "ubscriptions"}, + }, + { + {Text: "scribble some gra"}, + {Text: "f", Style: vaxis.Style{Attribute: vaxis.AttrReverse}}, + {Text: "fiti"}, + }, + { + {Text: "c", Style: vaxis.Style{Attribute: vaxis.AttrReverse}}, + {Text: "hange your settings"}, + }, + { + {Text: "see cr"}, + {Text: "e", Style: vaxis.Style{Attribute: vaxis.AttrReverse}}, + {Text: "dits"}, + }, + { + {Text: "read "}, + {Text: "d", Style: vaxis.Style{Attribute: vaxis.AttrReverse}}, + {Text: "ocumentation"}, + }, }, index), "↑↓/kj move ↵ enter q exit", } @@ -58,6 +90,24 @@ func (menu *MainMenu) Event(state *ui.State, event vaxis.Event) (processed bool) menu.list.End() case "Home", "g": menu.list.Home() + case "r": + menu.list.SetIndex(0) + case "m": + menu.list.SetIndex(1) + case "n": + menu.list.SetIndex(2) + case "b": + menu.list.SetIndex(3) + case "s": + menu.list.SetIndex(4) + case "f": + menu.list.SetIndex(5) + case "c": + menu.list.SetIndex(6) + case "e": + menu.list.SetIndex(7) + case "d": + menu.list.SetIndex(8) case "0", "1", "2", "3", "4", "5", "6", "7", "8": i, _ := strconv.Atoi(key.String()) menu.list.SetIndex(i) diff --git a/app/neighbors.go b/app/neighbors.go index 4365752..1cbc804 100644 --- a/app/neighbors.go +++ b/app/neighbors.go @@ -21,9 +21,9 @@ type Neighbors struct { func NewNeighbors(index int) *Neighbors { users := ttbp.SortUsersByRecent(ttbp.GetUsers()) subscriptions := ttbp.GetSubscriptions() - list := []string{} + list := [][]vaxis.Segment{} for _, user := range users { - list = append(list, formatNeighbor(user, subscriptions)) + list = append(list, []vaxis.Segment{{Text: formatNeighbor(user, subscriptions)}}) } return &Neighbors{ @@ -79,7 +79,7 @@ func (neighbors *Neighbors) Event(state *ui.State, event vaxis.Event) (processed neighbors.subscriptions.Subscribe(user) } neighbors.subscriptions.Write() - neighbors.list.SetItem(neighbors.list.Index(), formatNeighbor(user, neighbors.subscriptions)) + neighbors.list.SetItem(neighbors.list.Index(), []vaxis.Segment{{Text: formatNeighbor(user, neighbors.subscriptions)}}) case "Enter", "l", "Right": ui.ViewChange <- NewUserPage(neighbors.neighbors[neighbors.list.Index()].Name, false, neighbors.list.Index()) } diff --git a/app/publishing.go b/app/publishing.go index c0ab8c7..8d29d21 100644 --- a/app/publishing.go +++ b/app/publishing.go @@ -20,9 +20,9 @@ type Publishing struct { func NewPublishing() *Publishing { user, _ := user.Current() posts := ttbp.GetPostsForUser(user.Username) - list := []string{} + list := [][]vaxis.Segment{} for _, post := range posts { - list = append(list, formatPublishing(post)) + list = append(list, []vaxis.Segment{{Text: formatPublishing(post)}}) } return &Publishing{ @@ -71,13 +71,13 @@ func (publishing *Publishing) Event(state *ui.State, event vaxis.Event) (process if len(publishing.list.Items()) > 0 { publishing.posts[publishing.list.Index()].Nopub = !publishing.posts[publishing.list.Index()].Nopub ttbp.ToggleNopub(publishing.posts[publishing.list.Index()].Date) - publishing.list.SetItem(publishing.list.Index(), formatPublishing(publishing.posts[publishing.list.Index()])) + publishing.list.SetItem(publishing.list.Index(), []vaxis.Segment{{Text: formatPublishing(publishing.posts[publishing.list.Index()])}}) } case "m": if len(publishing.list.Items()) > 0 { publishing.posts[publishing.list.Index()].HTML = !publishing.posts[publishing.list.Index()].HTML ttbp.ToggleHTML(publishing.posts[publishing.list.Index()].Date) - publishing.list.SetItem(publishing.list.Index(), formatPublishing(publishing.posts[publishing.list.Index()])) + publishing.list.SetItem(publishing.list.Index(), []vaxis.Segment{{Text: formatPublishing(publishing.posts[publishing.list.Index()])}}) } } processed = true diff --git a/app/subscriptions.go b/app/subscriptions.go index e8a1ef9..a7b715f 100644 --- a/app/subscriptions.go +++ b/app/subscriptions.go @@ -19,11 +19,11 @@ type Subscriptions struct { func NewSubscriptions(index int) *Subscriptions { users := ttbp.SortUsersByRecent(ttbp.GetUsers()) subscriptions := ttbp.GetSubscriptions() - list := []string{} + list := [][]vaxis.Segment{} neighbors := []ttbp.User{} for _, user := range users { if subscriptions.IsSubscribed(user) { - list = append(list, formatNeighbor(user, subscriptions)) + list = append(list, []vaxis.Segment{{Text: formatNeighbor(user, subscriptions)}}) neighbors = append(neighbors, user) } } @@ -64,7 +64,7 @@ func (subscriptions *Subscriptions) Event(state *ui.State, event vaxis.Event) (p } else { subscriptions.subscriptions.Subscribe(user) } - subscriptions.list.SetItem(subscriptions.list.Index(), formatNeighbor(user, subscriptions.subscriptions)) + subscriptions.list.SetItem(subscriptions.list.Index(), []vaxis.Segment{{Text: formatNeighbor(user, subscriptions.subscriptions)}}) } case "Enter", "l", "Right": if len(subscriptions.list.Items()) > 0 { diff --git a/app/user.go b/app/user.go index 0bab213..b8f1ada 100644 --- a/app/user.go +++ b/app/user.go @@ -25,13 +25,13 @@ type UserPage struct { func NewUserPage(user string, self bool, index int) *UserPage { posts := ttbp.GetPostsForUser(user) - list := []string{} + list := [][]vaxis.Segment{} for _, post := range posts { - list = append(list, fmt.Sprintf( + list = append(list, []vaxis.Segment{{Text: fmt.Sprintf( "%s (%d words)", post.Date.Format("2006-01-02"), post.Words, - )) + )}}) } return &UserPage{ diff --git a/ui/list.go b/ui/list.go index cdf4ea8..ef6b828 100644 --- a/ui/list.go +++ b/ui/list.go @@ -13,11 +13,11 @@ import ( type List struct { index int - items []string + items [][]vaxis.Segment offset int } -func NewList(items []string, index int) List { +func NewList(items [][]vaxis.Segment, index int) List { return List{ items: items, index: index, @@ -32,7 +32,7 @@ func (m *List) Draw(win vaxis.Window) { m.offset = m.index } - defaultStyle := vaxis.Style{} + defaultStyle := vaxis.Style{Attribute: vaxis.AttrNone} selectedStyle := vaxis.Style{Attribute: vaxis.AttrReverse} index := m.index - m.offset @@ -43,7 +43,15 @@ func (m *List) Draw(win vaxis.Window) { } else { style = defaultStyle } - win.Println(i, vaxis.Segment{Text: fmt.Sprintf(" %-"+strconv.Itoa(win.Width-2)+"s", subject), Style: style}) + var styledSubject []vaxis.Segment + length := 0 + for _, chunk := range subject { + length += len(chunk.Text) + styledSubject = append(styledSubject, vaxis.Segment{Text: chunk.Text, Style: vaxis.Style{Attribute: style.Attribute | chunk.Style.Attribute}}) + } + styledSubject = append([]vaxis.Segment{{Text: " ", Style: style}}, styledSubject...) + styledSubject = append(styledSubject, vaxis.Segment{Text: fmt.Sprintf("%"+strconv.Itoa(win.Width-length-2)+"s", ""), Style: style}) + win.Println(i, styledSubject...) } } @@ -83,15 +91,23 @@ func (m *List) PageUp(win vaxis.Window) { } func (m *List) Items() []string { - return m.items + var items []string + for _, item := range m.items { + var text string + for _, chunk := range item { + text += chunk.Text + } + items = append(items, text) + } + return items } -func (m *List) SetItems(items []string) { +func (m *List) SetItems(items [][]vaxis.Segment) { m.items = items m.index = min(len(items)-1, m.index) } -func (m *List) SetItem(index int, item string) { +func (m *List) SetItem(index int, item []vaxis.Segment) { m.items[index] = item }