| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- package layout
- import (
- "reflect"
- "github.com/charmbracelet/bubbles/v2/key"
- tea "github.com/charmbracelet/bubbletea/v2"
- "github.com/charmbracelet/lipgloss/v2"
- )
- var Current *LayoutInfo
- func init() {
- Current = &LayoutInfo{
- Viewport: Dimensions{Width: 80, Height: 25},
- Container: Dimensions{Width: 80, Height: 25},
- }
- }
- type LayoutSize string
- type Dimensions struct {
- Width int
- Height int
- }
- type LayoutInfo struct {
- Viewport Dimensions
- Container Dimensions
- }
- type Modal interface {
- tea.Model
- Render(background string) string
- Close() tea.Cmd
- }
- type Focusable interface {
- Focus() tea.Cmd
- Blur() tea.Cmd
- IsFocused() bool
- }
- type Sizeable interface {
- SetSize(width, height int) tea.Cmd
- GetSize() (int, int)
- }
- type Alignable interface {
- MaxWidth() int
- Alignment() lipgloss.Position
- SetPosition(x, y int)
- GetPosition() (x, y int)
- }
- 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
- }
|