feat(login): configure tabs with [ui.tabs]

This commit is contained in:
ayn2op 2026-09-30 19:39:58 -04:00
parent 837e615d1a
commit dd2e690c34
6 changed files with 48 additions and 5 deletions

2
go.mod
View file

@ -15,7 +15,7 @@ require (
github.com/andybalholm/brotli v1.2.6
github.com/ayn2op/arikawa/v3 v3.0.0-20260929021956-7d0802bf4d7c
github.com/ayn2op/ningen/v3 v3.0.1-0.20260929010920-29794d5fa70e
github.com/ayn2op/tview v0.0.0-20260930215038-4bb4ac90d11c
github.com/ayn2op/tview v0.0.0-20260930235645-239215f3c690
github.com/bogdanfinn/fhttp v0.6.9
github.com/bogdanfinn/tls-client v1.16.0
github.com/gdamore/tcell/v3 v3.5.0

4
go.sum
View file

@ -14,8 +14,8 @@ github.com/ayn2op/arikawa/v3 v3.0.0-20260929021956-7d0802bf4d7c h1:Qkl3W5RXzUQUR
github.com/ayn2op/arikawa/v3 v3.0.0-20260929021956-7d0802bf4d7c/go.mod h1:SHqcr+EmZKeNtVKZybHJn4HNz+ufA1XbeKNSTigBCEE=
github.com/ayn2op/ningen/v3 v3.0.1-0.20260929010920-29794d5fa70e h1:QAei/IVEyZV7GcpkpcFUh37+QRqwrt57z7OT3ciHrhI=
github.com/ayn2op/ningen/v3 v3.0.1-0.20260929010920-29794d5fa70e/go.mod h1:RsvYiMzi4Si1F7vmml5NCL2DaKIZXkNUQC7QlGTMtCw=
github.com/ayn2op/tview v0.0.0-20260930215038-4bb4ac90d11c h1:ABMNEaSusSM3FiOjIrrR8zz9JUgA+oXQCs6bpUgqsmI=
github.com/ayn2op/tview v0.0.0-20260930215038-4bb4ac90d11c/go.mod h1:oRPTSZgaEJPhv3dmmNvo6grBq/BemrLG3wFQLMTZJkY=
github.com/ayn2op/tview v0.0.0-20260930235645-239215f3c690 h1:D9rzPnRksnsHtCszkHFwSalAO8fXnK4h2bbOCT+SyUo=
github.com/ayn2op/tview v0.0.0-20260930235645-239215f3c690/go.mod h1:oRPTSZgaEJPhv3dmmNvo6grBq/BemrLG3wFQLMTZJkY=
github.com/bdandy/go-errors v1.2.2 h1:WdFv/oukjTJCLa79UfkGmwX7ZxONAihKu4V0mLIs11Q=
github.com/bdandy/go-errors v1.2.2/go.mod h1:NkYHl4Fey9oRRdbB1CoC6e84tuqQHiqrOcZpqFEkBxM=
github.com/bdandy/go-socks4 v1.2.3 h1:Q6Y2heY1GRjCtHbmlKfnwrKVU/k81LS8mRGLRlmDlic=

View file

@ -178,7 +178,8 @@ type (
MembersTree PaneConfig `toml:"members_tree"`
Composer ComposerConfig `toml:"composer"`
Icons Icons `toml:"icons"`
UI UIConfig `toml:"ui"`
Icons Icons `toml:"icons"`
Keybinds Keybinds `toml:"keybinds"`
Theme Theme `toml:"theme"`

View file

@ -55,6 +55,20 @@ separator = " • "
width = 80
height = 25
[ui.tabs]
# Where tabs that fit are placed: "left", "center" or "right".
alignment = "center"
# Whether moving past the last tab selects the first, and past the first selects the last.
wrap = false
# Text between tabs.
separator = "│"
# Text on either side of each tab: [left, right]
padding = [" ", " "]
# Arrows shown while tabs are hidden past an end: [start, end]. An empty string turns that arrow off.
arrows = ["◀", "▶"]
# Whether clicking an arrow selects the tab next to the active one.
clickable_arrows = true
[timestamps]
enabled = true
# https://pkg.go.dev/time#Layout

16
internal/config/ui.go Normal file
View file

@ -0,0 +1,16 @@
package config
type (
UIConfig struct {
Tabs TabsConfig `toml:"tabs"`
}
TabsConfig struct {
Alignment AlignmentWrapper `toml:"alignment"`
Wrap bool `toml:"wrap"`
Separator string `toml:"separator"`
Padding [2]string `toml:"padding"`
Arrows [2]string `toml:"arrows"`
ClickableArrows bool `toml:"clickable_arrows"`
}
)

View file

@ -60,7 +60,7 @@ func (m Model) View() tview.Element {
case tabToken:
content = m.token.View()
}
t := tabs.New(m.password.Label(), m.qr.Label(), m.token.Label()).
t := m.tabs().
Active(int(m.active)).
Content(content).
Keybind(tabAction).
@ -68,6 +68,18 @@ func (m Model) View() tview.Element {
return ui.Box(t, &m.cfg.Theme, false)
}
// tabs returns the login methods as tabs set up by the tabs config.
func (m Model) tabs() tabs.Widget {
cfg := m.cfg.UI.Tabs
return tabs.New(m.password.Label(), m.qr.Label(), m.token.Label()).
Alignment(cfg.Alignment.Alignment).
Wrap(cfg.Wrap).
Separator(cfg.Separator).
Padding(cfg.Padding[0], cfg.Padding[1]).
Arrows(cfg.Arrows[0], cfg.Arrows[1]).
ClickableArrows(cfg.ClickableArrows)
}
func (m Model) Update(msg tview.Msg) (Model, tview.Cmd) {
var errCmd tview.Cmd
switch msg := msg.(type) {