Skip to content

Story 7.6: Starship-compatible format field (#56)#63

Merged
stephenleo merged 2 commits intomainfrom
worktree-7-6-starship-format-field
Mar 8, 2026
Merged

Story 7.6: Starship-compatible format field (#56)#63
stephenleo merged 2 commits intomainfrom
worktree-7-6-starship-format-field

Conversation

@stephenleo
Copy link
Copy Markdown
Owner

Summary

  • Add format field to CshipConfig supporting Starship-style format strings with $line_break for multi-row output and [content](style) ANSI styled spans
  • Fix parse_line to scan for both [ and $ simultaneously, preventing styled spans after literal text from being silently consumed as plain text
  • Handle $fill as empty with one-shot warning, $line_break splitting at the render() level, and format priority over lines with tracing::warn!

Closes #56

Test plan

  • cargo clippy -- -D warnings clean
  • cargo fmt --check clean
  • cargo test — 324 total (259 unit + 65 integration), 0 failures
  • 12 new tests: styled span parsing (content, empty, spaces, unclosed bracket, mixed, after-literal, after-native), $line_break split, format priority, lines backwards compat, $fill empty, integration format+line_break

🤖 Generated with Claude Code

…ed spans (#56)

Add `format` field to CshipConfig supporting Starship-style format strings
with `$line_break` for multi-row output and `[content](style)` ANSI spans.
Fix parse_line to scan for both `[` and `$` simultaneously, preventing
styled spans after literal text from being silently eaten as plain text.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@claude
Copy link
Copy Markdown

claude bot commented Mar 8, 2026

Code review

Bug: $token name parser doesn't stop at [, causing styled spans immediately adjacent to tokens to be silently dropped

File: src/renderer.rs (L59–L64)

When parse_line processes a $token, it terminates the token name only at whitespace:

let after_dollar = &remaining[1..];
let name_end = after_dollar
    .find(char::is_whitespace)
    .unwrap_or(after_dollar.len());
let name = &after_dollar[..name_end];

Because [ is not a stop character here, a format string like $cship.model[sep](fg:red) (no space before the styled span) will set name = "cship.model[sep](fg:red)" — the entire styled span is absorbed into the token name. The StyledSpan is never emitted; instead a Native lookup for a nonexistent module name is pushed, producing empty output.

This inconsistency is introduced by this PR: before it, [ had no special meaning, so consuming it into a token name was harmless. Now that [ opens a styled span, the $ name parser must also stop at it.

The existing tests all place a space between a token and a span (e.g. $cship.model [sep](fg:red)), so the no-space case is untested and broken.

Suggested fix:

let name_end = after_dollar
    .find(|c: char| c.is_whitespace() || c == '[')
    .unwrap_or(after_dollar.len());

🤖 Generated with Claude Code

…led spans

Without this, $cship.model[sep](fg:red) (no space) would consume the entire
[sep](fg:red) as part of the token name, silently dropping the styled span.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@stephenleo stephenleo merged commit ee48694 into main Mar 8, 2026
3 checks passed
@stephenleo stephenleo deleted the worktree-7-6-starship-format-field branch March 8, 2026 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Story 7.6: Starship-compatible format field with $line_break and [content](style) spans

1 participant