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.rsindex 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.rsindex 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.rsindex 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.snapindex 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/nullGIT_CONFIG_SYSTEM: /dev/nullGIT_EDITOR: ""- HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmp2NgX3P+ HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpDBx8wCLANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1704067200"@@ -27,6 +27,7 @@ exit_code: 0To enable automatic cd, run: wt configure-shell----- stderr ------π [36mExecuting (post-create): echo 'Setup done' > setup.txt[0m+π [36mExecuting (post-create):[0m+[40m [0m echo 'Setup done' > setup.txtπ [36mStarting (background): sleep 0.5 && echo 'Server running' > server.txt[0m[2mβ Logs: .git/wt-logs/post-start-[NAME]-[TIMESTAMP].log[0mdiff --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.snapindex 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/nullGIT_CONFIG_SYSTEM: /dev/nullGIT_EDITOR: ""- HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpqHEqBw+ HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpE6TWZJLANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1704067200"@@ -27,5 +27,6 @@ exit_code: 0To enable automatic cd, run: wt configure-shell----- stderr ------π [36mExecuting (post-create): exit 1[0m+π [36mExecuting (post-create):[0m+[40m [0m exit 1π‘ [33mCommand [1m[33mcmd[0m failed: Command 'exit 1' failed with exit code 1[0mdiff --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.snapindex 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/nullGIT_CONFIG_SYSTEM: /dev/nullGIT_EDITOR: ""- HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpdXUI1S+ HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpiQZs3jLANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1704067200"@@ -29,5 +29,7 @@ SecondTo enable automatic cd, run: wt configure-shell----- stderr ------π [36mExecuting (post-create): echo 'First'[0m-π [36mExecuting (post-create): echo 'Second'[0m+π [36mExecuting (post-create):[0m+[40m [0m echo 'First'+π [36mExecuting (post-create):[0m+[40m [0m 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.snapindex 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/nullGIT_CONFIG_SYSTEM: /dev/nullGIT_EDITOR: ""- HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpdoot33+ HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpGPHO4zLANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1704067200"@@ -29,5 +29,7 @@ Running setupTo enable automatic cd, run: wt configure-shell----- stderr ------π [36mExecuting (post-create): echo 'Installing deps'[0m-π [36mExecuting (post-create): echo 'Running setup'[0m+π [36mExecuting (post-create):[0m+[40m [0m echo 'Installing deps'+π [36mExecuting (post-create):[0m+[40m [0m 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.snapindex 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/nullGIT_CONFIG_SYSTEM: /dev/nullGIT_EDITOR: ""- HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpK8piSe+ HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpN3QRinLANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1704067200"@@ -28,4 +28,5 @@ Setup completeTo enable automatic cd, run: wt configure-shell----- stderr ------π [36mExecuting (post-create): echo 'Setup complete'[0m+π [36mExecuting (post-create):[0m+[40m [0m 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.snapindex 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/nullGIT_CONFIG_SYSTEM: /dev/nullGIT_EDITOR: ""- HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpB5F27p+ HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpBf74y9LANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1704067200"@@ -27,7 +27,11 @@ exit_code: 0To enable automatic cd, run: wt configure-shell----- stderr ------π [36mExecuting (post-create): echo 'Repo: main' > info.txt[0m-π [36mExecuting (post-create): echo 'Branch: feature-test' >> info.txt[0m-π [36mExecuting (post-create): echo 'Worktree: [REPO].feature-test' >> info.txt[0m-π [36mExecuting (post-create): echo 'Root: [REPO]' >> info.txt[0m+π [36mExecuting (post-create):[0m+[40m [0m echo 'Repo: main' > info.txt+π [36mExecuting (post-create):[0m+[40m [0m echo 'Branch: feature-test' >> info.txt+π [36mExecuting (post-create):[0m+[40m [0m echo 'Worktree: [REPO].feature-test' >> info.txt+π [36mExecuting (post-create):[0m+[40m [0m echo 'Root: [REPO]' >> info.txt