Skip to content

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

WIP: Auto-commit before merge

Maximilian Roos40c91236739e
diff --git a/CLAUDE.md b/CLAUDE.md
index 2ddfec404..aa72b0b32 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -239,6 +239,71 @@ println!("{}", line.render());
See `src/commands/list/render.rs` for advanced usage.
+### Gutter Formatting for Quoted Content
+
+The **gutter** is a subtle visual separator (single space with background color) used for quoted content like commands and configuration.
+
+**Core Principle: Alignment with Context**
+
+The gutter must align with its surrounding context to maintain clear visual hierarchy.
+
+#### Indentation Rules
+
+1. **Gutter positioning**: Place the gutter at the same indent level as its context
+ - If the label/description is at indent N, the gutter starts at indent N
+ - This creates visual cohesion between the context and the quoted content
+
+2. **After-gutter spacing**: Always use 1 space after the gutter
+ - The gutter itself provides visual separation
+ - Minimal spacing keeps content readable without excessive whitespace
+
+3. **Preserve internal structure**: Multi-line content maintains its original formatting
+ - Don't strip leading whitespace that's part of the content
+ - Apply gutter treatment uniformly to each line
+
+#### Examples
+
+**Top-level content (no context indent):**
+```
+Global Config: /path/to/config
+ worktree-path = "../{main-worktree}.{branch}"
+
+ [llm]
+```
+- Label at column 0 → gutter at column 0 → content at column 1
+
+**Nested context (2-space indent):**
+```
+ project wants to execute:
+ command here
+ more lines
+```
+- Label at column 2 → gutter at column 2 → content at column 3
+
+**Implementation:**
+
+```rust
+use worktrunk::styling::format_with_gutter;
+
+// Top-level: gutter at column 0
+print!("{}", format_with_gutter(&command, ""));
+
+// 2-space context: gutter at column 2
+print!(" "); // Position at context level
+print!("{}", format_with_gutter(&command, ""));
+
+// Or equivalently with left margin parameter:
+print!("{}", format_with_gutter(&command, " "));
+```
+
+**Function Signature:**
+```rust
+/// Arguments:
+/// - content: Text to format (preserves internal structure for multi-line)
+/// - left_margin: Spaces before the gutter (positions it at context level)
+pub fn format_with_gutter(content: &str, left_margin: &str) -> String
+```
+
## Testing Guidelines
### Testing with --execute Commands
diff --git a/src/commands/command_approval.rs b/src/commands/command_approval.rs
index 8a371306e..a27675d64 100644
--- a/src/commands/command_approval.rs
+++ b/src/commands/command_approval.rs
@@ -107,7 +107,7 @@ fn prompt_for_approval(command: &str, project_id: &str) -> std::io::Result<bool>
eprintln!("{WARNING_EMOJI} {WARNING}Permission required to execute in worktree{WARNING:#}");
eprintln!();
eprintln!(" {bold}{project_name}{bold:#} ({dim}{project_id}{dim:#}) wants to execute:");
- eprint!("{}", format_with_gutter(command, " "));
+ eprint!("{}", format_with_gutter(command, " ")); // Gutter at column 2 to match context
eprintln!();
eprint!(" {HINT_EMOJI} Allow and remember? {bold}[y/N]{bold:#} ");
io::stderr().flush()?;
diff --git a/src/commands/config.rs b/src/commands/config.rs
index debd105f3..66e00e8dc 100644
--- a/src/commands/config.rs
+++ b/src/commands/config.rs
@@ -91,8 +91,8 @@ fn display_global_config() -> Result<(), GitError> {
return Ok(());
}
- // Display TOML with syntax highlighting
- print!("{}", format_toml(&contents, " "));
+ // Display TOML with syntax highlighting (gutter at column 0)
+ print!("{}", format_toml(&contents, ""));
Ok(())
}
@@ -129,8 +129,8 @@ fn display_project_config() -> Result<(), GitError> {
return Ok(());
}
- // Display TOML with syntax highlighting
- print!("{}", format_toml(&contents, " "));
+ // Display TOML with syntax highlighting (gutter at column 0)
+ print!("{}", format_toml(&contents, ""));
Ok(())
}
diff --git a/src/commands/worktree.rs b/src/commands/worktree.rs
index 9bcaba311..5f2cac56c 100644
--- a/src/commands/worktree.rs
+++ b/src/commands/worktree.rs
@@ -422,7 +422,7 @@ fn execute_post_create_commands(
use std::io::Write;
let cyan = AnstyleStyle::new().fg_color(Some(Color::Ansi(AnsiColor::Cyan)));
eprintln!("🔄 {cyan}Executing (post-create):{cyan:#}");
- eprint!("{}", format_with_gutter(&expanded_command, " "));
+ eprint!("{}", format_with_gutter(&expanded_command, "")); // Gutter at column 0
let _ = std::io::stderr().flush();
if let Err(e) = execute_command_in_worktree(worktree_path, &expanded_command) {
diff --git a/src/styling.rs b/src/styling.rs
index 6bd01b3f9..9a5e030bf 100644
--- a/src/styling.rs
+++ b/src/styling.rs
@@ -168,20 +168,25 @@ impl StyledLine {
/// This creates a subtle visual separator for quoted content like commands or configuration.
///
/// # Arguments
-/// * `content` - The text to format (can be multi-line)
-/// * `indent` - Additional indentation after the gutter (e.g., " " or " ")
+/// * `content` - The text to format (preserves internal structure for multi-line)
+/// * `left_margin` - Spaces before the gutter (positions it at the context indent level)
+///
+/// The gutter appears at the `left_margin` position, followed by 1 space, then the content.
///
/// # Example
/// ```ignore
-/// let command = "npm install\nnpm test";
-/// print!("{}", format_with_gutter(&command, " "));
+/// // Top-level (gutter at column 0)
+/// print!("{}", format_with_gutter(&config, ""));
+///
+/// // Nested in 2-space context (gutter at column 2)
+/// print!("{}", format_with_gutter(&command, " "));
/// ```
-pub fn format_with_gutter(content: &str, indent: &str) -> String {
+pub fn format_with_gutter(content: &str, left_margin: &str) -> String {
let gutter = Style::new().bg_color(Some(Color::Ansi(AnsiColor::Black)));
let mut output = String::new();
for line in content.lines() {
- output.push_str(&format!("{gutter} {gutter:#}{indent}{line}\n"));
+ output.push_str(&format!("{left_margin}{gutter} {gutter:#} {line}\n"));
}
output
@@ -192,7 +197,7 @@ pub fn format_with_gutter(content: &str, indent: &str) -> String {
// ============================================================================
/// Formats TOML content with syntax highlighting using synoptic
-pub fn format_toml(content: &str, indent: &str) -> String {
+pub fn format_toml(content: &str, left_margin: &str) -> String {
// Gutter style: subtle background for visual separation
let gutter = Style::new().bg_color(Some(Color::Ansi(AnsiColor::Black)));
@@ -204,7 +209,9 @@ pub fn format_toml(content: &str, indent: &str) -> String {
let dim = Style::new().dimmed();
let mut output = String::new();
for line in content.lines() {
- output.push_str(&format!("{gutter} {gutter:#}{indent}{dim}{line}{dim:#}\n"));
+ output.push_str(&format!(
+ "{left_margin}{gutter} {gutter:#} {dim}{line}{dim:#}\n"
+ ));
}
return output;
}
@@ -218,10 +225,8 @@ pub fn format_toml(content: &str, indent: &str) -> String {
// Render each line with appropriate styling
for (y, line) in lines.iter().enumerate() {
- // Add gutter first
- output.push_str(&format!("{gutter} {gutter:#}"));
- // Add indentation
- output.push_str(indent);
+ // Add left margin, gutter, and spacing
+ output.push_str(&format!("{left_margin}{gutter} {gutter:#} "));
// Render each token with appropriate styling
for token in highlighter.line(y, line) {
@@ -298,7 +303,7 @@ project = "github.com/user/repo"
command = "npm install"
"#;
- let output = format_toml(toml_content, " ");
+ let output = format_toml(toml_content, "");
// Check that output contains ANSI escape codes
assert!(