save position of list
parent
cef04fb1a8
commit
0e00aeaf45
|
@ -0,0 +1 @@
|
|||
patch type="added" "save position of previous list when going back"
|
|
@ -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)
|
||||
|
|
|
@ -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()])
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
10
app/menu.go
10
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:
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
10
app/user.go
10
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()])
|
||||
|
|
2
main.go
2
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)
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue