summaryrefslogtreecommitdiffhomepage
path: root/packages/tui/internal/layout
diff options
context:
space:
mode:
authoradamdottv <[email protected]>2025-06-17 07:09:04 -0500
committeradamdottv <[email protected]>2025-06-17 07:09:04 -0500
commita5da5127faffacd7703fc0dde061ef1f490d3dce (patch)
treeab9c65d0eb45ab9fdc326187ca5881dc9b10936e /packages/tui/internal/layout
parentb5a4439704c70a17d661f1984bb030d5325d141a (diff)
downloadopencode-a5da5127faffacd7703fc0dde061ef1f490d3dce.tar.gz
opencode-a5da5127faffacd7703fc0dde061ef1f490d3dce.zip
chore: consolidate chat page into tui.go
Diffstat (limited to 'packages/tui/internal/layout')
-rw-r--r--packages/tui/internal/layout/container.go56
-rw-r--r--packages/tui/internal/layout/flex.go3
2 files changed, 31 insertions, 28 deletions
diff --git a/packages/tui/internal/layout/container.go b/packages/tui/internal/layout/container.go
index b1310f498..14434124a 100644
--- a/packages/tui/internal/layout/container.go
+++ b/packages/tui/internal/layout/container.go
@@ -6,20 +6,14 @@ import (
"github.com/sst/opencode/internal/theme"
)
-type ModelWithView interface {
+type Container interface {
tea.Model
tea.ViewModel
-}
-
-type Container interface {
- ModelWithView
Sizeable
- Focus()
- Blur()
+ Focusable
MaxWidth() int
Alignment() lipgloss.Position
GetPosition() (x, y int)
- GetContent() ModelWithView
}
type container struct {
@@ -28,7 +22,7 @@ type container struct {
x int
y int
- content ModelWithView
+ content tea.ViewModel
paddingTop int
paddingRight int
@@ -48,13 +42,19 @@ type container struct {
}
func (c *container) Init() tea.Cmd {
- return c.content.Init()
+ if model, ok := c.content.(tea.Model); ok {
+ return model.Init()
+ }
+ return nil
}
func (c *container) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
- u, cmd := c.content.Update(msg)
- c.content = u.(ModelWithView)
- return c, cmd
+ if model, ok := c.content.(tea.Model); ok {
+ u, cmd := model.Update(msg)
+ c.content = u.(tea.ViewModel)
+ return c, cmd
+ }
+ return c, nil
}
func (c *container) View() string {
@@ -156,21 +156,28 @@ func (c *container) Alignment() lipgloss.Position {
}
// Focus sets the container as focused
-func (c *container) Focus() {
+func (c *container) Focus() tea.Cmd {
c.focused = true
- // Pass focus to content if it supports it
- if focusable, ok := c.content.(interface{ Focus() }); ok {
- focusable.Focus()
+ if focusable, ok := c.content.(Focusable); ok {
+ return focusable.Focus()
}
+ return nil
}
// Blur removes focus from the container
-func (c *container) Blur() {
+func (c *container) Blur() tea.Cmd {
c.focused = false
- // Remove focus from content if it supports it
- if blurable, ok := c.content.(interface{ Blur() }); ok {
- blurable.Blur()
+ if blurable, ok := c.content.(Focusable); ok {
+ return blurable.Blur()
}
+ return nil
+}
+
+func (c *container) IsFocused() bool {
+ if blurable, ok := c.content.(Focusable); ok {
+ return blurable.IsFocused()
+ }
+ return c.focused
}
// GetPosition returns the x, y coordinates of the container
@@ -178,14 +185,9 @@ func (c *container) GetPosition() (x, y int) {
return c.x, c.y
}
-// GetContent returns the content of the container
-func (c *container) GetContent() ModelWithView {
- return c.content
-}
-
type ContainerOption func(*container)
-func NewContainer(content ModelWithView, options ...ContainerOption) Container {
+func NewContainer(content tea.ViewModel, options ...ContainerOption) Container {
c := &container{
content: content,
borderStyle: lipgloss.NormalBorder(),
diff --git a/packages/tui/internal/layout/flex.go b/packages/tui/internal/layout/flex.go
index 3a5c3aa71..0d337be2a 100644
--- a/packages/tui/internal/layout/flex.go
+++ b/packages/tui/internal/layout/flex.go
@@ -25,7 +25,8 @@ func FlexPaneSizeFixed(size int) FlexPaneSize {
}
type FlexLayout interface {
- ModelWithView
+ tea.Model
+ tea.ViewModel
Sizeable
SetPanes(panes []Container) tea.Cmd
SetPaneSizes(sizes []FlexPaneSize) tea.Cmd