Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

fix(statusline): space the context gauge emoji from its percent (#2944)

Maximilian Roos51e32f4425eb
diff --git a/.claude/skills/writing-user-outputs/SKILL.md b/.claude/skills/writing-user-outputs/SKILL.md
index 623404b99..fc041bbbc 100644
--- a/.claude/skills/writing-user-outputs/SKILL.md
+++ b/.claude/skills/writing-user-outputs/SKILL.md
@@ -648,6 +648,28 @@ perform_squash()?;
eprintln!("{}", success_message("Squashed @ a1b2c3d"));
```
+## Section and Glyph Spacing
+
+When composing tightly-packed output where adjacent pieces carry distinct
+meaning (the statusline segments, prefix-char indicators like `@+1`, `↓1`,
+`?^|`), pack sections flush — no separating space. The marker and its value
+read as one unit, and visual density keeps the line short.
+
+The one exception is **emoji**: leave a trailing space after an emoji glyph.
+Most terminals render emoji as double-width and bleed the glyph into the cell
+to its right, so a flush `🌔65%` collides the moon with the digits. A space
+(`🌔 65%`) keeps them legible. ASCII and narrow Unicode markers (`@`, `↓`, `●`,
+`⊂`) don't have this problem and stay flush.
+
+```rust
+// GOOD - ASCII marker flush with its value
+format!("@{added}"); // @+1
+// GOOD - emoji gets a trailing space to clear the next cell
+format!("{moon} {pct:.0}%"); // 🌔 65%
+// BAD - emoji runs into the digits; terminals overlap the glyph
+format!("{moon}{pct:.0}%"); // 🌔65%
+```
+
## Style Constants
Only three `anstyle` constants exist for table rendering (`src/styling/constants.rs`):
diff --git a/docs/content/claude-code.md b/docs/content/claude-code.md
index 2f740dc2c..e95cc7b07 100644
--- a/docs/content/claude-code.md
+++ b/docs/content/claude-code.md
@@ -109,7 +109,7 @@ On session exit the worktree is offered for removal via the `WorktreeRemove` hoo
`wt list statusline --format=claude-code` outputs a single-line status for the Claude Code statusline. When the CI status cache is stale, this fetches from the network — typically 1–2 seconds — making it suitable for async statuslines but too slow for synchronous shell prompts. If a faster version would be helpful, please [open an issue](https://github.com/max-sixty/worktrunk/issues).
-<code>~/w/myproject.feature-auth !🤖 @<span style='color:#0a0'>+42</span> <span style='color:#a00'>-8</span> <span style='color:#0a0'>↑3</span> <span style='color:#0a0'>⇡1</span> <span style='color:#0a0'>●</span> Opus 🌔65% <span style='color:#a70'>1.4×pace(10am–3pm)</span></code>
+<code>~/w/myproject.feature-auth !🤖 @<span style='color:#0a0'>+42</span> <span style='color:#a00'>-8</span> <span style='color:#0a0'>↑3</span> <span style='color:#0a0'>⇡1</span> <span style='color:#0a0'>●</span> Opus 🌔 65% <span style='color:#a70'>1.4×pace(10am–3pm)</span></code>
When Claude Code provides context window usage via stdin JSON, a moon phase gauge appears (🌕→🌑 as context fills). A yellow `<n>×pace(<window>)` segment appears when Claude's 5-hour or weekly rate limit is on track to be hit before reset — `1.4×pace(10am–3pm)` reads as 1.4× the pace that would exactly fill that window.
diff --git a/skills/worktrunk/reference/claude-code.md b/skills/worktrunk/reference/claude-code.md
index 0adcae17d..a06b52f76 100644
--- a/skills/worktrunk/reference/claude-code.md
+++ b/skills/worktrunk/reference/claude-code.md
@@ -111,7 +111,7 @@ On session exit the worktree is offered for removal via the `WorktreeRemove` hoo
`wt list statusline --format=claude-code` outputs a single-line status for the Claude Code statusline. When the CI status cache is stale, this fetches from the network — typically 1–2 seconds — making it suitable for async statuslines but too slow for synchronous shell prompts. If a faster version would be helpful, please [open an issue](https://github.com/max-sixty/worktrunk/issues).
-<code>~/w/myproject.feature-auth !🤖 @<span style='color:#0a0'>+42</span> <span style='color:#a00'>-8</span> <span style='color:#0a0'>↑3</span> <span style='color:#0a0'>⇡1</span> <span style='color:#0a0'>●</span> Opus 🌔65% <span style='color:#a70'>1.4×pace(10am–3pm)</span></code>
+<code>~/w/myproject.feature-auth !🤖 @<span style='color:#0a0'>+42</span> <span style='color:#a00'>-8</span> <span style='color:#0a0'>↑3</span> <span style='color:#0a0'>⇡1</span> <span style='color:#0a0'>●</span> Opus 🌔 65% <span style='color:#a70'>1.4×pace(10am–3pm)</span></code>
When Claude Code provides context window usage via stdin JSON, a moon phase gauge appears (🌕→🌑 as context fills). A yellow `<n>×pace(<window>)` segment appears when Claude's 5-hour or weekly rate limit is on track to be hit before reset — `1.4×pace(10am–3pm)` reads as 1.4× the pace that would exactly fill that window.
diff --git a/src/commands/statusline.rs b/src/commands/statusline.rs
index 689d76cdd..5b5fbf0e5 100644
--- a/src/commands/statusline.rs
+++ b/src/commands/statusline.rs
@@ -516,10 +516,12 @@ fn format_context_gauge(percentage: f64) -> String {
91..=97 => '🌒',
_ => '🌑',
};
- // Display the original percentage (not clamped) for transparency
- // Emoji + percent runs together (no separator) to match the other
- // prefix-char segments in the statusline: `@+1`, `↓1`, `?^|`.
- format!("{symbol}{:.0}%", percentage)
+ // Display the original percentage (not clamped) for transparency.
+ // A space separates the moon emoji from the percent: unlike the ASCII
+ // prefix-char segments (`@+1`, `↓1`, `?^|`) that run flush, emoji glyphs
+ // are double-width and bleed into the next cell on most terminals, so they
+ // need a trailing space to keep from colliding with the digits.
+ format!("{symbol} {:.0}%", percentage)
}
/// Run the statusline command.
@@ -1002,38 +1004,38 @@ mod tests {
fn test_context_gauge_formatting() {
// Test boundary values for each moon phase symbol (waning - darker as context fills)
// Thresholds use exponential halving: ratio 16:8:4:2:1, normalized to 100%
- assert_eq!(format_context_gauge(0.0), "🌕0%");
- assert_eq!(format_context_gauge(51.0), "🌕51%");
- assert_eq!(format_context_gauge(52.0), "🌔52%");
- assert_eq!(format_context_gauge(77.0), "🌔77%");
- assert_eq!(format_context_gauge(78.0), "🌓78%");
- assert_eq!(format_context_gauge(90.0), "🌓90%");
- assert_eq!(format_context_gauge(91.0), "🌒91%");
- assert_eq!(format_context_gauge(97.0), "🌒97%");
- assert_eq!(format_context_gauge(98.0), "🌑98%");
- assert_eq!(format_context_gauge(100.0), "🌑100%");
+ assert_eq!(format_context_gauge(0.0), "🌕 0%");
+ assert_eq!(format_context_gauge(51.0), "🌕 51%");
+ assert_eq!(format_context_gauge(52.0), "🌔 52%");
+ assert_eq!(format_context_gauge(77.0), "🌔 77%");
+ assert_eq!(format_context_gauge(78.0), "🌓 78%");
+ assert_eq!(format_context_gauge(90.0), "🌓 90%");
+ assert_eq!(format_context_gauge(91.0), "🌒 91%");
+ assert_eq!(format_context_gauge(97.0), "🌒 97%");
+ assert_eq!(format_context_gauge(98.0), "🌑 98%");
+ assert_eq!(format_context_gauge(100.0), "🌑 100%");
}
#[test]
fn test_context_gauge_fractional_percentages() {
// Fractional values are rounded (per {:.0} format specifier)
// Rust uses banker's rounding (round half to even)
- assert_eq!(format_context_gauge(42.7), "🌕43%"); // 43% is in 0-51% range
- assert_eq!(format_context_gauge(0.4), "🌕0%");
- assert_eq!(format_context_gauge(0.5), "🌕0%"); // banker's rounding: 0.5 rounds to even (0)
- assert_eq!(format_context_gauge(1.5), "🌕2%"); // banker's rounding: 1.5 rounds to even (2)
- assert_eq!(format_context_gauge(99.9), "🌑100%");
+ assert_eq!(format_context_gauge(42.7), "🌕 43%"); // 43% is in 0-51% range
+ assert_eq!(format_context_gauge(0.4), "🌕 0%");
+ assert_eq!(format_context_gauge(0.5), "🌕 0%"); // banker's rounding: 0.5 rounds to even (0)
+ assert_eq!(format_context_gauge(1.5), "🌕 2%"); // banker's rounding: 1.5 rounds to even (2)
+ assert_eq!(format_context_gauge(99.9), "🌑 100%");
}
#[test]
fn test_context_gauge_edge_cases() {
// Negative values: symbol clamps to bright (low usage), but display shows original value
- assert_eq!(format_context_gauge(-5.0), "🌕-5%");
- assert_eq!(format_context_gauge(-0.1), "🌕-0%"); // rounds to -0%
+ assert_eq!(format_context_gauge(-5.0), "🌕 -5%");
+ assert_eq!(format_context_gauge(-0.1), "🌕 -0%"); // rounds to -0%
// Values over 100%: symbol clamps to dark (high usage), but display shows original value
- assert_eq!(format_context_gauge(105.0), "🌑105%");
- assert_eq!(format_context_gauge(150.0), "🌑150%");
+ assert_eq!(format_context_gauge(105.0), "🌑 105%");
+ assert_eq!(format_context_gauge(150.0), "🌑 150%");
}
#[test]
diff --git a/tests/integration_tests/statusline.rs b/tests/integration_tests/statusline.rs
index 1cb0fda2c..c60e072ff 100644
--- a/tests/integration_tests/statusline.rs
+++ b/tests/integration_tests/statusline.rs
@@ -247,7 +247,7 @@ fn test_statusline_claude_code_with_context_gauge(repo: TestRepo) {
let output = run_statusline(&repo, &["--format=claude-code"], Some(&json));
claude_code_snapshot_settings().bind(|| {
- assert_snapshot!(output, @"[PATH] main ^| Opus 🌕42%");
+ assert_snapshot!(output, @"[PATH] main ^| Opus 🌕 42%");
});
}
@@ -264,7 +264,7 @@ fn test_statusline_claude_code_context_gauge_low(repo: TestRepo) {
let output = run_statusline(&repo, &["--format=claude-code"], Some(&json));
claude_code_snapshot_settings().bind(|| {
- assert_snapshot!(output, @"[PATH] main ^| Opus 🌕5%");
+ assert_snapshot!(output, @"[PATH] main ^| Opus 🌕 5%");
});
}
@@ -281,7 +281,7 @@ fn test_statusline_claude_code_context_gauge_high(repo: TestRepo) {
let output = run_statusline(&repo, &["--format=claude-code"], Some(&json));
claude_code_snapshot_settings().bind(|| {
- assert_snapshot!(output, @"[PATH] main ^| Opus 🌑98%");
+ assert_snapshot!(output, @"[PATH] main ^| Opus 🌑 98%");
});
}
diff --git a/tests/snapshots/integration__integration_tests__statusline__rate_limit_5h_24h_locale.snap b/tests/snapshots/integration__integration_tests__statusline__rate_limit_5h_24h_locale.snap
index 331e4734e..591c55626 100644
--- a/tests/snapshots/integration__integration_tests__statusline__rate_limit_5h_24h_locale.snap
+++ b/tests/snapshots/integration__integration_tests__statusline__rate_limit_5h_24h_locale.snap
@@ -2,4 +2,4 @@
source: tests/integration_tests/statusline.rs
expression: out
---
-[PATH] main ^| Opus 🌕42% 1.3×pace(10:00–15:00)
+[PATH] main ^| Opus 🌕 42% 1.3×pace(10:00–15:00)
diff --git a/tests/snapshots/integration__integration_tests__statusline__rate_limit_5h_at_limit.snap b/tests/snapshots/integration__integration_tests__statusline__rate_limit_5h_at_limit.snap
index 1c3536ae7..754b2fc73 100644
--- a/tests/snapshots/integration__integration_tests__statusline__rate_limit_5h_at_limit.snap
+++ b/tests/snapshots/integration__integration_tests__statusline__rate_limit_5h_at_limit.snap
@@ -2,4 +2,4 @@
source: tests/integration_tests/statusline.rs
expression: out
---
-[PATH] main ^| Opus 🌕42% 1.7×pace(10am–3pm)
+[PATH] main ^| Opus 🌕 42% 1.7×pace(10am–3pm)
diff --git a/tests/snapshots/integration__integration_tests__statusline__rate_limit_5h_clock_time.snap b/tests/snapshots/integration__integration_tests__statusline__rate_limit_5h_clock_time.snap
index d6cb02423..d589edf43 100644
--- a/tests/snapshots/integration__integration_tests__statusline__rate_limit_5h_clock_time.snap
+++ b/tests/snapshots/integration__integration_tests__statusline__rate_limit_5h_clock_time.snap
@@ -2,4 +2,4 @@
source: tests/integration_tests/statusline.rs
expression: out
---
-[PATH] main ^| Opus 🌕42% 1.3×pace(10am–3pm)
+[PATH] main ^| Opus 🌕 42% 1.3×pace(10am–3pm)
diff --git a/tests/snapshots/integration__integration_tests__statusline__rate_limit_5h_with_minutes.snap b/tests/snapshots/integration__integration_tests__statusline__rate_limit_5h_with_minutes.snap
index 92c769032..ca01ace4b 100644
--- a/tests/snapshots/integration__integration_tests__statusline__rate_limit_5h_with_minutes.snap
+++ b/tests/snapshots/integration__integration_tests__statusline__rate_limit_5h_with_minutes.snap
@@ -2,4 +2,4 @@
source: tests/integration_tests/statusline.rs
expression: out
---
-[PATH] main ^| Opus 🌕42% 1.1×pace(8:30am–1:30pm)
+[PATH] main ^| Opus 🌕 42% 1.1×pace(8:30am–1:30pm)
diff --git a/tests/snapshots/integration__integration_tests__statusline__rate_limit_7d_with_day_and_time.snap b/tests/snapshots/integration__integration_tests__statusline__rate_limit_7d_with_day_and_time.snap
index bf52ea4b1..528c3188c 100644
--- a/tests/snapshots/integration__integration_tests__statusline__rate_limit_7d_with_day_and_time.snap
+++ b/tests/snapshots/integration__integration_tests__statusline__rate_limit_7d_with_day_and_time.snap
@@ -2,4 +2,4 @@
source: tests/integration_tests/statusline.rs
expression: out
---
-[PATH] main ^| Opus 🌕42% 1.9×pace(Mon–Mon 3pm)
+[PATH] main ^| Opus 🌕 42% 1.9×pace(Mon–Mon 3pm)
diff --git a/tests/snapshots/integration__integration_tests__statusline__rate_limit_both_picks_worse.snap b/tests/snapshots/integration__integration_tests__statusline__rate_limit_both_picks_worse.snap
index bf52ea4b1..528c3188c 100644
--- a/tests/snapshots/integration__integration_tests__statusline__rate_limit_both_picks_worse.snap
+++ b/tests/snapshots/integration__integration_tests__statusline__rate_limit_both_picks_worse.snap
@@ -2,4 +2,4 @@
source: tests/integration_tests/statusline.rs
expression: out
---
-[PATH] main ^| Opus 🌕42% 1.9×pace(Mon–Mon 3pm)
+[PATH] main ^| Opus 🌕 42% 1.9×pace(Mon–Mon 3pm)
diff --git a/tests/snapshots/integration__integration_tests__statusline__rate_limit_drops_at_narrow_width.snap b/tests/snapshots/integration__integration_tests__statusline__rate_limit_drops_at_narrow_width.snap
index 114b02d8a..eac1f8ed4 100644
--- a/tests/snapshots/integration__integration_tests__statusline__rate_limit_drops_at_narrow_width.snap
+++ b/tests/snapshots/integration__integration_tests__statusline__rate_limit_drops_at_narrow_width.snap
@@ -2,4 +2,4 @@
source: tests/integration_tests/statusline.rs
expression: out
---
-[PATH] main ^| Opus 🌕42%
+[PATH] main ^| Opus 🌕 42%
diff --git a/tests/snapshots/integration__integration_tests__statusline__rate_limit_hidden_when_safe.snap b/tests/snapshots/integration__integration_tests__statusline__rate_limit_hidden_when_safe.snap
index 114b02d8a..eac1f8ed4 100644
--- a/tests/snapshots/integration__integration_tests__statusline__rate_limit_hidden_when_safe.snap
+++ b/tests/snapshots/integration__integration_tests__statusline__rate_limit_hidden_when_safe.snap
@@ -2,4 +2,4 @@
source: tests/integration_tests/statusline.rs
expression: out
---
-[PATH] main ^| Opus 🌕42%
+[PATH] main ^| Opus 🌕 42%
diff --git a/tests/snapshots/integration__integration_tests__statusline__rate_limit_with_dirty_worktree_and_context.snap b/tests/snapshots/integration__integration_tests__statusline__rate_limit_with_dirty_worktree_and_context.snap
index 54edb0484..d7a3dc87c 100644
--- a/tests/snapshots/integration__integration_tests__statusline__rate_limit_with_dirty_worktree_and_context.snap
+++ b/tests/snapshots/integration__integration_tests__statusline__rate_limit_with_dirty_worktree_and_context.snap
@@ -2,4 +2,4 @@
source: tests/integration_tests/statusline.rs
expression: out
---
-[PATH] main ?^| @+1 Opus 🌒95% 1.3×pace(10am–3pm)
+[PATH] main ?^| @+1 Opus 🌒 95% 1.3×pace(10am–3pm)