Skip to content

cmdio: route lipgloss styling through a version-agnostic renderer - #7737

Open
pietern wants to merge 1 commit into
pietern/charm-v2/01-termtest-emulatorfrom
pietern/charm-v2/02a-renderer
Open

pietern wants to merge 1 commit into
pietern/charm-v2/01-termtest-emulatorfrom
pietern/charm-v2/02a-renderer

Conversation

@pietern

@pietern pietern commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Changes

Adds the renderer seam the charm.land v2 swap needs. On v1 it changes output in one place: Git Bash and other MSYS2 terminals (see below).

  • libs/cmdio/lipgloss.go: Renderer (NewStyle, Profile, Writer, Render), Color, LightDark, Hyperlink. NewRenderer uses termenv's profile and Ascii when color is off, as before. New: on an MSYS2 pty pipe, which cmdio treats as a terminal since cmdio: make NO_COLOR only affect color #7700 but termenv cannot recognise, it raises the profile from Ascii to basic ANSI unless CLICOLOR=0. Lipgloss styles (spinner, pager, tables, databricks air) were uncolored there; they now show basic colors. v2 needs the same rule, so it lands here where it can be checked on v1.
  • cmd/air writes through Renderer.Writer.
  • cmd/selftest/tui profile and huh probes read the profile and dark background through cmdio.
  • Ruleguard: libs/gorules/rule_lipgloss.go bans lipgloss.AdaptiveColor and termenv.Hyperlink in new code.

Why

v2 removes AdaptiveColor, termenv.Hyperlink and the *Renderer methods the callers used, so every caller needs a version-agnostic seam first. Landing it on v1 first keeps the swap a mechanical change. LogString is not in this PR, so stderr output is unchanged; that is the next PR.

Tests

  • go build ./...; go vet on touched packages; golangci-lint (0 issues); gofmt clean.
  • TERM=xterm-256color go test -race -count=3 ./libs/cmdio/... passes.
  • go test for libs/tableview, libs/apps/..., cmd/air, cmd/apps, cmd/fs, cmd/aitools, cmd/selftest/..., internal/build passes.
  • Full acceptance suite (go test ./acceptance/...) passes.
  • The pins pass without -update. No golden changes.

Stack: based on pietern/charm-v2/01-termtest-emulator. The branch after this one is pietern/charm-v2/02b-logstring-strip, which changes stderr output.

Manual check for real terminals: in Git Bash (mintty), databricks selftest tui colors --lipgloss shows colored swatches with this PR and uncolored ones with #7736 below it; with CLICOLOR=0 both are uncolored.

This pull request and its description were written by Isaac.

@eng-dev-ecosystem-bot

eng-dev-ecosystem-bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Integration test report

Commit: af6a99b

Run: 46451989938

Env 💚​RECOVERED ✅​pass 🙈​skip Time
💚​ aws linux-2core-8gb 1 88 6 1:56
💚​ aws-windows-latest-4core-16gb 1 88 6 3:23
💚​ azure linux-2core-8gb 1 88 6 2:00
💚​ azure-windows-latest-4core-16gb 1 88 6 3:14
💚​ gcp linux-2core-8gb 1 88 6 2:00
💚​ gcp-windows-latest-4core-16gb 1 88 6 3:23
Test Name aws linux-2core-8gb aws-windows-latest-4core-16gb azure linux-2core-8gb azure-windows-latest-4core-16gb gcp linux-2core-8gb gcp-windows-latest-4core-16gb
💚​ TestAccept 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R
Top 3 slowest tests (at least 2 minutes):
duration env testname
3:22 gcp-windows-latest-4core-16gb TestAccept
3:21 aws-windows-latest-4core-16gb TestAccept
3:13 azure-windows-latest-4core-16gb TestAccept

@pietern
pietern added this pull request to stack #7754 November 18, 2026 08:35
@pietern

pietern commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

/review

Comment thread cmd/selftest/tui/huh.go Resolved
@pietern
pietern force-pushed the pietern/charm-v2/02a-renderer branch from 61fd417 to f9e24c5 Compare November 18, 2026 13:07
@github-actions github-actions Bot added Dependencies Pull requests that update a dependency file AIR Databricks AI Runtime CLI labels Nov 18, 2026
@pietern
pietern force-pushed the pietern/charm-v2/02a-renderer branch from f9e24c5 to c8050e5 Compare November 18, 2026 15:55
@pietern
pietern force-pushed the pietern/charm-v2/02a-renderer branch from c8050e5 to d7b1888 Compare November 18, 2026 16:07
@pietern

pietern commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

/review

@pietern
pietern force-pushed the pietern/charm-v2/02a-renderer branch 3 times, most recently from 093b1be to a89f4ef Compare November 23, 2026 15:47
@pietern
pietern marked this pull request as ready for review November 23, 2026 15:49
@pietern
pietern requested review from a team as code owners November 23, 2026 15:49
@pietern

pietern commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

/review

@pietern
pietern requested a review from a team as a code owner November 23, 2026 15:49

@review-oss-bot review-oss-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review at a89f4ef. Each finding was verified against the code.

No blocking issues found. 5 non-blocking comment(s) and 1 question(s) below.

This PR adds a cmdio.Renderer layer (Color, LightDark, Hyperlink, Writer/Render) so callers stop depending on lipgloss v1 APIs that v2 removes, and it raises MSYS2 pty pipes from Ascii to basic ANSI. I traced the call sites and found nothing that changes output on v1 apart from the MSYS2 raise and the selftest tui profile diagnostic. That diagnostic now prints the same background for both streams and NoTTY where it used to print Ascii. The other items are smaller: the MSYS2 branch reads CLICOLOR from the process environment instead of ctx, one security test lost its OSC 8 check, and a few doc comments are imprecise.

Questions

  1. The MSYS2 Ascii→ANSI raise (libs/cmdio/lipgloss.go:54, plus the two conpty tests) changes what Git Bash/mintty users see. It ships inside a PR that otherwise only reroutes callers and keeps v1 output unchanged, and it can only be checked by hand on Windows. Should it land in its own PR so it can be reviewed and reverted on its own, or does it need to stay with the seam? (non-blocking)

Comment thread cmd/selftest/tui/profile.go Resolved
Comment thread libs/cmdio/lipgloss.go
lg.SetColorProfile(termenv.Ascii)
return &Renderer{lg: lg, profile: colorprofile.NoTTY}, false
}
if isMSYSPipe(w) && lg.ColorProfile() == termenv.Ascii && !termenv.EnvNoColor() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nice to have] termenv.EnvNoColor() reads CLICOLOR (and NO_COLOR) with os.Getenv. Everything else in cmdio reads these from ctx via env.Get (colorFromEnv in capabilities.go). So env.Set(ctx, "CLICOLOR", "0"), as acceptance tests do, doesn't stop an MSYS2 pipe from being raised to ANSI. That is also why the new conpty tests need t.Setenv. Could this be env.Get(ctx, "CLICOLOR") == "0", plus a CLICOLOR_FORCE check if you want termenv's full rule, so the decision comes from the same place as SupportsColor?

Comment thread cmd/air/render_test.go Resolved
Comment thread libs/cmdio/lipgloss.go Resolved
Comment thread libs/cmdio/lipgloss.go Resolved

@pardis-beikzadeh-db pardis-beikzadeh-db left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review limited to cmd/air.

Comment thread cmd/air/render.go
// 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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

problem: every styled cmd/air output now needs out = renderer.Writer(out) next to NewRenderer and newPalette, at four sites (here, run.go:398, run.go:413, logs.go:260). Today a missing one changes nothing, but after the v2 swap a new caller that forgets it prints color codes under --no-color or into pipes.

suggested fix: one helper that returns all three, e.g. newPalette(ctx, out) (palette, io.Writer, bool), used at the four sites. Fine as a follow-up.

@pietern
pietern force-pushed the pietern/charm-v2/02a-renderer branch from a89f4ef to 75adb25 Compare November 26, 2026 11:10
@pietern
pietern force-pushed the pietern/charm-v2/02a-renderer branch from 75adb25 to 273b6a3 Compare November 27, 2026 15:49
Adds the seam the charm.land v2 swap needs without changing output on
v1. cmdio.Renderer carries the color profile for one writer: NewStyle,
Profile, Writer, Render. Color, LightDark and Hyperlink stand in for the
lipgloss helpers whose shape changes in v2. NewRenderer keeps #7700's
rules: termenv's profile, Ascii when color is off, and the MSYS2 pty
raise to ANSI unless CLICOLOR=0.

Callers move to it: cmd/air writes through Renderer.Writer, and the
selftest profile and huh probes read the profile and dark background
through cmdio. Ruleguard bans lipgloss.AdaptiveColor and
termenv.Hyperlink in new code so the v2 swap does not reintroduce them.

No output changes: LogString still writes to stderr unstripped, and no
pin golden moves.

Co-authored-by: Isaac <no-reply@databricks.com>
@pietern
pietern force-pushed the pietern/charm-v2/02a-renderer branch from 7d1ad34 to af6a99b Compare November 30, 2026 15:32

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AIR Databricks AI Runtime CLI Dependencies Pull requests that update a dependency file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants