diff --git a/.nanparc b/.nanparc new file mode 100644 index 0000000..e5d5119 --- /dev/null +++ b/.nanparc @@ -0,0 +1 @@ +version 0.1.0 diff --git a/README.md b/README.md index 3406dac..f9fa850 100644 --- a/README.md +++ b/README.md @@ -14,16 +14,15 @@ make - [x] main menu - [x] credits -- [ ] feels browser -- [ ] configuration editor -- [x] feels publishing +- [x] feels browser +- [x] configuration editor +- [ ] feels manager +- [ ] feels publishing + - [x] plaintext + - [ ] html + - [ ] gopher - [ ] graffiti -- [ ] feedback -- [ ] documentation with manpages - -nice-to-haves: -- [ ] mouse support -- [ ] image support via sixels +- [x] documentation with manpages ## contributing diff --git a/app/menu.go b/app/menu.go index 1e076e2..5c6316e 100644 --- a/app/menu.go +++ b/app/menu.go @@ -32,8 +32,8 @@ func NewMainMenu() *MainMenu { "manage your feels", "check out your neighbors", "browse global feels", - "visit your subscriptions", // TODO - "scribble some graffiti", // TODO + "visit your subscriptions", + "scribble some graffiti", // TODO "change your settings", "see credits", "read documentation", @@ -68,6 +68,8 @@ func (menu *MainMenu) Event(state *ui.State, event vaxis.Event) (processed bool) ui.ViewChange <- NewNeighbors() case 3: ui.ViewChange <- NewBrowse() + case 4: + ui.ViewChange <- NewSubscriptions() case 6: ui.ViewChange <- NewConfig() case 7: diff --git a/app/neighbors.go b/app/neighbors.go index d2635de..17f5ccb 100644 --- a/app/neighbors.go +++ b/app/neighbors.go @@ -78,6 +78,7 @@ func (neighbors *Neighbors) Event(state *ui.State, event vaxis.Event) (processed } else { neighbors.subscriptions.Subscribe(user) } + 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) diff --git a/app/subscriptions.go b/app/subscriptions.go new file mode 100644 index 0000000..38b597b --- /dev/null +++ b/app/subscriptions.go @@ -0,0 +1,94 @@ +package app + +import ( + "strconv" + + "git.sr.ht/~rockorager/vaxis" + "git.tilde.town/nbsp/neofeels/ttbp" + "git.tilde.town/nbsp/neofeels/ui" +) + +type Subscriptions struct { + title string + list ui.List + help string + neighbors []ttbp.User + subscriptions *ttbp.Subscriptions +} + +func NewSubscriptions() *Subscriptions { + users := ttbp.SortUsersByRecent(ttbp.GetUsers()) + subscriptions := ttbp.GetSubscriptions() + list := []string{} + neighbors := []ttbp.User{} + for _, user := range users { + if subscriptions.IsSubscribed(user) { + list = append(list, formatNeighbor(user, subscriptions)) + neighbors = append(neighbors, user) + } + } + + return &Subscriptions{ + title, + ui.NewList(list), + "↑↓/kj move ↵ enter s subscribe q return", + neighbors, + subscriptions, + } +} + +func (subscriptions *Subscriptions) Event(state *ui.State, event vaxis.Event) (processed bool) { + if key, ok := event.(vaxis.Key); ok && key.EventType == vaxis.EventPress { + switch key.String() { + case "Ctrl+c", "Ctrl+d": + close(ui.Quit) + case "Down", "j": + subscriptions.list.Down() + case "Up", "k": + subscriptions.list.Up() + case "End", "Shift+g": + subscriptions.list.End() + case "Home", "g": + subscriptions.list.Home() + case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9": + i, _ := strconv.Atoi(key.String()) + subscriptions.list.SetIndex(i) + case "q", "h", "Left": + subscriptions.subscriptions.Write() + ui.ViewChange <- NewMainMenu() + case "s": + if len(subscriptions.list.Items()) > 0 { + user := subscriptions.neighbors[subscriptions.list.Index()] + if subscriptions.subscriptions.IsSubscribed(user) { + subscriptions.subscriptions.Unsubscribe(user) + } else { + subscriptions.subscriptions.Subscribe(user) + } + subscriptions.list.SetItem(subscriptions.list.Index(), formatNeighbor(user, subscriptions.subscriptions)) + } + case "Enter", "l", "Right": + subscriptions.subscriptions.Write() + ui.ViewChange <- NewUserPage(subscriptions.neighbors[subscriptions.list.Index()].Name) + } + processed = true + } + subscriptions.Draw(state) + return +} + +func (subscriptions *Subscriptions) Draw(state *ui.State) { + win := state.Window() + win.New(win.Width/2-10, win.Height/2-8, 20, 5).Print(vaxis.Segment{Text: subscriptions.title}) + subscriptions.list.Draw(vaxis.Window{ + Vx: win.Vx, + Parent: nil, + Column: win.Width/2 - 40, + Row: win.Height/2 - 2, + Width: 80, + Height: 10, + }) + if len(subscriptions.list.Items()) == 0 { + win.New(win.Width/2-22, win.Height/2-1, 44, 2).Print(vaxis.Segment{Text: "no subscriptions yet\nvisit your neighbors to subscribe to them!"}) + } + win.New(win.Width/2-22, win.Height/2+9, 44, 1).Print(vaxis.Segment{Text: subscriptions.help}) +} diff --git a/ttbp/ttbp.go b/ttbp/ttbp.go index 0e701a7..2003898 100644 --- a/ttbp/ttbp.go +++ b/ttbp/ttbp.go @@ -171,20 +171,18 @@ func (subscriptions *Subscriptions) IsSubscribed(user User) bool { func (subscriptions *Subscriptions) Subscribe(user User) { subscriptions.users = append(subscriptions.users, user.Name) - subscriptions.write() } func (subscriptions *Subscriptions) Unsubscribe(user User) { for i, sub := range subscriptions.users { if sub == user.Name { subscriptions.users = append(subscriptions.users[:i], subscriptions.users[i+1:]...) - subscriptions.write() return } } } -func (subscriptions *Subscriptions) write() { +func (subscriptions *Subscriptions) Write() { file, err := os.Create(path.Join(os.Getenv("HOME"), ".ttbp/config/subs")) if err != nil { return