Skip to content
Draft
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
4 changes: 4 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ charmbracelet/bubbletea - https://github.com/charmbracelet/bubbletea
Copyright (c) 2020-2025 Charmbracelet, Inc
License - https://github.com/charmbracelet/bubbletea/blob/main/LICENSE

charmbracelet/colorprofile - https://github.com/charmbracelet/colorprofile
Copyright (c) 2020-2024 Charmbracelet, Inc
License - https://github.com/charmbracelet/colorprofile/blob/main/LICENSE

charmbracelet/huh - https://github.com/charmbracelet/huh
Copyright (c) 2023 Charmbracelet, Inc.
License - https://github.com/charmbracelet/huh/blob/main/LICENSE
Expand Down
3 changes: 1 addition & 2 deletions cmd/air/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

"github.com/databricks/cli/libs/cmdio"
"github.com/databricks/databricks-sdk-go/service/jobs"
"github.com/muesli/termenv"
"go.yaml.in/yaml/v3"
)

Expand All @@ -36,7 +35,7 @@ func hyperlink(ctx context.Context, out io.Writer, label, url string) string {
if url == "" || !cmdio.SupportsColor(ctx, out) {
return label
}
return termenv.Hyperlink(url, label)
return cmdio.Hyperlink(url, label)
}

// reformatYAMLForDisplay re-renders a training-config YAML so multi-line strings
Expand Down
6 changes: 3 additions & 3 deletions cmd/air/list_tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func renderListText(cmd *cobra.Command, f *runFetcher, limit int, activeOnly boo
_, err = io.WriteString(out, emptyListMessage(activeOnly))
return err
}
_, err = io.WriteString(out, staticListTable(r, rows, color))
_, err = io.WriteString(r.Writer(out), staticListTable(r, rows, color))
return err
}

Expand All @@ -75,7 +75,7 @@ func emptyListMessage(activeOnly bool) string {

// staticListTable renders the whole table once, with no selection — used when
// piped or non-interactive.
func staticListTable(r *lipgloss.Renderer, rows []listRow, links bool) string {
func staticListTable(r *cmdio.Renderer, rows []listRow, links bool) string {
if len(rows) == 0 {
return "No runs found.\n"
}
Expand Down Expand Up @@ -131,7 +131,7 @@ type listModel struct {
// detailHorizontalStep is how many columns ←/→ pan the detail pane.
const detailHorizontalStep = 8

func newListModel(r *lipgloss.Renderer, f *runFetcher, rows []listRow, links bool) listModel {
func newListModel(r *cmdio.Renderer, f *runFetcher, rows []listRow, links bool) listModel {
vp := viewport.New(0, 0)
vp.SetHorizontalStep(detailHorizontalStep)
return listModel{
Expand Down
37 changes: 19 additions & 18 deletions cmd/air/list_tui_render.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,23 @@ import (

"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/x/ansi"
"github.com/muesli/termenv"

"github.com/databricks/cli/libs/cmdio"
)

// DuBois dark-first palette. Neutrals (n7..n12) carry structure; the state
// colors are reserved for the Status column.
const (
colN7 = lipgloss.Color("#69696B") // gutter / dim
colN9 = lipgloss.Color("#ABABAE") // secondary values
colN11 = lipgloss.Color("#E0E0E3") // body
colN12 = lipgloss.Color("#F1F1F4") // selected text
colOverlay = lipgloss.Color("#1F1F23") // selected-row fill
colRunID = lipgloss.Color("#B7A8E8") // run id
colGreen = lipgloss.Color("#4CD964") // success
colAmber = lipgloss.Color("#E8B84A") // running / pending
colRed = lipgloss.Color("#EB6B6B") // failed
colBlue = lipgloss.Color("#6CA8F0") // MLflow link
var (
colN7 cmdio.Color = lipgloss.Color("#69696B") // gutter / dim
colN9 cmdio.Color = lipgloss.Color("#ABABAE") // secondary values
colN11 cmdio.Color = lipgloss.Color("#E0E0E3") // body
colN12 cmdio.Color = lipgloss.Color("#F1F1F4") // selected text
colOverlay cmdio.Color = lipgloss.Color("#1F1F23") // selected-row fill
colRunID cmdio.Color = lipgloss.Color("#B7A8E8") // run id
colGreen cmdio.Color = lipgloss.Color("#4CD964") // success
colAmber cmdio.Color = lipgloss.Color("#E8B84A") // running / pending
colRed cmdio.Color = lipgloss.Color("#EB6B6B") // failed
colBlue cmdio.Color = lipgloss.Color("#6CA8F0") // MLflow link
)

// mlflowColWidth is the MLflow column's width in a wide terminal, and the width
Expand All @@ -30,10 +31,10 @@ const mlflowColWidth = 22
// listStyles renders the runs table. The renderer carries the color profile, so
// styles render plain under --no-color / non-tty.
type listStyles struct {
r *lipgloss.Renderer
r *cmdio.Renderer
}

func newListStyles(r *lipgloss.Renderer) listStyles {
func newListStyles(r *cmdio.Renderer) listStyles {
return listStyles{r: r}
}

Expand Down Expand Up @@ -257,7 +258,7 @@ func (s listStyles) renderRow(cols listCols, r listRow, selected, links bool) st
if selected {
base = base.Background(colOverlay)
}
fg := func(c lipgloss.Color) lipgloss.Color {
fg := func(c cmdio.Color) cmdio.Color {
if selected {
return colN12
}
Expand Down Expand Up @@ -324,15 +325,15 @@ func listRowStatus(r listRow) string {
// characters (it may come from the server, or from a cache written before this
// stripping existed), truncated to width, then padded with (background-only)
// spaces so columns align even when the text is styled or hyperlinked.
func (s listStyles) cell(base lipgloss.Style, text string, width int, fg lipgloss.Color, right, underline bool, link string) string {
func (s listStyles) cell(base lipgloss.Style, text string, width int, fg cmdio.Color, right, underline bool, link string) string {
text = truncate(stripControl(text), width)
style := base.Foreground(fg)
if underline {
style = style.Underline(true)
}
rendered := style.Render(text)
if link != "" {
rendered = termenv.Hyperlink(link, rendered)
rendered = cmdio.Hyperlink(link, rendered)
}
gap := max(width-lipgloss.Width(text), 0)
padStr := base.Render(strings.Repeat(" ", gap))
Expand Down Expand Up @@ -370,7 +371,7 @@ func mlflowLabel(r listRow) string {
}

// statusColor maps an air run status word to its data color.
func statusColor(status string) lipgloss.Color {
func statusColor(status string) cmdio.Color {
switch status {
case "SUCCESS":
return colGreen
Expand Down
28 changes: 21 additions & 7 deletions cmd/air/list_tui_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,12 @@ func TestListModelEnterOpensMLflowLogs(t *testing.T) {

func TestListModelView(t *testing.T) {
next, _ := testListModel(t).Update(tea.WindowSizeMsg{Width: 200, Height: 24})
out := next.(listModel).View()
raw := next.(listModel).View()

assert.NotContains(t, out, "\x1b", "Ascii profile + no links should produce no escapes")
// On lipgloss v2 styles always render full color and the program
// downsamples at write time, so check text on the stripped view.
assert.NotContains(t, raw, "\x1b]8;;", "no links should produce no hyperlinks")
out := ansi.Strip(raw)
for _, want := range []string{
"Run ID", "Experiment", "Status", "Started", "Duration", "Progress", "MLflow", "User", "Accelerators",
"qwen-train", "● SUCCESS", "● RUNNING", "● FAILED",
Expand All @@ -193,8 +196,15 @@ func TestListModelView(t *testing.T) {

func TestStaticListTable(t *testing.T) {
r, _ := cmdio.NewRenderer(cmdio.MockDiscard(t.Context()), io.Discard)
out := staticListTable(r, testListRows(), false)

raw := staticListTable(r, testListRows(), false)
assert.NotContains(t, raw, "\x1b]8;;", "no links should produce no hyperlinks")

// Write the table as renderListText does. The table carries styling (full
// color on lipgloss v2); r.Writer strips it for this color-less target.
var b strings.Builder
_, err := io.WriteString(r.Writer(&b), raw)
require.NoError(t, err)
out := b.String()
assert.NotContains(t, out, "\x1b")
assert.NotContains(t, out, "▸", "static table has no selection")
for _, want := range []string{"Run ID", "1", "qwen-train", "1m 14s", "qwen-run-001", "8x H100", "Accelerators"} {
Expand Down Expand Up @@ -253,12 +263,16 @@ func TestRenderRowStripsControlCharacters(t *testing.T) {
}
cols := computeListCols([]listRow{row})

out := styles.renderRow(cols, row, false, false)
raw := styles.renderRow(cols, row, false, false)
// On lipgloss v2 styles always render full color (stripped at write
// time), so check the injected sequences on the raw output only.
for _, injected := range []string{"\x1b]0;", "\x1b[2J", "\x1b[31m", "\r"} {
assert.NotContains(t, raw, injected)
}
out := r.Render(raw)
assert.Contains(t, out, "experiment")
assert.Contains(t, out, "user@example.com")
assert.Contains(t, out, "my-run")
assert.NotContains(t, out, "\x1b")
assert.NotContains(t, out, "\r")
// Stripping happens before width is measured, so the columns stay aligned.
assert.Equal(t, cols.experiment, lipgloss.Width(stripControl(row.Experiment)))
}
Expand Down
1 change: 1 addition & 0 deletions cmd/air/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ func fetchLogs(ctx context.Context, w *databricks.WorkspaceClient, out io.Writer
// printJobRunLink leaves the run link below the streamed output, including on failure.
func printJobRunLink(ctx context.Context, out io.Writer, runURL string) {
renderer, colorOn := cmdio.NewRenderer(ctx, out)
out = renderer.Writer(out)
p := newPalette(renderer)
fmt.Fprintln(out)
fmt.Fprintln(out, "View job run at: "+link(colorOn, p.blue, runURL, runURL))
Expand Down
6 changes: 3 additions & 3 deletions cmd/air/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/databricks/databricks-sdk-go/config"
"github.com/databricks/databricks-sdk-go/httpclient"
"github.com/databricks/databricks-sdk-go/service/jobs"
"github.com/muesli/termenv"
"go.yaml.in/yaml/v3"
)

Expand Down Expand Up @@ -55,7 +54,7 @@ type palette struct {
red lipgloss.Style // failed status
}

func newPalette(r *lipgloss.Renderer) palette {
func newPalette(r *cmdio.Renderer) palette {
fg := func(hex string) lipgloss.Style { return r.NewStyle().Foreground(lipgloss.Color(hex)) }
return palette{
n7: fg("#6E6E70"),
Expand Down Expand Up @@ -98,6 +97,7 @@ func renderRunText(ctx context.Context, out io.Writer, w *databricks.WorkspaceCl
// emits no SGR codes; combined with the link fallback below this gives clean,
// un-escaped output under --no-color / NO_COLOR / piped stdout.
renderer, colorOn := cmdio.NewRenderer(ctx, out)
out = renderer.Writer(out)
p := newPalette(renderer)

// The list detail pane (list_detail.go) renders through here without going
Expand Down Expand Up @@ -487,7 +487,7 @@ func link(colorOn bool, style lipgloss.Style, label, url string) string {
// through lipgloss.Render instead corrupts it: lipgloss re-styles each rune
// and splits the "\x1b]8;;" introducer, so the terminal can't parse the
// sequence and prints it literally.
return termenv.Hyperlink(url, style.Underline(true).Render(label))
return cmdio.Hyperlink(url, style.Underline(true).Render(label))
}

// statusStyle maps a run status to its accent color: green for success, red for
Expand Down
50 changes: 30 additions & 20 deletions cmd/air/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ import (
"github.com/databricks/databricks-sdk-go"
"github.com/databricks/databricks-sdk-go/experimental/mocks"
"github.com/databricks/databricks-sdk-go/service/jobs"
"github.com/muesli/termenv"
"github.com/stretchr/testify/assert"
)

// asciiPalette returns a palette whose styles emit no escape codes, so render
// output is plain text and assertions stay readable.
func asciiPalette(t *testing.T) palette {
// asciiPalette returns a palette for a color-less target and a function that
// renders styled output the way it reaches that target (no escape codes). On
// lipgloss v2 styles always render full color and are stripped at write time,
// so tests assert on what reaches the target.
func asciiPalette(t *testing.T) (palette, func(string) string) {
r, _ := cmdio.NewRenderer(cmdio.MockDiscard(t.Context()), io.Discard)
return newPalette(r)
return newPalette(r), r.Render
}

// A local HTTP server exercises the SDK export path without a live workspace.
Expand Down Expand Up @@ -209,9 +210,9 @@ func TestSynthConfigYAML(t *testing.T) {
}

func TestColorizeConfigLine(t *testing.T) {
p := asciiPalette(t)
// Under the Ascii profile colorization adds no escapes, so each line is
// preserved verbatim (indentation included) regardless of its role.
p, plain := asciiPalette(t)
// Colorization only adds styling, so each line is preserved verbatim
// (indentation included) regardless of its role.
for _, line := range []string{
"experiment_name: stream-latency-test",
"compute:",
Expand All @@ -220,7 +221,7 @@ func TestColorizeConfigLine(t *testing.T) {
"command: |",
` for i in $(seq 1 10); do echo "step $i"; done`,
} {
assert.Equal(t, line, colorizeConfigLine(p, line))
assert.Equal(t, line, plain(colorizeConfigLine(p, line)))
}
}

Expand All @@ -233,8 +234,8 @@ func TestIsConfigKey(t *testing.T) {
}

func TestRenderBox(t *testing.T) {
p := asciiPalette(t)
out := renderBox(p, configBoxTitle, "experiment_name: stream-latency-test\ncompute:")
p, plain := asciiPalette(t)
out := plain(renderBox(p, configBoxTitle, "experiment_name: stream-latency-test\ncompute:"))
lines := strings.Split(out, "\n")

// Title sits in the top border; corners are rounded; every row is the same width.
Expand All @@ -250,8 +251,8 @@ func TestRenderBox(t *testing.T) {
}

func TestRenderFields(t *testing.T) {
p := asciiPalette(t)
out := renderFields(p, false, runView{
p, plain := asciiPalette(t)
out := plain(renderFields(p, false, runView{
runID: "836121283738861",
dashboardURL: "https://h.test/jobs/runs/836121283738861",
status: "SUCCESS",
Expand All @@ -265,7 +266,7 @@ func TestRenderFields(t *testing.T) {
user: "user@example.com",
accelerators: "1x A10",
environment: "4",
})
}))

// Labels are padded to the longest ("Accelerators"), so values align.
assert.Contains(t, out, "Run ID ")
Expand All @@ -283,8 +284,8 @@ func TestRenderFields(t *testing.T) {
}

func TestRenderFieldsStripsControlCharacters(t *testing.T) {
p := asciiPalette(t)
out := renderFields(p, false, runView{
p, plain := asciiPalette(t)
raw := renderFields(p, false, runView{
runID: "1",
status: "SUCCESS",
submitted: "2026-06-03 04:17 UTC",
Expand All @@ -298,6 +299,12 @@ func TestRenderFieldsStripsControlCharacters(t *testing.T) {
environment: "\x1b]8;;https://attacker.test/\x07databricks_ai_v6\x1b]8;;\x07",
})

// On lipgloss v2 styles always render full color (stripped at write
// time), so check the injected sequences on the raw output only.
for _, injected := range []string{"\x1b]0;", "\x1b[2J", "\x1b[31m", "\r"} {
assert.NotContains(t, raw, injected)
}
out := plain(raw)
assert.Contains(t, out, "Experiment experiment")
assert.Contains(t, out, "MLflow Run runname")
assert.Contains(t, out, "User user@example.com")
Expand All @@ -307,12 +314,15 @@ func TestRenderFieldsStripsControlCharacters(t *testing.T) {
}

func TestLink(t *testing.T) {
p := asciiPalette(t)
p, plain := asciiPalette(t)
// Color off: the bare label, no URL.
assert.Equal(t, "label", link(false, p.blue, "label", "https://h.test"))
assert.Equal(t, "label", link(false, p.blue, "label", ""))
assert.Equal(t, "label", plain(link(false, p.blue, "label", "https://h.test")))
assert.Equal(t, "label", plain(link(false, p.blue, "label", "")))
// With color on, the label is wrapped in an OSC 8 hyperlink to the url.
assert.Contains(t, link(true, p.blue, "label", "https://h.test"), termenv.Hyperlink("https://h.test", "label"))
linked := link(true, p.blue, "label", "https://h.test")
assert.True(t, strings.HasPrefix(linked, "\x1b]8;;https://h.test\x1b\\"), linked)
assert.True(t, strings.HasSuffix(linked, "\x1b]8;;\x1b\\"), linked)
assert.Equal(t, "label", plain(linked))
}

func TestStatusStyleSelectors(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions cmd/air/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ func handleWatchResult(out io.Writer, profile, runID string, err error) error {
// degrades to plain text on non-rich terminals.
func printSubmitResult(ctx context.Context, out io.Writer, runIDStr, dashboardURL string) {
renderer, colorOn := cmdio.NewRenderer(ctx, out)
out = renderer.Writer(out)
p := newPalette(renderer)

fmt.Fprintln(out, p.green.Render("Submitted workload with Job Run ID: "+runIDStr))
Expand All @@ -409,6 +410,7 @@ const logsDividerWidth = 60
// dropped on non-rich terminals; the rule characters are always printed.
func printLogsDivider(ctx context.Context, out io.Writer) {
renderer, _ := cmdio.NewRenderer(ctx, out)
out = renderer.Writer(out)
p := newPalette(renderer)

const label = " Logs "
Expand Down
Loading
Loading