Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ require (
charm.land/log/v2 v2.0.0 // indirect
charm.land/wish/v2 v2.0.0 // indirect
dappco.re/go/cgo v0.11.2 // indirect
dappco.re/go/html v0.15.0 // direct: cli/tui renders .ctml (tabs.go)
dappco.re/go/html v0.16.0 // direct: cli/tui renders .ctml (tabs.go)
dappco.re/go/i18n v0.12.1 // indirect
dappco.re/go/log v0.13.1 // indirect
dappco.re/go/ratelimit v0.12.1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions cli/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ dappco.re/go/html v0.14.0 h1:vUDiFe4b5IXF2xFCFPSPwwlXwWW5Cf+OhDQq0gnt/iY=
dappco.re/go/html v0.14.0/go.mod h1:vhB4+z5cz6WYRqG7c/sDAOxm7Esc8GHEVnOpoN48+r4=
dappco.re/go/html v0.15.0 h1:XMFA7fKY07F3gskoF/9+NYo1WlLaNmoGEFmOofWvnRw=
dappco.re/go/html v0.15.0/go.mod h1:vhB4+z5cz6WYRqG7c/sDAOxm7Esc8GHEVnOpoN48+r4=
dappco.re/go/html v0.16.0 h1:xaQxd7TYh6pCnagQuCLnAsQsX0IskCigDHqor0ysQD4=
dappco.re/go/html v0.16.0/go.mod h1:1UKrgjMWNEJ9IyVy/emc2T60q0Y4AzTLBy07Ly6/QlA=
dappco.re/go/i18n v0.12.1 h1:Pm1DF9I0O8bckTr815OrnR+G+7EvbQhP2Vk4ItC0mB4=
dappco.re/go/i18n v0.12.1/go.mod h1:AYx1QkPfW+qvzLCfJnuOlc4J+grwlgFzoHnoke4TAYg=
dappco.re/go/inference v0.14.0 h1:3Lddj4W8T7/Mg8iTmvS+hCUkUqYYhRPYGe6i/ILF1+o=
Expand Down
8 changes: 4 additions & 4 deletions cli/tui/agentoverlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ package tui
import (
_ "embed"

"github.com/charmbracelet/bubbles/textarea"
"github.com/charmbracelet/bubbles/textinput"
"github.com/charmbracelet/bubbles/viewport"
tea "github.com/charmbracelet/bubbletea"
tea "dappco.re/go/html/tui"
"dappco.re/go/html/tui/textarea"
"dappco.re/go/html/tui/textinput"
"dappco.re/go/html/tui/viewport"

core "dappco.re/go"
"dappco.re/go/html/ctml"
Expand Down
32 changes: 16 additions & 16 deletions cli/tui/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
"sync"
"time"

"github.com/charmbracelet/bubbles/key"
"github.com/charmbracelet/bubbles/list"
"github.com/charmbracelet/bubbles/spinner"
"github.com/charmbracelet/bubbles/textarea"
"github.com/charmbracelet/bubbles/viewport"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
tea "dappco.re/go/html/tui"
"dappco.re/go/html/tui/key"
"dappco.re/go/html/tui/list"
"dappco.re/go/html/tui/spinner"
"dappco.re/go/html/tui/style"
"dappco.re/go/html/tui/textarea"
"dappco.re/go/html/tui/viewport"

core "dappco.re/go"
"dappco.re/go/html"
Expand Down Expand Up @@ -3076,7 +3076,7 @@
if err != nil {
return ""
}
return lipgloss.NewStyle().Width(a.view.Width).Render(html.RenderTerm(tree, html.NewContext()))
return style.New().Width(a.view.Width).Render(html.RenderTerm(tree, html.NewContext()))
}

// transcriptBindings supplies transcript.ctml's two row sequences. notice is
Expand Down Expand Up @@ -3267,7 +3267,7 @@
return a.svc.view(a.modelName, a.width, a.styles)
case panelWork:
if a.work == nil {
return lipgloss.JoinVertical(lipgloss.Left,
return style.Column(style.Left,
a.styles.title.Render("Work"),
"",
a.styles.status.Render("○ No work yet"),
Expand All @@ -3281,7 +3281,7 @@
return a.work.View(metrics.mainWidth, metrics.mainHeight, a.styles)
case panelData:
if a.data == nil {
return lipgloss.JoinVertical(lipgloss.Left,
return style.Column(style.Left,
a.styles.title.Render("Data"),
"",
a.styles.status.Render("○ No dataset store connected"),
Expand All @@ -3300,7 +3300,7 @@
if a.model == nil {
return "\n " + a.spin.View() + a.styles.status.Render(" loading "+displayName(a.loading)+" …")
}
return lipgloss.JoinVertical(lipgloss.Left,
return style.Column(style.Left,
a.view.View(),
a.styles.inputBorder.Render(a.input.View()),
)
Expand All @@ -3313,7 +3313,7 @@
if a.boot.err != nil {
reason = a.boot.err.Error()
}
return lipgloss.JoinVertical(lipgloss.Left,
return style.Column(style.Left,
a.styles.err.Render("Workspace could not open"),
"",
a.styles.answer.Render(reason),
Expand All @@ -3322,7 +3322,7 @@
a.styles.status.Render("Q Quit without changing storage"),
)
}
return lipgloss.JoinVertical(lipgloss.Left,
return style.Column(style.Left,
a.spin.View()+a.styles.title.Render(" Opening ~/.lem workspace"),
"",
a.styles.status.Render("Preparing durable sessions, preferences, work, and local knowledge…"),
Expand Down Expand Up @@ -3409,7 +3409,7 @@
return renderOverlay(body, width, height, a.styles)
}

func (a app) sessionStrip() string {

Check failure on line 3412 in cli/tui/app.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this method to reduce its Cognitive Complexity from 21 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=dAppCore_go-inference&issues=AZ-OF7AJZzjgfdxhpOQv&open=AZ-OF7AJZzjgfdxhpOQv&pullRequest=16
if a.sessions == nil || len(a.sessions.Recent()) == 0 {
title := newSessionTitle
for _, item := range a.turns {
Expand Down Expand Up @@ -3449,7 +3449,7 @@
if hidden > 0 {
candidate = append(candidate, core.Sprintf("+%d", hidden))
}
if lipgloss.Width(core.Join(" · ", candidate...)) <= maxWidth {
if style.Measure(core.Join(" · ", candidate...)) <= maxWidth {
break
}
parts = parts[:len(parts)-1]
Expand Down Expand Up @@ -3486,11 +3486,11 @@

func compactStripTitle(value string, maxCells int) string {
value = core.Trim(value)
if maxCells < 2 || lipgloss.Width(value) <= maxCells {
if maxCells < 2 || style.Measure(value) <= maxCells {
return value
}
runes := []rune(value)
for len(runes) > 1 && lipgloss.Width(string(runes)+"…") > maxCells {
for len(runes) > 1 && style.Measure(string(runes)+"…") > maxCells {
runes = runes[:len(runes)-1]
}
return string(runes) + "…"
Expand Down
6 changes: 3 additions & 3 deletions cli/tui/dataoverlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ package tui
import (
_ "embed"

"github.com/charmbracelet/bubbles/textarea"
"github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea"
tea "dappco.re/go/html/tui"
"dappco.re/go/html/tui/textarea"
"dappco.re/go/html/tui/textinput"

core "dappco.re/go"
"dappco.re/go/html/ctml"
Expand Down
23 changes: 11 additions & 12 deletions cli/tui/datapanel.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import (
"sort"
"time"

"github.com/charmbracelet/bubbles/list"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/x/ansi"
tea "dappco.re/go/html/tui"
"dappco.re/go/html/tui/list"
"dappco.re/go/html/tui/style"

core "dappco.re/go"
"dappco.re/go/html"
Expand Down Expand Up @@ -504,13 +503,13 @@ func (panel *dataPanel) View(width, height int, styles uiStyles) string {
var view string
if width >= 100 {
separator := fitPane("│", 1, height, styles.separator)
view = lipgloss.JoinHorizontal(lipgloss.Top,
view = style.Row(style.Top,
fitPane(listView, listWidth, height, styles.panel),
separator,
fitPane(detailView, detailWidth, height, styles.panel),
)
} else {
view = lipgloss.JoinVertical(lipgloss.Left,
view = style.Column(style.Left,
fitPane(listView, listWidth, listHeight, styles.panel),
"",
fitPane(detailView, detailWidth, detailHeight, styles.panel),
Expand Down Expand Up @@ -572,13 +571,13 @@ func dataListBindings(panel *dataPanel, width int) ctml.Bindings {
// The F band renders its blocks at width-2 (the frame's own inner
// margin), so the row budget subtracts that before the cursor, the
// two fixed segments, and their two 2-cell gaps.
budget := max(1, width-2-lipgloss.Width(cursor)-lipgloss.Width(status)-lipgloss.Width(meta)-4)
budget := max(1, width-2-style.Measure(cursor)-style.Measure(status)-style.Measure(meta)-4)
sequences["rows"] = append(sequences["rows"], map[string]any{
"state": state,
"cursor": cursor,
"status": status,
"meta": meta,
"slug": ansi.Truncate(item.row.Dataset.Slug, budget, "…"),
"slug": style.Truncate(item.row.Dataset.Slug, budget, "…"),
})
}
if len(visible) == 0 {
Expand All @@ -597,9 +596,9 @@ func dataListBindings(panel *dataPanel, width int) ctml.Bindings {
func dataListTheme(styles uiStyles) *html.TermTheme {
theme := html.DefaultTermTheme()
theme.Text = styles.answer
theme.Header = lipgloss.NewStyle()
theme.Footer = lipgloss.NewStyle()
theme.Classes = map[string]lipgloss.Style{
theme.Header = style.New()
theme.Footer = style.New()
theme.Classes = map[string]style.Style{
"list-title": styles.title,
"list-meta": styles.status,
"list-filter": styles.thought,
Expand Down Expand Up @@ -692,7 +691,7 @@ func (panel *dataPanel) dataDetailBindings(width int) ctml.Bindings {
func dataDetailTheme(styles uiStyles) *html.TermTheme {
theme := html.DefaultTermTheme()
theme.Text = styles.answer
theme.Classes = map[string]lipgloss.Style{
theme.Classes = map[string]style.Style{
"detail-empty": styles.status,
"detail-title": styles.title,
"detail-status": styles.status,
Expand Down
5 changes: 2 additions & 3 deletions cli/tui/inspector.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ package tui
import (
_ "embed"

"github.com/charmbracelet/lipgloss"

core "dappco.re/go"
"dappco.re/go/html"
"dappco.re/go/html/ctml"
"dappco.re/go/html/tui/style"
)

type inspectorControl uint8
Expand Down Expand Up @@ -164,7 +163,7 @@ func (inspector inspectorState) View(target app, width, height int) string {
func inspectorTheme(styles uiStyles) *html.TermTheme {
theme := html.DefaultTermTheme()
theme.Text = styles.inspector
theme.Classes = map[string]lipgloss.Style{
theme.Classes = map[string]style.Style{
"inspector-title": styles.title,
"label": styles.accent,
"control-active": styles.accent,
Expand Down
2 changes: 1 addition & 1 deletion cli/tui/keymap.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

package tui

import "github.com/charmbracelet/bubbles/key"
import "dappco.re/go/html/tui/key"

type keyMap struct {
NewSession key.Binding
Expand Down
27 changes: 13 additions & 14 deletions cli/tui/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ package tui
import (
_ "embed"

"github.com/charmbracelet/lipgloss"

core "dappco.re/go"
"dappco.re/go/html"
"dappco.re/go/html/ctml"
"dappco.re/go/html/tui/style"
)

type layoutKind uint8
Expand Down Expand Up @@ -145,8 +144,8 @@ var shellWideCTML []byte
// it byte-exact.
func shellFrameTheme(styles uiStyles) *html.TermTheme {
theme := html.DefaultTermTheme()
theme.Header = lipgloss.NewStyle()
theme.Footer = lipgloss.NewStyle()
theme.Header = style.New()
theme.Footer = style.New()
return theme
}

Expand All @@ -159,7 +158,7 @@ func shellFrameTheme(styles uiStyles) *html.TermTheme {
// and gets word-wrapped onto a spurious extra row (S:15.5).
func shellRegionTheme(styles uiStyles) *html.TermTheme {
theme := shellFrameTheme(styles)
theme.Content = lipgloss.NewStyle()
theme.Content = style.New()
return theme
}

Expand All @@ -176,7 +175,7 @@ func shellRegionTheme(styles uiStyles) *html.TermTheme {
// default border colour.
func shellWideTheme(styles uiStyles) *html.TermTheme {
theme := shellRegionTheme(styles)
theme.Aside = lipgloss.NewStyle()
theme.Aside = style.New()
theme.GutterRule = "│"
theme.Rule = styles.separator
return theme
Expand Down Expand Up @@ -245,7 +244,7 @@ func renderWideLayout(src []byte, width int, theme *html.TermTheme, bindings ...
//
// The ONE shape that still cannot join header+region+footer into a single
// call -- Overlay with the inspector open -- stays a host-side
// lipgloss.JoinVertical of three independently rendered pieces: shell.ctml's
// style.Column of three independently rendered pieces: shell.ctml's
// H/F-only layout (split by renderBandFrame, unchanged), and
// renderInspectorStack's own region render sat between them. What changed
// this slice (docs/ctml.md S:15.7, go-html v0.15.0) is that the REGION
Expand Down Expand Up @@ -288,7 +287,7 @@ func renderFrame(spec frameSpec, styles uiStyles) string {
case metrics.kind == layoutOverlay && spec.InspectorOpen:
region := renderInspectorStack(spec, metrics, styles)
head, foot := renderBandFrame(shellCTML, metrics.innerWidth, shellFrameTheme(styles), shellBindings(header, footer))
inside = lipgloss.JoinVertical(lipgloss.Left, head, region, foot)
inside = style.Column(style.Left, head, region, foot)
case metrics.kind == layoutWide:
main := fitPane(spec.Main, metrics.mainWidth, metrics.mainHeight, styles.panel)
inspector := fitPane(spec.Inspector, metrics.inspectorWidth, metrics.inspectorHeight, styles.inspector)
Expand Down Expand Up @@ -332,10 +331,10 @@ var shellInspectorPairCTML []byte
// history), not go-html's own similar-but-different default border colour.
func inspectorPairTheme(styles uiStyles) *html.TermTheme {
theme := html.DefaultTermTheme()
theme.Header = lipgloss.NewStyle().
Border(lipgloss.NormalBorder(), false, false, true, false).
theme.Header = style.New().
Border(style.Normal(), false, false, true, false).
BorderForeground(styles.theme.border)
theme.Content = lipgloss.NewStyle()
theme.Content = style.New()
return theme
}

Expand All @@ -362,7 +361,7 @@ func inspectorPairBindings(inspector, main string) ctml.Bindings {
// (zero-chrome) and this pair's own H (bordered) different styles from the
// one flat TermTheme a render call threads through every nested Layout.
// renderFrame still joins this function's output between the (unchanged,
// separately rendered) header/footer bands with lipgloss.JoinVertical --
// separately rendered) header/footer bands with style.Column --
// that outer join, not this region's own composition, is what remains
// host-side.
func renderInspectorStack(spec frameSpec, metrics frameMetrics, styles uiStyles) string {
Expand All @@ -371,14 +370,14 @@ func renderInspectorStack(spec frameSpec, metrics frameMetrics, styles uiStyles)
return renderBandLayout(shellInspectorPairCTML, metrics.innerWidth, inspectorPairTheme(styles), inspectorPairBindings(inspector, main))
}

func fitLine(content string, width int, style lipgloss.Style) string {
func fitLine(content string, width int, style style.Style) string {
if width <= 0 {
return ""
}
return style.Width(width).MaxWidth(width).MaxHeight(1).Render(content)
}

func fitPane(content string, width, height int, style lipgloss.Style) string {
func fitPane(content string, width, height int, style style.Style) string {
if width <= 0 || height <= 0 {
return ""
}
Expand Down
20 changes: 10 additions & 10 deletions cli/tui/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"sync"
"time"

tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/glamour"
tea "dappco.re/go/html/tui"
"dappco.re/go/html/tui/markdown"
)

type markdownCacheKey struct {
Expand All @@ -30,15 +30,15 @@ type markdownRenderer struct {
mu sync.Mutex
theme string
cache map[markdownCacheKey]string
renderers map[int]*glamour.TermRenderer
renderers map[int]*markdown.Renderer
stats markdownStats
}

func newMarkdownRenderer(theme string) *markdownRenderer {
return &markdownRenderer{
theme: theme,
cache: make(map[markdownCacheKey]string),
renderers: make(map[int]*glamour.TermRenderer),
renderers: make(map[int]*markdown.Renderer),
}
}

Expand All @@ -63,12 +63,12 @@ func (renderer *markdownRenderer) Render(turnID, content string, width int) stri
renderer.stats.Misses++
term := renderer.renderers[width]
if term == nil {
built, err := glamour.NewTermRenderer(
glamour.WithStandardStyle("dark"),
glamour.WithWordWrap(width),
glamour.WithTableWrap(true),
glamour.WithPreservedNewLines(),
glamour.WithEmoji(),
built, err := markdown.New(
markdown.WithStandardStyle("dark"),
markdown.WithWordWrap(width),
markdown.WithTableWrap(true),
markdown.WithPreservedNewLines(),
markdown.WithEmoji(),
)
if err != nil {
renderer.cache[key] = content
Expand Down
Loading
Loading