Skip to content

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

Refactor: Use gutter formatting for command output

Maximilian Roosec98780e5548
diff --git a/src/commands/command_approval.rs b/src/commands/command_approval.rs
index bcdfd4fe1..8a371306e 100644
--- a/src/commands/command_approval.rs
+++ b/src/commands/command_approval.rs
@@ -5,7 +5,7 @@
use worktrunk::config::{CommandConfig, WorktrunkConfig};
use worktrunk::git::GitError;
-use worktrunk::styling::{AnstyleStyle, HINT_EMOJI, WARNING, WARNING_EMOJI};
+use worktrunk::styling::{AnstyleStyle, HINT_EMOJI, WARNING, WARNING_EMOJI, format_with_gutter};
/// Convert CommandConfig to a vector of (name, command) pairs
///
@@ -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:");
- eprintln!(" {dim}{command}{dim:#}");
+ eprint!("{}", format_with_gutter(command, " "));
eprintln!();
eprint!(" {HINT_EMOJI} Allow and remember? {bold}[y/N]{bold:#} ");
io::stderr().flush()?;
diff --git a/src/commands/worktree.rs b/src/commands/worktree.rs
index 2d8c91f24..9bcaba311 100644
--- a/src/commands/worktree.rs
+++ b/src/commands/worktree.rs
@@ -105,7 +105,8 @@ use std::path::PathBuf;
use worktrunk::config::{ProjectConfig, WorktrunkConfig, expand_template};
use worktrunk::git::{GitError, Repository};
use worktrunk::styling::{
- AnstyleStyle, ERROR, ERROR_EMOJI, HINT, HINT_EMOJI, WARNING, WARNING_EMOJI, eprintln, println,
+ AnstyleStyle, ERROR, ERROR_EMOJI, HINT, HINT_EMOJI, WARNING, WARNING_EMOJI, eprint, eprintln,
+ format_with_gutter, println,
};
use crate::commands::command_approval::{check_and_approve_command, command_config_to_vec};
@@ -420,7 +421,8 @@ fn execute_post_create_commands(
use anstyle::{AnsiColor, Color};
use std::io::Write;
let cyan = AnstyleStyle::new().fg_color(Some(Color::Ansi(AnsiColor::Cyan)));
- eprintln!("πŸ”„ {cyan}Executing (post-create): {expanded_command}{cyan:#}");
+ eprintln!("πŸ”„ {cyan}Executing (post-create):{cyan:#}");
+ eprint!("{}", format_with_gutter(&expanded_command, " "));
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 00b12fc5e..6bd01b3f9 100644
--- a/src/styling.rs
+++ b/src/styling.rs
@@ -159,6 +159,34 @@ impl StyledLine {
}
}
+// ============================================================================
+// Gutter Formatting
+// ============================================================================
+
+/// Formats text with a gutter (single-space with background color) on each line
+///
+/// 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 " ")
+///
+/// # Example
+/// ```ignore
+/// let command = "npm install\nnpm test";
+/// print!("{}", format_with_gutter(&command, " "));
+/// ```
+pub fn format_with_gutter(content: &str, indent: &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
+}
+
// ============================================================================
// TOML Syntax Highlighting
// ============================================================================
diff --git a/tests/snapshots/integration__integration_tests__post_start_commands__both_create_and_start.snap b/tests/snapshots/integration__integration_tests__post_start_commands__both_create_and_start.snap
index 21d48b8c4..c30ccacbc 100644
--- a/tests/snapshots/integration__integration_tests__post_start_commands__both_create_and_start.snap
+++ b/tests/snapshots/integration__integration_tests__post_start_commands__both_create_and_start.snap
@@ -13,7 +13,7 @@ info:
GIT_CONFIG_GLOBAL: /dev/null
GIT_CONFIG_SYSTEM: /dev/null
GIT_EDITOR: ""
- HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmp2NgX3P
+ HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpDBx8wC
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1704067200"
@@ -27,6 +27,7 @@ exit_code: 0
To enable automatic cd, run: wt configure-shell
----- stderr -----
-πŸ”„ Executing (post-create): echo 'Setup done' > setup.txt
+πŸ”„ Executing (post-create):
+  echo 'Setup done' > setup.txt
πŸ”„ Starting (background): sleep 0.5 && echo 'Server running' > server.txt
→ Logs: .git/wt-logs/post-start-[NAME]-[TIMESTAMP].log
diff --git a/tests/snapshots/integration__integration_tests__post_start_commands__post_create_failing_command.snap b/tests/snapshots/integration__integration_tests__post_start_commands__post_create_failing_command.snap
index 76bfe8c87..ebd38bc03 100644
--- a/tests/snapshots/integration__integration_tests__post_start_commands__post_create_failing_command.snap
+++ b/tests/snapshots/integration__integration_tests__post_start_commands__post_create_failing_command.snap
@@ -13,7 +13,7 @@ info:
GIT_CONFIG_GLOBAL: /dev/null
GIT_CONFIG_SYSTEM: /dev/null
GIT_EDITOR: ""
- HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpqHEqBw
+ HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpE6TWZJ
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1704067200"
@@ -27,5 +27,6 @@ exit_code: 0
To enable automatic cd, run: wt configure-shell
----- stderr -----
-πŸ”„ Executing (post-create): exit 1
+πŸ”„ Executing (post-create):
+  exit 1
🟑 Command cmd failed: Command 'exit 1' failed with exit code 1
diff --git a/tests/snapshots/integration__integration_tests__post_start_commands__post_create_multiple_commands_array.snap b/tests/snapshots/integration__integration_tests__post_start_commands__post_create_multiple_commands_array.snap
index af85df91b..85f131e6f 100644
--- a/tests/snapshots/integration__integration_tests__post_start_commands__post_create_multiple_commands_array.snap
+++ b/tests/snapshots/integration__integration_tests__post_start_commands__post_create_multiple_commands_array.snap
@@ -13,7 +13,7 @@ info:
GIT_CONFIG_GLOBAL: /dev/null
GIT_CONFIG_SYSTEM: /dev/null
GIT_EDITOR: ""
- HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpdXUI1S
+ HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpiQZs3j
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1704067200"
@@ -29,5 +29,7 @@ Second
To enable automatic cd, run: wt configure-shell
----- stderr -----
-πŸ”„ Executing (post-create): echo 'First'
-πŸ”„ Executing (post-create): echo 'Second'
+πŸ”„ Executing (post-create):
+  echo 'First'
+πŸ”„ Executing (post-create):
+  echo 'Second'
diff --git a/tests/snapshots/integration__integration_tests__post_start_commands__post_create_named_commands.snap b/tests/snapshots/integration__integration_tests__post_start_commands__post_create_named_commands.snap
index c6207519e..f530af483 100644
--- a/tests/snapshots/integration__integration_tests__post_start_commands__post_create_named_commands.snap
+++ b/tests/snapshots/integration__integration_tests__post_start_commands__post_create_named_commands.snap
@@ -13,7 +13,7 @@ info:
GIT_CONFIG_GLOBAL: /dev/null
GIT_CONFIG_SYSTEM: /dev/null
GIT_EDITOR: ""
- HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpdoot33
+ HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpGPHO4z
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1704067200"
@@ -29,5 +29,7 @@ Running setup
To enable automatic cd, run: wt configure-shell
----- stderr -----
-πŸ”„ Executing (post-create): echo 'Installing deps'
-πŸ”„ Executing (post-create): echo 'Running setup'
+πŸ”„ Executing (post-create):
+  echo 'Installing deps'
+πŸ”„ Executing (post-create):
+  echo 'Running setup'
diff --git a/tests/snapshots/integration__integration_tests__post_start_commands__post_create_single_command.snap b/tests/snapshots/integration__integration_tests__post_start_commands__post_create_single_command.snap
index 82118296e..158ddb79b 100644
--- a/tests/snapshots/integration__integration_tests__post_start_commands__post_create_single_command.snap
+++ b/tests/snapshots/integration__integration_tests__post_start_commands__post_create_single_command.snap
@@ -13,7 +13,7 @@ info:
GIT_CONFIG_GLOBAL: /dev/null
GIT_CONFIG_SYSTEM: /dev/null
GIT_EDITOR: ""
- HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpK8piSe
+ HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpN3QRin
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1704067200"
@@ -28,4 +28,5 @@ Setup complete
To enable automatic cd, run: wt configure-shell
----- stderr -----
-πŸ”„ Executing (post-create): echo 'Setup complete'
+πŸ”„ Executing (post-create):
+  echo 'Setup complete'
diff --git a/tests/snapshots/integration__integration_tests__post_start_commands__post_create_template_expansion.snap b/tests/snapshots/integration__integration_tests__post_start_commands__post_create_template_expansion.snap
index b7da2214c..caee0cbc9 100644
--- a/tests/snapshots/integration__integration_tests__post_start_commands__post_create_template_expansion.snap
+++ b/tests/snapshots/integration__integration_tests__post_start_commands__post_create_template_expansion.snap
@@ -13,7 +13,7 @@ info:
GIT_CONFIG_GLOBAL: /dev/null
GIT_CONFIG_SYSTEM: /dev/null
GIT_EDITOR: ""
- HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpB5F27p
+ HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpBf74y9
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1704067200"
@@ -27,7 +27,11 @@ exit_code: 0
To enable automatic cd, run: wt configure-shell
----- stderr -----
-πŸ”„ Executing (post-create): echo 'Repo: main' > info.txt
-πŸ”„ Executing (post-create): echo 'Branch: feature-test' >> info.txt
-πŸ”„ Executing (post-create): echo 'Worktree: [REPO].feature-test' >> info.txt
-πŸ”„ Executing (post-create): echo 'Root: [REPO]' >> info.txt
+πŸ”„ Executing (post-create):
+  echo 'Repo: main' > info.txt
+πŸ”„ Executing (post-create):
+  echo 'Branch: feature-test' >> info.txt
+πŸ”„ Executing (post-create):
+  echo 'Worktree: [REPO].feature-test' >> info.txt
+πŸ”„ Executing (post-create):
+  echo 'Root: [REPO]' >> info.txt