refactor(ui): use tview/inert for dialogs and pickers

This commit is contained in:
ayn2op 2026-09-27 20:41:19 -04:00
parent 24342490e5
commit 07733bc436
5 changed files with 9 additions and 26 deletions

2
go.mod
View file

@ -15,7 +15,7 @@ require (
github.com/andybalholm/brotli v1.2.5
github.com/ayn2op/arikawa/v3 v3.0.0-20260904042054-7df757872273
github.com/ayn2op/ningen/v3 v3.0.1-0.20260904045623-5978c9be899f
github.com/ayn2op/tview v0.0.0-20260928000403-b1f6164a02e5
github.com/ayn2op/tview v0.0.0-20260928003911-758a51d24cad
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-20260904042054-7df757872273 h1:cJ1donaon2Cjh
github.com/ayn2op/arikawa/v3 v3.0.0-20260904042054-7df757872273/go.mod h1:bzMgZqBnJr1pu7EHq2d9906sAtHA+iklIxxvnS5kfDo=
github.com/ayn2op/ningen/v3 v3.0.1-0.20260904045623-5978c9be899f h1:RrbCgoBOmYsLJAaf4lES+eoJYOG7zQMykACIFZgEvdU=
github.com/ayn2op/ningen/v3 v3.0.1-0.20260904045623-5978c9be899f/go.mod h1:j8CBNjCkOpsgQm6X2xYJ0kXu5Y/PiQ+6QxxmExCq1Fs=
github.com/ayn2op/tview v0.0.0-20260928000403-b1f6164a02e5 h1:90J4ipdQLF+nvfPPMoHCWAPlvNgXqPmRCejn7PatvHE=
github.com/ayn2op/tview v0.0.0-20260928000403-b1f6164a02e5/go.mod h1:oRPTSZgaEJPhv3dmmNvo6grBq/BemrLG3wFQLMTZJkY=
github.com/ayn2op/tview v0.0.0-20260928003911-758a51d24cad h1:NzrmJFrWVtRVY8u+Q9HUv0ow9dvlu4s+YdrqEnh4yGM=
github.com/ayn2op/tview v0.0.0-20260928003911-758a51d24cad/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

@ -28,8 +28,8 @@ import (
"github.com/ayn2op/tview/backdrop"
"github.com/ayn2op/tview/center"
"github.com/ayn2op/tview/column"
"github.com/ayn2op/tview/inert"
"github.com/ayn2op/tview/keybind"
"github.com/ayn2op/tview/opaque"
"github.com/ayn2op/tview/row"
"github.com/ayn2op/tview/stack"
)
@ -457,9 +457,9 @@ func (m Model) View() tview.Element {
return main
}
return stack.New(
main,
// The backdrop keeps clicks from reaching the panes behind the picker.
opaque.New(backdrop.New().Style(m.cfg.Theme.Dialog.BackgroundStyle.Style)),
// The panes behind the picker take no input.
inert.New(main),
backdrop.New().Style(m.cfg.Theme.Dialog.BackgroundStyle.Style),
center.New(column.New(picker).Width(tview.Fixed(m.cfg.Picker.Width)).Height(tview.Fixed(m.cfg.Picker.Height))),
)
}

View file

@ -1,18 +0,0 @@
package root
import "github.com/ayn2op/tview"
// inert draws child but gives it no input, like HTML's inert attribute, for what is behind the dialog.
type inert struct {
child tview.Element
}
var _ tview.Element = inert{}
func (i inert) Draw(screen tview.Screen, area tview.Rectangle) {
i.child.Draw(screen, area)
}
func (inert) Handle(msg tview.Msg, area tview.Rectangle) tview.Msg {
return msg
}

View file

@ -17,6 +17,7 @@ import (
"github.com/ayn2op/tview/column"
"github.com/ayn2op/tview/dialog"
"github.com/ayn2op/tview/help"
"github.com/ayn2op/tview/inert"
"github.com/ayn2op/tview/keybind"
"github.com/ayn2op/tview/stack"
"github.com/gdamore/tcell/v3"
@ -157,7 +158,7 @@ func (m Model) View() tview.Element {
if m.modal == nil {
return content
}
return stack.New(inert{content}, backdrop.New().Style(m.cfg.Theme.Dialog.BackgroundStyle.Style), m.dialogView())
return stack.New(inert.New(content), backdrop.New().Style(m.cfg.Theme.Dialog.BackgroundStyle.Style), m.dialogView())
}
func (m *Model) showModal(request ui.ModalMsg) tview.Cmd {