Skip to content

feat: expose type-based styling as a system variable #558

@apstndb

Description

@apstndb

Background

PR #557 introduced StyledCell and the typeStyles field on systemVariables, enabling type-based ANSI styling for query result cells. However, typeStyles is currently a private field with no way to configure it — it defaults to nil (no styling).

Goal

Expose type-to-style mapping as a system variable CLI_TYPE_STYLES so users can configure how different Spanner types are displayed in table output.

Design

Format

LS_COLORS/GCC_COLORS style — colon-separated key=value pairs:

SET CLI_TYPE_STYLES = "STRING=green:INT64=bold:FLOAT64=bold:BOOL=yellow:TIMESTAMP=cyan:NULL=dim"

Keys

Spanner type names (uppercase) matching TypeCode enum names, plus NULL:

BOOL, INT64, FLOAT32, FLOAT64, NUMERIC, STRING, BYTES, JSON,
DATE, TIMESTAMP, ARRAY, STRUCT, PROTO, ENUM, INTERVAL, UUID, NULL
  • ARRAY, STRUCT are styled by their outer type code (not element type)
  • NULL overrides the default dim styling on NullCell. When CLI_TYPE_STYLES is set but NULL is not specified, the current default dim is preserved.

Values

Semicolon-separated SGR parameters, supporting both raw numbers and named colors/attributes:

Named SGR Named SGR
bold 1 black 30
dim 2 red 31
italic 3 green 32
underline 4 yellow 33
blink 5 blue 34
reverse 7 magenta 35
hidden 8 cyan 36
strikethrough 9 white 37

Raw SGR numbers also accepted for 256-color (38;5;N) and truecolor (38;2;R;G;B).

Examples:

CLI_TYPE_STYLES = "STRING=green:INT64=bold:NULL=dim"
CLI_TYPE_STYLES = "STRING=1;32:TIMESTAMP=38;5;214"
CLI_TYPE_STYLES = "STRING=bold;green:BOOL=yellow"

Default

Empty string (no type styling) — preserves current behavior. NullCell retains its hardcoded dim when CLI_TYPE_STYLES is unset or empty.

Interaction with CLI_STYLED_OUTPUT

CLI_TYPE_STYLES only takes effect when CLI_STYLED_OUTPUT resolves to styled mode (Auto+TTY, or True). In non-styled contexts (MCP, piped output, False), RawText() is used regardless of CLI_TYPE_STYLES.

Tasks

  • Implement parser for the TYPE=STYLE colon-separated format with named color/attribute support
  • Register CLI_TYPE_STYLES as a system variable in system_variables_registry.go
  • Wire parsed typeStyles map into systemVariables.typeStyles
  • Allow NULL key to override NullCell default dim style
  • Add unit tests for parsing (valid, invalid, edge cases)
  • Add integration-level tests verifying styled output

References

  • StyledCell type: internal/mycli/format/config.go
  • typeStyles field: internal/mycli/system_variables.go
  • spannerRowToRow (cell type selection): internal/mycli/row_iter.go
  • Prior art: LS_COLORS, GCC_COLORS, GREP_COLORS (colon-separated key=value with SGR values)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions