diff options
| author | adamdottv <[email protected]> | 2025-06-12 16:00:20 -0500 |
|---|---|---|
| committer | adamdottv <[email protected]> | 2025-06-12 16:00:26 -0500 |
| commit | 653965ef5908a240f6038609e17bc8fa27640203 (patch) | |
| tree | 439910084fdcea0c45856ad0132f916fd9038a4b /packages/tui/internal/layout | |
| parent | ca0ea3f94dc1929071efc93bfcf708c8cf054be8 (diff) | |
| download | opencode-653965ef5908a240f6038609e17bc8fa27640203.tar.gz opencode-653965ef5908a240f6038609e17bc8fa27640203.zip | |
wip: refactoring tui
Diffstat (limited to 'packages/tui/internal/layout')
| -rw-r--r-- | packages/tui/internal/layout/layout.go | 6 | ||||
| -rw-r--r-- | packages/tui/internal/layout/overlay.go | 41 |
2 files changed, 8 insertions, 39 deletions
diff --git a/packages/tui/internal/layout/layout.go b/packages/tui/internal/layout/layout.go index 9a7fefcad..b49913bde 100644 --- a/packages/tui/internal/layout/layout.go +++ b/packages/tui/internal/layout/layout.go @@ -36,6 +36,12 @@ type LayoutInfo struct { Container Dimensions } +type Modal interface { + tea.Model + Render(background string) string + Close() tea.Cmd +} + type Focusable interface { Focus() tea.Cmd Blur() tea.Cmd diff --git a/packages/tui/internal/layout/overlay.go b/packages/tui/internal/layout/overlay.go index a6dd6f40a..f3d302a99 100644 --- a/packages/tui/internal/layout/overlay.go +++ b/packages/tui/internal/layout/overlay.go @@ -8,15 +8,9 @@ import ( "github.com/muesli/ansi" "github.com/muesli/reflow/truncate" "github.com/muesli/termenv" - "github.com/sst/opencode/internal/styles" - "github.com/sst/opencode/internal/theme" "github.com/sst/opencode/internal/util" ) -// Most of this code is borrowed from -// https://github.com/charmbracelet/lipgloss/v2/pull/102 -// as well as the lipgloss library, with some modification for what I needed. - // Split a string into lines, additionally returning the size of the widest line. func getLines(s string) (lines []string, widest int) { lines = strings.Split(s, "\n") @@ -33,42 +27,18 @@ func getLines(s string) (lines []string, widest int) { func PlaceOverlay( x, y int, fg, bg string, - shadow bool, opts ...WhitespaceOption, + opts ...WhitespaceOption, ) string { fgLines, fgWidth := getLines(fg) bgLines, bgWidth := getLines(bg) bgHeight := len(bgLines) fgHeight := len(fgLines) - shadow = false - - if shadow { - t := theme.CurrentTheme() - baseStyle := styles.BaseStyle() - - var shadowbg string = "" - shadowchar := lipgloss.NewStyle(). - Background(t.BackgroundElement()). - Foreground(t.Background()). - Render("░") - bgchar := baseStyle.Render(" ") - for i := 0; i <= fgHeight; i++ { - if i == 0 { - shadowbg += bgchar + strings.Repeat(bgchar, fgWidth) + "\n" - } else { - shadowbg += bgchar + strings.Repeat(shadowchar, fgWidth) + "\n" - } - } - - fg = PlaceOverlay(0, 0, fg, shadowbg, false, opts...) - fgLines, fgWidth = getLines(fg) - fgHeight = len(fgLines) - } - if fgWidth >= bgWidth && fgHeight >= bgHeight { // FIXME: return fg or bg? return fg } + // TODO: allow placement outside of the bg box? x = util.Clamp(x, 0, bgWidth-fgWidth) y = util.Clamp(y, 0, bgHeight-fgHeight) @@ -122,13 +92,6 @@ func cutLeft(s string, cutWidth int) string { return chAnsi.Cut(s, cutWidth, lipgloss.Width(s)) } -func max(a, b int) int { - if a > b { - return a - } - return b -} - type whitespace struct { style termenv.Style chars string |
