pico
created pr with
48.1
added 48.2
1: 9033000 = 1: 9033000 refactor(tui): use vaxis
-: ------- > 2: e191f12 chore(tui): setup page navigation
changed status to
accepted
cmds
checkout latest patchset:
ssh pr.pico.sh print 48 | git am -3checkout any patchset in a patch request:
ssh pr.pico.sh print 48.[rev] | git am -3add changes to patch request:
git format-patch main --stdout | ssh pr.pico.sh pr add 48set PR to open (enables RSS notifications):
ssh pr.pico.sh pr open 48set PR to draft (stops RSS notifications):
ssh pr.pico.sh pr draft 48
Patchset
48.2
chore(tui): setup page navigation
Eric Bower
2025-02-25T01:15:47ZSemantic diff summary
6 added,
3 modified,
2 signature changed,
0 removed
across 3 analyzed files
(2 files skipped: unsupported file type)
+3
-3
go.mod
#
| ... | ... | @@ -16,17 +16,17 @@ go 1.23.1 | |
| 16 | 16 | ||
| 17 | 17 | // replace git.sr.ht/~delthas/senpai => ../../senpai | |
| 18 | 18 | ||
| 19 | - | // replace git.sr.ht/~rockorager/vaxis => ../../vaxis | |
| 19 | + | replace git.sr.ht/~rockorager/vaxis => ../../../src/vaxis | |
| 20 | 20 | ||
| 21 | 21 | // replace github.com/charmbracelet/wish => ../../wish | |
| 22 | 22 | ||
| 23 | 23 | replace git.sr.ht/~delthas/senpai => github.com/antoniomika/senpai v0.0.0-20250114180426-3061ddccec76 | |
| 24 | 24 | ||
| 25 | - | replace git.sr.ht/~rockorager/vaxis => github.com/antoniomika/vaxis v0.0.0-20250114030546-8524674789ca | |
| 25 | + | // replace git.sr.ht/~rockorager/vaxis => github.com/antoniomika/vaxis v0.0.0-20250114030546-8524674789ca | |
| 26 | 26 | ||
| 27 | 27 | require ( | |
| 28 | 28 | git.sr.ht/~delthas/senpai v0.3.1-0.20240425235039-206be659439e | |
| 29 | - | git.sr.ht/~rockorager/vaxis v0.10.3 | |
| 29 | + | git.sr.ht/~rockorager/vaxis v0.12.1-0.20250219164615-8231ece877f3 | |
| 30 | 30 | github.com/alecthomas/chroma/v2 v2.14.0 | |
| 31 | 31 | github.com/antoniomika/syncmap v1.0.0 | |
| 32 | 32 | github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de |
+0
-2
go.sum
#
| ... | ... | @@ -68,8 +68,6 @@ github.com/antoniomika/senpai v0.0.0-20250114180426-3061ddccec76 h1:WAGPWAxThUoz | |
| 68 | 68 | github.com/antoniomika/senpai v0.0.0-20250114180426-3061ddccec76/go.mod h1:HIPY7uPDy44ep6xKwfsW6JTmDUTiC5DXh0l4yZP/aT4= | |
| 69 | 69 | github.com/antoniomika/syncmap v1.0.0 h1:iFSfbQFQOvHZILFZF+hqWosO0no+W9+uF4y2VEyMKWU= | |
| 70 | 70 | github.com/antoniomika/syncmap v1.0.0/go.mod h1:fK2829foEYnO4riNfyUn0SHQZt4ue3DStYjGU+sJj38= | |
| 71 | - | github.com/antoniomika/vaxis v0.0.0-20250114030546-8524674789ca h1:vD1Ioetf2ikrlkvHu7FIpbPgtMIJpaU16YRR+HA+/2Y= | |
| 72 | - | github.com/antoniomika/vaxis v0.0.0-20250114030546-8524674789ca/go.mod h1:h94aKek3frIV1hJbdXjqnBqaLkbWXvV+UxAsQHg9bns= | |
| 73 | 71 | github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de h1:FxWPpzIjnTlhPwqqXc4/vE0f7GvRjuAsbW+HOIe8KnA= | |
| 74 | 72 | github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de/go.mod h1:DCaWoUhZrYW9p1lxo/cm8EmUOOzAPSEZNGF2DK1dJgw= | |
| 75 | 73 | github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= |
+13
-4
pico/ssh_vaxis.go
#
| ... | ... | @@ -27,14 +28,22 @@ import ( | |
| 27 | 28 | ) | |
| 28 | 29 | ||
| 29 | 30 | func createRouterVaxis(cfg *shared.ConfigSite, handler *UploadHandler, cliHandler *CliHandler) proxy.Router { | |
| 30 | - | return func(sh ssh.Handler, s ssh.Session) []wish.Middleware { | |
| 31 | + | return func(sh ssh.Handler, sesh ssh.Session) []wish.Middleware { | |
| 32 | + | shrd := &common.SharedModel{ | |
| 33 | + | Session: sesh, | |
| 34 | + | Cfg: cfg, | |
| 35 | + | Dbpool: handler.DBPool, | |
| 36 | + | Width: 80, | |
| 37 | + | Height: 24, | |
| 38 | + | Logger: cfg.Logger, | |
| 39 | + | } | |
| 31 | 40 | return []wish.Middleware{ | |
| 32 | 41 | pipe.Middleware(handler, ""), | |
| 33 | 42 | list.Middleware(handler), | |
| 34 | 43 | scp.Middleware(handler), | |
| 35 | 44 | wishrsync.Middleware(handler), | |
| 36 | 45 | auth.Middleware(handler), | |
| 37 | - | wsh.PtyMdw(createTui()), | |
| 46 | + | wsh.PtyMdw(createTui(shrd)), | |
| 38 | 47 | WishMiddleware(cliHandler), | |
| 39 | 48 | wsh.LogMiddleware(handler.GetLogger()), | |
| 40 | 49 | } |
| ... | ... | @@ -52,7 +61,7 @@ func withProxyVaxis(cfg *shared.ConfigSite, handler *UploadHandler, cliHandler * | |
| 52 | 61 | } | |
| 53 | 62 | } | |
| 54 | 63 | ||
| 55 | - | func createTui() wish.Middleware { | |
| 64 | + | func createTui(shrd *common.SharedModel) wish.Middleware { | |
| 56 | 65 | return func(next ssh.Handler) ssh.Handler { | |
| 57 | 66 | return func(sesh ssh.Session) { | |
| 58 | 67 | vty, err := shared.NewVConsole(sesh) |
+8
-1
tui/pages/pages.go
#
+90
-13
tuivax/ui.go
#
| ... | ... | @@ -1,30 +1,107 @@ | |
| 1 | 1 | package tuivax | |
| 2 | 2 | ||
| 3 | 3 | import ( | |
| 4 | + | "fmt" | |
| 5 | + | ||
| 4 | 6 | "git.sr.ht/~rockorager/vaxis" | |
| 7 | + | "git.sr.ht/~rockorager/vaxis/widgets/list" | |
| 8 | + | "github.com/picosh/pico/tui/common" | |
| 5 | 9 | ) | |
| 6 | 10 | ||
| 7 | - | func NewTui(opts vaxis.Options) { | |
| 11 | + | var menuChoices = []string{ | |
| 12 | + | "pubkeys", | |
| 13 | + | "tokens", | |
| 14 | + | "settings", | |
| 15 | + | "logs", | |
| 16 | + | "analytics", | |
| 17 | + | "chat", | |
| 18 | + | "pico+", | |
| 19 | + | } | |
| 20 | + | ||
| 21 | + | type UIVx struct { | |
| 22 | + | shared *common.SharedModel | |
| 23 | + | vx *vaxis.Vaxis | |
| 24 | + | ||
| 25 | + | page string | |
| 26 | + | quit bool | |
| 27 | + | menu list.List | |
| 28 | + | } | |
| 29 | + | ||
| 30 | + | type Navigate struct { | |
| 31 | + | To string | |
| 32 | + | } | |
| 33 | + | ||
| 34 | + | type Quit struct{} | |
| 35 | + | ||
| 36 | + | func (ui *UIVx) menuPage(win vaxis.Window, ev vaxis.Event) { | |
| 37 | + | switch msg := ev.(type) { | |
| 38 | + | case vaxis.Key: | |
| 39 | + | switch msg.String() { | |
| 40 | + | case "Ctrl+c", "q", "Escape": | |
| 41 | + | ui.quit = true | |
| 42 | + | case "Down", "j": | |
| 43 | + | ui.menu.Down() | |
| 44 | + | case "Up", "k": | |
| 45 | + | ui.menu.Up() | |
| 46 | + | case "Enter": | |
| 47 | + | ui.page = menuChoices[ui.menu.Index()] | |
| 48 | + | } | |
| 49 | + | } | |
| 50 | + | ui.menu.Draw(win) | |
| 51 | + | } | |
| 52 | + | ||
| 53 | + | func (ui *UIVx) keysPage(win vaxis.Window, ev vaxis.Event) { | |
| 54 | + | switch msg := ev.(type) { | |
| 55 | + | case vaxis.Key: | |
| 56 | + | switch msg.String() { | |
| 57 | + | case "Ctrl+c": | |
| 58 | + | ui.quit = true | |
| 59 | + | case "q", "Escape": | |
| 60 | + | ui.page = "menu" | |
| 61 | + | } | |
| 62 | + | } | |
| 63 | + | win.Print(vaxis.Segment{Text: "Hello, World!"}) | |
| 64 | + | } | |
| 65 | + | ||
| 66 | + | func NewTui(opts vaxis.Options, shared *common.SharedModel) { | |
| 8 | 67 | vx, err := vaxis.New(opts) | |
| 9 | 68 | if err != nil { | |
| 10 | 69 | panic(err) | |
| 11 | 70 | } | |
| 12 | 71 | defer vx.Close() | |
| 72 | + | ||
| 73 | + | ui := UIVx{ | |
| 74 | + | shared: shared, | |
| 75 | + | vx: vx, | |
| 76 | + | ||
| 77 | + | page: "menu", | |
| 78 | + | menu: list.New(menuChoices), | |
| 79 | + | } | |
| 80 | + | ||
| 13 | 81 | for ev := range vx.Events() { | |
| 14 | - | switch ev := ev.(type) { | |
| 15 | - | case vaxis.Key: | |
| 16 | - | switch ev.String() { | |
| 17 | - | case "Ctrl+c": | |
| 18 | - | return | |
| 19 | - | case "q": | |
| 20 | - | return | |
| 21 | - | case "Escape": | |
| 22 | - | return | |
| 23 | - | } | |
| 24 | - | } | |
| 25 | 82 | win := vx.Window() | |
| 26 | 83 | win.Clear() | |
| 27 | - | win.Print(vaxis.Segment{Text: "Hello, World!"}) | |
| 84 | + | ||
| 85 | + | // header | |
| 86 | + | win.Print(vaxis.Segment{ | |
| 87 | + | Text: fmt.Sprintf("pico.sh • %s", ui.page), | |
| 88 | + | }) | |
| 89 | + | ||
| 90 | + | // page window | |
| 91 | + | width, height := win.Size() | |
| 92 | + | pageWin := win.New(0, 2, width, height-2) | |
| 93 | + | ||
| 94 | + | switch ui.page { | |
| 95 | + | case "menu": | |
| 96 | + | ui.menuPage(pageWin, ev) | |
| 97 | + | case "pubkeys": | |
| 98 | + | ui.keysPage(pageWin, ev) | |
| 99 | + | } | |
| 100 | + | ||
| 101 | + | if ui.quit { | |
| 102 | + | return | |
| 103 | + | } | |
| 104 | + | ||
| 28 | 105 | vx.Render() | |
| 29 | 106 | } | |
| 30 | 107 | } |