save position of list

trunk
nbsp 2025-01-09 04:54:03 +02:00
parent cef04fb1a8
commit 0e00aeaf45
No known key found for this signature in database
GPG Key ID: 7184AC1C9835CE48
17 changed files with 43 additions and 39 deletions

View File

@ -0,0 +1 @@
patch type="added" "save position of previous list when going back"

View File

@ -37,7 +37,7 @@ func NewBackups() *Backups {
return &Backups{ return &Backups{
title, title,
ui.NewList(list), ui.NewList(list, 0),
"↑↓/kj move ↵ enter q return", "↑↓/kj move ↵ enter q return",
"choose a backup to restore", "choose a backup to restore",
backups, backups,
@ -61,7 +61,7 @@ func (backups *Backups) Event(state *ui.State, event vaxis.Event) (processed boo
i, _ := strconv.Atoi(key.String()) i, _ := strconv.Atoi(key.String())
backups.list.SetIndex(i) backups.list.SetIndex(i)
case "q", "h", "Left": case "q", "h", "Left":
ui.ViewChange <- NewManagement() ui.ViewChange <- NewManagement(3)
case "Enter", "l", "Right": case "Enter", "l", "Right":
if len(backups.list.Items()) > 0 { if len(backups.list.Items()) > 0 {
backups.LoadBackup(state) backups.LoadBackup(state)

View File

@ -35,7 +35,7 @@ func NewBrowse() *Browse {
return &Browse{ return &Browse{
title, title,
ui.NewList(list), ui.NewList(list, 0),
"↑↓/kj move ↵ enter q return", "↑↓/kj move ↵ enter q return",
posts, posts,
} }
@ -58,7 +58,7 @@ func (browse *Browse) Event(state *ui.State, event vaxis.Event) (processed bool)
i, _ := strconv.Atoi(key.String()) i, _ := strconv.Atoi(key.String())
browse.list.SetIndex(i) browse.list.SetIndex(i)
case "q", "h", "Left": case "q", "h", "Left":
ui.ViewChange <- NewMainMenu() ui.ViewChange <- NewMainMenu(3)
case "Enter", "l", "Right": case "Enter", "l", "Right":
showPost(state, browse.posts[browse.list.Index()]) showPost(state, browse.posts[browse.list.Index()])
} }

View File

@ -34,7 +34,7 @@ func NewBury() *Bury {
return &Bury{ return &Bury{
title, title,
ui.NewList(list), ui.NewList(list, 0),
"↑↓/kj move ↵ enter q return", "↑↓/kj move ↵ enter q return",
posts, posts,
} }
@ -57,7 +57,7 @@ func (bury *Bury) Event(state *ui.State, event vaxis.Event) (processed bool) {
i, _ := strconv.Atoi(key.String()) i, _ := strconv.Atoi(key.String())
bury.list.SetIndex(i) bury.list.SetIndex(i)
case "q", "h", "Left": case "q", "h", "Left":
ui.ViewChange <- NewManagement() ui.ViewChange <- NewManagement(4)
case "Enter", "l", "Right": case "Enter", "l", "Right":
if len(bury.list.Items()) > 0 { if len(bury.list.Items()) > 0 {
bury.Confirmation(state, func() { bury.Confirmation(state, func() {

View File

@ -31,7 +31,7 @@ func NewConfig() *Config {
} }
return &Config{ return &Config{
title, title,
ui.NewList(configList), ui.NewList(configList, 0),
"↑↓/kj move ↵ enter q return", "↑↓/kj move ↵ enter q return",
cfg, cfg,
[]string{ []string{
@ -82,7 +82,7 @@ func (config *Config) Event(state *ui.State, event vaxis.Event) (processed bool)
config.list.SetIndex(i) config.list.SetIndex(i)
} }
case "q", "h", "Left": case "q", "h", "Left":
ui.ViewChange <- NewMainMenu() ui.ViewChange <- NewMainMenu(6)
case "Enter", "l", "Right", "Space": case "Enter", "l", "Right", "Space":
switch config.list.Index() { switch config.list.Index() {
case 0: case 0:

View File

@ -31,7 +31,7 @@ func (credits *Credits) Event(state *ui.State, event vaxis.Event) (processed boo
case "Ctrl+c", "Ctrl+d": case "Ctrl+c", "Ctrl+d":
close(ui.Quit) close(ui.Quit)
case "Enter", "q", "h", "l", "Left", "Right": case "Enter", "q", "h", "l", "Left", "Right":
ui.ViewChange <- NewMainMenu() ui.ViewChange <- NewMainMenu(7)
} }
processed = true processed = true
} }

View File

@ -33,7 +33,7 @@ func NewDelete() *Delete {
return &Delete{ return &Delete{
title, title,
ui.NewList(list), ui.NewList(list, 0),
"↑↓/kj move ↵ enter q return", "↑↓/kj move ↵ enter q return",
posts, posts,
} }
@ -56,7 +56,7 @@ func (delete *Delete) Event(state *ui.State, event vaxis.Event) (processed bool)
i, _ := strconv.Atoi(key.String()) i, _ := strconv.Atoi(key.String())
delete.list.SetIndex(i) delete.list.SetIndex(i)
case "q", "h", "Left": case "q", "h", "Left":
ui.ViewChange <- NewManagement() ui.ViewChange <- NewManagement(5)
case "Enter", "l", "Right": case "Enter", "l", "Right":
if len(delete.list.Items()) > 0 { if len(delete.list.Items()) > 0 {
delete.Confirmation(state, func() { delete.Confirmation(state, func() {

View File

@ -42,14 +42,14 @@ func (graffiti *Graffiti) Event(state *ui.State, event vaxis.Event) (processed b
case "Ctrl+c", "Ctrl+d": case "Ctrl+c", "Ctrl+d":
close(ui.Quit) close(ui.Quit)
case "q", "h", "Left": case "q", "h", "Left":
ui.ViewChange <- NewMainMenu() ui.ViewChange <- NewMainMenu(5)
case "Enter", "l", "Right": case "Enter", "l", "Right":
if ttbp.GraffitiFree() { if ttbp.GraffitiFree() {
os.Create(ttbp.PathWallLock) os.Create(ttbp.PathWallLock)
editGraffiti(state) editGraffiti(state)
os.Remove(ttbp.PathWallLock) os.Remove(ttbp.PathWallLock)
} }
ui.ViewChange <- NewMainMenu() ui.ViewChange <- NewMainMenu(5)
} }
processed = true processed = true
} }

View File

@ -20,7 +20,7 @@ type Management struct {
help string help string
} }
func NewManagement() *Management { func NewManagement(index int) *Management {
return &Management{ return &Management{
title, title,
ui.NewList([]string{ ui.NewList([]string{
@ -32,7 +32,7 @@ func NewManagement() *Management {
"delete feels by day", "delete feels by day",
"purge all feels", "purge all feels",
"wipe feels account", "wipe feels account",
}), }, index),
"↑↓/kj move ↵ enter q return", "↑↓/kj move ↵ enter q return",
} }
} }
@ -54,12 +54,12 @@ func (management *Management) Event(state *ui.State, event vaxis.Event) (process
i, _ := strconv.Atoi(key.String()) i, _ := strconv.Atoi(key.String())
management.list.SetIndex(i) management.list.SetIndex(i)
case "q", "h", "Left": case "q", "h", "Left":
ui.ViewChange <- NewMainMenu() ui.ViewChange <- NewMainMenu(1)
case "Enter", "l", "Right": case "Enter", "l", "Right":
switch management.list.Index() { switch management.list.Index() {
case 0: case 0:
user, _ := user.Current() user, _ := user.Current()
ui.ViewChange <- NewUserPage(user.Username, true) ui.ViewChange <- NewUserPage(user.Username, true, 0)
case 1: case 1:
ui.ViewChange <- NewPublishing() ui.ViewChange <- NewPublishing()
case 2: case 2:

View File

@ -25,7 +25,7 @@ const title = ` ___ __
/_/ \__/\__/_/___/ /_/ \__/\__/_/___/
neofeels 0.1.0` neofeels 0.1.0`
func NewMainMenu() *MainMenu { func NewMainMenu(index int) *MainMenu {
return &MainMenu{ return &MainMenu{
title, title,
ui.NewList([]string{ ui.NewList([]string{
@ -38,7 +38,7 @@ func NewMainMenu() *MainMenu {
"change your settings", "change your settings",
"see credits", "see credits",
"read documentation", "read documentation",
}), }, index),
"↑↓/kj move ↵ enter q exit", "↑↓/kj move ↵ enter q exit",
} }
} }
@ -64,13 +64,13 @@ func (menu *MainMenu) Event(state *ui.State, event vaxis.Event) (processed bool)
case 0: case 0:
newFeels(state) newFeels(state)
case 1: case 1:
ui.ViewChange <- NewManagement() ui.ViewChange <- NewManagement(0)
case 2: case 2:
ui.ViewChange <- NewNeighbors() ui.ViewChange <- NewNeighbors(0)
case 3: case 3:
ui.ViewChange <- NewBrowse() ui.ViewChange <- NewBrowse()
case 4: case 4:
ui.ViewChange <- NewSubscriptions() ui.ViewChange <- NewSubscriptions(0)
case 5: case 5:
ui.ViewChange <- NewGraffiti() ui.ViewChange <- NewGraffiti()
case 6: case 6:

View File

@ -18,7 +18,7 @@ type Neighbors struct {
subscriptions *ttbp.Subscriptions subscriptions *ttbp.Subscriptions
} }
func NewNeighbors() *Neighbors { func NewNeighbors(index int) *Neighbors {
users := ttbp.SortUsersByRecent(ttbp.GetUsers()) users := ttbp.SortUsersByRecent(ttbp.GetUsers())
subscriptions := ttbp.GetSubscriptions() subscriptions := ttbp.GetSubscriptions()
list := []string{} list := []string{}
@ -28,7 +28,7 @@ func NewNeighbors() *Neighbors {
return &Neighbors{ return &Neighbors{
title, title,
ui.NewList(list), ui.NewList(list, index),
"↑↓/kj move ↵ enter s subscribe q return", "↑↓/kj move ↵ enter s subscribe q return",
users, users,
subscriptions, subscriptions,
@ -70,7 +70,7 @@ func (neighbors *Neighbors) Event(state *ui.State, event vaxis.Event) (processed
i, _ := strconv.Atoi(key.String()) i, _ := strconv.Atoi(key.String())
neighbors.list.SetIndex(i) neighbors.list.SetIndex(i)
case "q", "h", "Left": case "q", "h", "Left":
ui.ViewChange <- NewMainMenu() ui.ViewChange <- NewMainMenu(2)
case "s": case "s":
user := neighbors.neighbors[neighbors.list.Index()] user := neighbors.neighbors[neighbors.list.Index()]
if neighbors.subscriptions.IsSubscribed(user) { if neighbors.subscriptions.IsSubscribed(user) {
@ -81,7 +81,7 @@ func (neighbors *Neighbors) Event(state *ui.State, event vaxis.Event) (processed
neighbors.subscriptions.Write() neighbors.subscriptions.Write()
neighbors.list.SetItem(neighbors.list.Index(), formatNeighbor(user, neighbors.subscriptions)) neighbors.list.SetItem(neighbors.list.Index(), formatNeighbor(user, neighbors.subscriptions))
case "Enter", "l", "Right": case "Enter", "l", "Right":
ui.ViewChange <- NewUserPage(neighbors.neighbors[neighbors.list.Index()].Name, false) ui.ViewChange <- NewUserPage(neighbors.neighbors[neighbors.list.Index()].Name, false, neighbors.list.Index())
} }
processed = true processed = true
} }

View File

@ -40,7 +40,7 @@ func (posted *Posted) Event(state *ui.State, event vaxis.Event) (processed bool)
case "Ctrl+c", "Ctrl+d": case "Ctrl+c", "Ctrl+d":
close(ui.Quit) close(ui.Quit)
case "Enter", "q", "h", "l", "Left", "Right": case "Enter", "q", "h", "l", "Left", "Right":
ui.ViewChange <- NewMainMenu() ui.ViewChange <- NewMainMenu(0)
} }
processed = true processed = true
} }

View File

@ -27,7 +27,7 @@ func NewPublishing() *Publishing {
return &Publishing{ return &Publishing{
title, title,
ui.NewList(list), ui.NewList(list, 0),
"↑↓/kj move ↵ enter q return", "↑↓/kj move ↵ enter q return",
posts, posts,
} }
@ -63,7 +63,7 @@ func (publishing *Publishing) Event(state *ui.State, event vaxis.Event) (process
publishing.list.SetIndex(i) publishing.list.SetIndex(i)
case "q", "h", "Left": case "q", "h", "Left":
ttbp.Publish() ttbp.Publish()
ui.ViewChange <- NewManagement() ui.ViewChange <- NewManagement(1)
case "Enter", "l", "Right": case "Enter", "l", "Right":
if len(publishing.list.Items()) > 0 { if len(publishing.list.Items()) > 0 {
publishing.posts[publishing.list.Index()].Nopub = !publishing.posts[publishing.list.Index()].Nopub publishing.posts[publishing.list.Index()].Nopub = !publishing.posts[publishing.list.Index()].Nopub

View File

@ -16,7 +16,7 @@ type Subscriptions struct {
subscriptions *ttbp.Subscriptions subscriptions *ttbp.Subscriptions
} }
func NewSubscriptions() *Subscriptions { func NewSubscriptions(index int) *Subscriptions {
users := ttbp.SortUsersByRecent(ttbp.GetUsers()) users := ttbp.SortUsersByRecent(ttbp.GetUsers())
subscriptions := ttbp.GetSubscriptions() subscriptions := ttbp.GetSubscriptions()
list := []string{} list := []string{}
@ -30,7 +30,7 @@ func NewSubscriptions() *Subscriptions {
return &Subscriptions{ return &Subscriptions{
title, title,
ui.NewList(list), ui.NewList(list, index),
"↑↓/kj move ↵ enter s subscribe q return", "↑↓/kj move ↵ enter s subscribe q return",
neighbors, neighbors,
subscriptions, subscriptions,
@ -55,7 +55,7 @@ func (subscriptions *Subscriptions) Event(state *ui.State, event vaxis.Event) (p
subscriptions.list.SetIndex(i) subscriptions.list.SetIndex(i)
case "q", "h", "Left": case "q", "h", "Left":
subscriptions.subscriptions.Write() subscriptions.subscriptions.Write()
ui.ViewChange <- NewMainMenu() ui.ViewChange <- NewMainMenu(4)
case "s": case "s":
if len(subscriptions.list.Items()) > 0 { if len(subscriptions.list.Items()) > 0 {
user := subscriptions.neighbors[subscriptions.list.Index()] user := subscriptions.neighbors[subscriptions.list.Index()]
@ -69,7 +69,7 @@ func (subscriptions *Subscriptions) Event(state *ui.State, event vaxis.Event) (p
case "Enter", "l", "Right": case "Enter", "l", "Right":
if len(subscriptions.list.Items()) > 0 { if len(subscriptions.list.Items()) > 0 {
subscriptions.subscriptions.Write() subscriptions.subscriptions.Write()
ui.ViewChange <- NewUserPage(subscriptions.neighbors[subscriptions.list.Index()].Name, false) ui.ViewChange <- NewUserPage(subscriptions.neighbors[subscriptions.list.Index()].Name, false, subscriptions.list.Index())
} }
} }
processed = true processed = true

View File

@ -19,9 +19,10 @@ type UserPage struct {
help string help string
posts []ttbp.Post posts []ttbp.Post
self bool self bool
index int // which index on the previous page to return to?
} }
func NewUserPage(user string, self bool) *UserPage { func NewUserPage(user string, self bool, index int) *UserPage {
posts := ttbp.GetPostsForUser(user) posts := ttbp.GetPostsForUser(user)
list := []string{} list := []string{}
for _, post := range posts { for _, post := range posts {
@ -34,10 +35,11 @@ func NewUserPage(user string, self bool) *UserPage {
return &UserPage{ return &UserPage{
title, title,
ui.NewList(list), ui.NewList(list, 0),
"↑↓/kj move ↵ enter q return", "↑↓/kj move ↵ enter q return",
posts, posts,
self, self,
index,
} }
} }
@ -59,9 +61,9 @@ func (user *UserPage) Event(state *ui.State, event vaxis.Event) (processed bool)
user.list.SetIndex(i) user.list.SetIndex(i)
case "q", "h", "Left": case "q", "h", "Left":
if user.self { if user.self {
ui.ViewChange <- NewManagement() ui.ViewChange <- NewManagement(0)
} else { } else {
ui.ViewChange <- NewNeighbors() ui.ViewChange <- NewNeighbors(user.index)
} }
case "Enter", "l", "Right": case "Enter", "l", "Right":
showPost(state, user.posts[user.list.Index()]) showPost(state, user.posts[user.list.Index()])

View File

@ -53,7 +53,7 @@ func main() {
initializePrompt() initializePrompt()
} }
state, err := ui.New(app.NewMainMenu()) state, err := ui.New(app.NewMainMenu(0))
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@ -17,9 +17,10 @@ type List struct {
offset int offset int
} }
func NewList(items []string) List { func NewList(items []string, index int) List {
return List{ return List{
items: items, items: items,
index: index,
} }
} }