From 99af6146d5def31c59993636d60eb75a483a283b Mon Sep 17 00:00:00 2001 From: Dax Raad Date: Sun, 18 May 2025 22:30:41 -0400 Subject: openapi --- pkg/tui/layout/layout.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 pkg/tui/layout/layout.go (limited to 'pkg/tui/layout/layout.go') diff --git a/pkg/tui/layout/layout.go b/pkg/tui/layout/layout.go new file mode 100644 index 000000000..495a3fbc5 --- /dev/null +++ b/pkg/tui/layout/layout.go @@ -0,0 +1,35 @@ +package layout + +import ( + "reflect" + + "github.com/charmbracelet/bubbles/key" + tea "github.com/charmbracelet/bubbletea" +) + +type Focusable interface { + Focus() tea.Cmd + Blur() tea.Cmd + IsFocused() bool +} + +type Sizeable interface { + SetSize(width, height int) tea.Cmd + GetSize() (int, int) +} + +type Bindings interface { + BindingKeys() []key.Binding +} + +func KeyMapToSlice(t any) (bindings []key.Binding) { + typ := reflect.TypeOf(t) + if typ.Kind() != reflect.Struct { + return nil + } + for i := range typ.NumField() { + v := reflect.ValueOf(t).Field(i) + bindings = append(bindings, v.Interface().(key.Binding)) + } + return +} -- cgit v1.2.3