-
Notifications
You must be signed in to change notification settings - Fork 3
Description
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,STRUCTare styled by their outer type code (not element type)NULLoverrides the default dim styling onNullCell. WhenCLI_TYPE_STYLESis set butNULLis 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=STYLEcolon-separated format with named color/attribute support - Register
CLI_TYPE_STYLESas a system variable insystem_variables_registry.go - Wire parsed
typeStylesmap intosystemVariables.typeStyles - Allow
NULLkey to overrideNullCelldefault dim style - Add unit tests for parsing (valid, invalid, edge cases)
- Add integration-level tests verifying styled output
References
StyledCelltype:internal/mycli/format/config.gotypeStylesfield:internal/mycli/system_variables.gospannerRowToRow(cell type selection):internal/mycli/row_iter.go- Prior art:
LS_COLORS,GCC_COLORS,GREP_COLORS(colon-separatedkey=valuewith SGR values)