parent
9d4053da0b
commit
350727cd58
1
.nanpa/salsa-old-jam.kdl
Normal file
1
.nanpa/salsa-old-jam.kdl
Normal file
@ -0,0 +1 @@
|
||||
patch type="added" "shortcuts to list items in menu and management"
|
5
Makefile
5
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
|
||||
|
||||
|
@ -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{
|
||||
|
@ -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{
|
||||
|
@ -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{
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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{
|
||||
|
@ -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)
|
||||
|
70
app/menu.go
70
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)
|
||||
|
@ -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())
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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{
|
||||
|
30
ui/list.go
30
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
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user