diff --git a/.nanpa/position.kdl b/.nanpa/position.kdl new file mode 100644 index 0000000..3d3d56f --- /dev/null +++ b/.nanpa/position.kdl @@ -0,0 +1 @@ +patch type="added" "save position of previous list when going back" diff --git a/app/backups.go b/app/backups.go index 86f4e52..f8bc2c6 100644 --- a/app/backups.go +++ b/app/backups.go @@ -37,7 +37,7 @@ func NewBackups() *Backups { return &Backups{ title, - ui.NewList(list), + ui.NewList(list, 0), "↑↓/kj move ↵ enter q return", "choose a backup to restore", backups, @@ -61,7 +61,7 @@ func (backups *Backups) Event(state *ui.State, event vaxis.Event) (processed boo i, _ := strconv.Atoi(key.String()) backups.list.SetIndex(i) case "q", "h", "Left": - ui.ViewChange <- NewManagement() + ui.ViewChange <- NewManagement(3) case "Enter", "l", "Right": if len(backups.list.Items()) > 0 { backups.LoadBackup(state) diff --git a/app/browse.go b/app/browse.go index 817c8ae..809de3c 100644 --- a/app/browse.go +++ b/app/browse.go @@ -35,7 +35,7 @@ func NewBrowse() *Browse { return &Browse{ title, - ui.NewList(list), + ui.NewList(list, 0), "↑↓/kj move ↵ enter q return", posts, } @@ -58,7 +58,7 @@ func (browse *Browse) Event(state *ui.State, event vaxis.Event) (processed bool) i, _ := strconv.Atoi(key.String()) browse.list.SetIndex(i) case "q", "h", "Left": - ui.ViewChange <- NewMainMenu() + ui.ViewChange <- NewMainMenu(3) case "Enter", "l", "Right": showPost(state, browse.posts[browse.list.Index()]) } diff --git a/app/bury.go b/app/bury.go index b6225f5..3ba4f45 100644 --- a/app/bury.go +++ b/app/bury.go @@ -34,7 +34,7 @@ func NewBury() *Bury { return &Bury{ title, - ui.NewList(list), + ui.NewList(list, 0), "↑↓/kj move ↵ enter q return", posts, } @@ -57,7 +57,7 @@ func (bury *Bury) Event(state *ui.State, event vaxis.Event) (processed bool) { i, _ := strconv.Atoi(key.String()) bury.list.SetIndex(i) case "q", "h", "Left": - ui.ViewChange <- NewManagement() + ui.ViewChange <- NewManagement(4) case "Enter", "l", "Right": if len(bury.list.Items()) > 0 { bury.Confirmation(state, func() { diff --git a/app/config.go b/app/config.go index aa8e7e5..7c2c3c3 100644 --- a/app/config.go +++ b/app/config.go @@ -31,7 +31,7 @@ func NewConfig() *Config { } return &Config{ title, - ui.NewList(configList), + ui.NewList(configList, 0), "↑↓/kj move ↵ enter q return", cfg, []string{ @@ -82,7 +82,7 @@ func (config *Config) Event(state *ui.State, event vaxis.Event) (processed bool) config.list.SetIndex(i) } case "q", "h", "Left": - ui.ViewChange <- NewMainMenu() + ui.ViewChange <- NewMainMenu(6) case "Enter", "l", "Right", "Space": switch config.list.Index() { case 0: diff --git a/app/credits.go b/app/credits.go index b85cd70..dd2e800 100644 --- a/app/credits.go +++ b/app/credits.go @@ -31,7 +31,7 @@ func (credits *Credits) Event(state *ui.State, event vaxis.Event) (processed boo case "Ctrl+c", "Ctrl+d": close(ui.Quit) case "Enter", "q", "h", "l", "Left", "Right": - ui.ViewChange <- NewMainMenu() + ui.ViewChange <- NewMainMenu(7) } processed = true } diff --git a/app/delete.go b/app/delete.go index ffad527..2a6285e 100644 --- a/app/delete.go +++ b/app/delete.go @@ -33,7 +33,7 @@ func NewDelete() *Delete { return &Delete{ title, - ui.NewList(list), + ui.NewList(list, 0), "↑↓/kj move ↵ enter q return", posts, } @@ -56,7 +56,7 @@ func (delete *Delete) Event(state *ui.State, event vaxis.Event) (processed bool) i, _ := strconv.Atoi(key.String()) delete.list.SetIndex(i) case "q", "h", "Left": - ui.ViewChange <- NewManagement() + ui.ViewChange <- NewManagement(5) case "Enter", "l", "Right": if len(delete.list.Items()) > 0 { delete.Confirmation(state, func() { diff --git a/app/graffiti.go b/app/graffiti.go index 3fa22c5..71e3713 100644 --- a/app/graffiti.go +++ b/app/graffiti.go @@ -42,14 +42,14 @@ func (graffiti *Graffiti) Event(state *ui.State, event vaxis.Event) (processed b case "Ctrl+c", "Ctrl+d": close(ui.Quit) case "q", "h", "Left": - ui.ViewChange <- NewMainMenu() + ui.ViewChange <- NewMainMenu(5) case "Enter", "l", "Right": if ttbp.GraffitiFree() { os.Create(ttbp.PathWallLock) editGraffiti(state) os.Remove(ttbp.PathWallLock) } - ui.ViewChange <- NewMainMenu() + ui.ViewChange <- NewMainMenu(5) } processed = true } diff --git a/app/management.go b/app/management.go index 3c87a7a..93aee59 100644 --- a/app/management.go +++ b/app/management.go @@ -20,7 +20,7 @@ type Management struct { help string } -func NewManagement() *Management { +func NewManagement(index int) *Management { return &Management{ title, ui.NewList([]string{ @@ -32,7 +32,7 @@ func NewManagement() *Management { "delete feels by day", "purge all feels", "wipe feels account", - }), + }, index), "↑↓/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()) management.list.SetIndex(i) case "q", "h", "Left": - ui.ViewChange <- NewMainMenu() + ui.ViewChange <- NewMainMenu(1) case "Enter", "l", "Right": switch management.list.Index() { case 0: user, _ := user.Current() - ui.ViewChange <- NewUserPage(user.Username, true) + ui.ViewChange <- NewUserPage(user.Username, true, 0) case 1: ui.ViewChange <- NewPublishing() case 2: diff --git a/app/menu.go b/app/menu.go index acac71d..f131025 100644 --- a/app/menu.go +++ b/app/menu.go @@ -25,7 +25,7 @@ const title = ` ___ __ /_/ \__/\__/_/___/ neofeels 0.1.0` -func NewMainMenu() *MainMenu { +func NewMainMenu(index int) *MainMenu { return &MainMenu{ title, ui.NewList([]string{ @@ -38,7 +38,7 @@ func NewMainMenu() *MainMenu { "change your settings", "see credits", "read documentation", - }), + }, index), "↑↓/kj move ↵ enter q exit", } } @@ -64,13 +64,13 @@ func (menu *MainMenu) Event(state *ui.State, event vaxis.Event) (processed bool) case 0: newFeels(state) case 1: - ui.ViewChange <- NewManagement() + ui.ViewChange <- NewManagement(0) case 2: - ui.ViewChange <- NewNeighbors() + ui.ViewChange <- NewNeighbors(0) case 3: ui.ViewChange <- NewBrowse() case 4: - ui.ViewChange <- NewSubscriptions() + ui.ViewChange <- NewSubscriptions(0) case 5: ui.ViewChange <- NewGraffiti() case 6: diff --git a/app/neighbors.go b/app/neighbors.go index b3078b9..4365752 100644 --- a/app/neighbors.go +++ b/app/neighbors.go @@ -18,7 +18,7 @@ type Neighbors struct { subscriptions *ttbp.Subscriptions } -func NewNeighbors() *Neighbors { +func NewNeighbors(index int) *Neighbors { users := ttbp.SortUsersByRecent(ttbp.GetUsers()) subscriptions := ttbp.GetSubscriptions() list := []string{} @@ -28,7 +28,7 @@ func NewNeighbors() *Neighbors { return &Neighbors{ title, - ui.NewList(list), + ui.NewList(list, index), "↑↓/kj move ↵ enter s subscribe q return", users, subscriptions, @@ -70,7 +70,7 @@ func (neighbors *Neighbors) Event(state *ui.State, event vaxis.Event) (processed i, _ := strconv.Atoi(key.String()) neighbors.list.SetIndex(i) case "q", "h", "Left": - ui.ViewChange <- NewMainMenu() + ui.ViewChange <- NewMainMenu(2) case "s": user := neighbors.neighbors[neighbors.list.Index()] if neighbors.subscriptions.IsSubscribed(user) { @@ -81,7 +81,7 @@ func (neighbors *Neighbors) Event(state *ui.State, event vaxis.Event) (processed neighbors.subscriptions.Write() neighbors.list.SetItem(neighbors.list.Index(), formatNeighbor(user, neighbors.subscriptions)) 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 } diff --git a/app/posted.go b/app/posted.go index 2776afd..a12db54 100644 --- a/app/posted.go +++ b/app/posted.go @@ -40,7 +40,7 @@ func (posted *Posted) Event(state *ui.State, event vaxis.Event) (processed bool) case "Ctrl+c", "Ctrl+d": close(ui.Quit) case "Enter", "q", "h", "l", "Left", "Right": - ui.ViewChange <- NewMainMenu() + ui.ViewChange <- NewMainMenu(0) } processed = true } diff --git a/app/publishing.go b/app/publishing.go index 5b87a94..c792973 100644 --- a/app/publishing.go +++ b/app/publishing.go @@ -27,7 +27,7 @@ func NewPublishing() *Publishing { return &Publishing{ title, - ui.NewList(list), + ui.NewList(list, 0), "↑↓/kj move ↵ enter q return", posts, } @@ -63,7 +63,7 @@ func (publishing *Publishing) Event(state *ui.State, event vaxis.Event) (process publishing.list.SetIndex(i) case "q", "h", "Left": ttbp.Publish() - ui.ViewChange <- NewManagement() + ui.ViewChange <- NewManagement(1) case "Enter", "l", "Right": if len(publishing.list.Items()) > 0 { publishing.posts[publishing.list.Index()].Nopub = !publishing.posts[publishing.list.Index()].Nopub diff --git a/app/subscriptions.go b/app/subscriptions.go index d853887..e8a1ef9 100644 --- a/app/subscriptions.go +++ b/app/subscriptions.go @@ -16,7 +16,7 @@ type Subscriptions struct { subscriptions *ttbp.Subscriptions } -func NewSubscriptions() *Subscriptions { +func NewSubscriptions(index int) *Subscriptions { users := ttbp.SortUsersByRecent(ttbp.GetUsers()) subscriptions := ttbp.GetSubscriptions() list := []string{} @@ -30,7 +30,7 @@ func NewSubscriptions() *Subscriptions { return &Subscriptions{ title, - ui.NewList(list), + ui.NewList(list, index), "↑↓/kj move ↵ enter s subscribe q return", neighbors, subscriptions, @@ -55,7 +55,7 @@ func (subscriptions *Subscriptions) Event(state *ui.State, event vaxis.Event) (p subscriptions.list.SetIndex(i) case "q", "h", "Left": subscriptions.subscriptions.Write() - ui.ViewChange <- NewMainMenu() + ui.ViewChange <- NewMainMenu(4) case "s": if len(subscriptions.list.Items()) > 0 { 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": if len(subscriptions.list.Items()) > 0 { 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 diff --git a/app/user.go b/app/user.go index 929effd..7576584 100644 --- a/app/user.go +++ b/app/user.go @@ -19,9 +19,10 @@ type UserPage struct { help string posts []ttbp.Post 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) list := []string{} for _, post := range posts { @@ -34,10 +35,11 @@ func NewUserPage(user string, self bool) *UserPage { return &UserPage{ title, - ui.NewList(list), + ui.NewList(list, 0), "↑↓/kj move ↵ enter q return", posts, self, + index, } } @@ -59,9 +61,9 @@ func (user *UserPage) Event(state *ui.State, event vaxis.Event) (processed bool) user.list.SetIndex(i) case "q", "h", "Left": if user.self { - ui.ViewChange <- NewManagement() + ui.ViewChange <- NewManagement(0) } else { - ui.ViewChange <- NewNeighbors() + ui.ViewChange <- NewNeighbors(user.index) } case "Enter", "l", "Right": showPost(state, user.posts[user.list.Index()]) diff --git a/main.go b/main.go index 8745207..b2bfa3f 100644 --- a/main.go +++ b/main.go @@ -53,7 +53,7 @@ func main() { initializePrompt() } - state, err := ui.New(app.NewMainMenu()) + state, err := ui.New(app.NewMainMenu(0)) if err != nil { panic(err) } diff --git a/ui/list.go b/ui/list.go index a042982..cdf4ea8 100644 --- a/ui/list.go +++ b/ui/list.go @@ -17,9 +17,10 @@ type List struct { offset int } -func NewList(items []string) List { +func NewList(items []string, index int) List { return List{ items: items, + index: index, } }