Skip to content

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

Add prompt_message() formatting function (#858)

Maximilian Roosbf3461aa4c91
diff --git a/src/commands/command_approval.rs b/src/commands/command_approval.rs
index bf2e8262f..ed2827375 100644
--- a/src/commands/command_approval.rs
+++ b/src/commands/command_approval.rs
@@ -25,8 +25,8 @@ use color_print::cformat;
use worktrunk::config::UserConfig;
use worktrunk::git::{GitError, HookType};
use worktrunk::styling::{
- INFO_SYMBOL, PROMPT_SYMBOL, WARNING_SYMBOL, eprint, eprintln, format_bash_with_gutter,
- hint_message, stderr, warning_message,
+ INFO_SYMBOL, WARNING_SYMBOL, eprint, eprintln, format_bash_with_gutter, hint_message,
+ prompt_message, stderr, warning_message,
};
use super::hook_filter::{HookSource, ParsedFilter};
@@ -148,8 +148,8 @@ fn prompt_for_batch_approval(commands: &[&HookCommand], project_id: &str) -> any
stderr().flush()?;
eprint!(
- "{}",
- cformat!("{PROMPT_SYMBOL} Allow and remember? <bold>[y/N]</> ")
+ "{} ",
+ prompt_message(cformat!("Allow and remember? <bold>[y/N]</>"))
);
stderr().flush()?;
diff --git a/src/commands/configure_shell.rs b/src/commands/configure_shell.rs
index 56f3c1a28..f6e0fce68 100644
--- a/src/commands/configure_shell.rs
+++ b/src/commands/configure_shell.rs
@@ -7,8 +7,8 @@ use anstyle::Style;
use worktrunk::path::format_path_for_display;
use worktrunk::shell::{self, Shell};
use worktrunk::styling::{
- INFO_SYMBOL, PROMPT_SYMBOL, SUCCESS_SYMBOL, eprint, eprintln, format_bash_with_gutter,
- format_with_gutter, warning_message,
+ INFO_SYMBOL, SUCCESS_SYMBOL, eprint, eprintln, format_bash_with_gutter, format_with_gutter,
+ prompt_message, warning_message,
};
pub struct ConfigureResult {
@@ -726,8 +726,8 @@ pub fn prompt_for_install(
) -> Result<bool, String> {
loop {
eprint!(
- "{}",
- color_print::cformat!("{} {} <bold>[y/N/?]</> ", PROMPT_SYMBOL, prompt_text)
+ "{} ",
+ prompt_message(color_print::cformat!("{prompt_text} <bold>[y/N/?]</>"))
);
io::stderr().flush().map_err(|e| e.to_string())?;
@@ -758,8 +758,10 @@ pub fn prompt_for_install(
/// Prompt user for yes/no confirmation (simple [y/N] prompt)
fn prompt_yes_no() -> Result<bool, String> {
- let bold = Style::new().bold();
- eprint!("{PROMPT_SYMBOL} Proceed? {bold}[y/N]{bold:#} ");
+ eprint!(
+ "{} ",
+ prompt_message(color_print::cformat!("Proceed? <bold>[y/N]</>"))
+ );
io::stderr().flush().map_err(|e| e.to_string())?;
let mut input = String::new();
@@ -1237,7 +1239,7 @@ pub fn handle_show_theme() {
// Prompt
eprintln!("{}", info_message("Prompt formatting:"));
- eprintln!("{PROMPT_SYMBOL} Proceed? [y/N] ");
+ eprintln!("{} ", prompt_message("Proceed? [y/N]"));
}
#[cfg(test)]
diff --git a/src/styling/constants.rs b/src/styling/constants.rs
index 660f3176f..a6513ee40 100644
--- a/src/styling/constants.rs
+++ b/src/styling/constants.rs
@@ -205,6 +205,11 @@ pub fn info_message(content: impl AsRef<str>) -> FormattedMessage {
FormattedMessage(format!("{INFO_SYMBOL} {}", content.as_ref()))
}
+/// Format a prompt message with symbol and cyan styling
+pub fn prompt_message(content: impl AsRef<str>) -> FormattedMessage {
+ FormattedMessage(cformat!("{PROMPT_SYMBOL} <cyan>{}</>", content.as_ref()))
+}
+
/// Format a section heading (cyan uppercase text, no emoji)
///
/// Used for organizing output into distinct sections. Headings can have
@@ -331,6 +336,13 @@ mod tests {
assert!(msg.as_str().contains("5 items found"));
}
+ #[test]
+ fn test_prompt_message() {
+ let msg = prompt_message("Continue?");
+ assert!(msg.as_str().contains(PROMPT_SYMBOL));
+ assert!(msg.as_str().contains("Continue?"));
+ }
+
// ============================================================================
// format_heading Tests
// ============================================================================
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__config_show_theme__show_theme.snap b/tests/integration_tests/snapshots/integration__integration_tests__config_show_theme__show_theme.snap
index b1d2383d1..6f9a247c5 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__config_show_theme__show_theme.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__config_show_theme__show_theme.snap
@@ -10,6 +10,8 @@ info:
CLICOLOR_FORCE: "1"
COLUMNS: "500"
GIT_EDITOR: ""
+ LANG: C
+ LC_ALL: C
RUST_LOG: warn
SHELL: ""
TERM: alacritty
@@ -38,4 +40,4 @@ exit_code: 0
  eval "$(wt config shell init bash)"
○ Prompt formatting:
-❯ Proceed? [y/N]
+❯ Proceed? [y/N]
diff --git a/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_accept.snap b/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_accept.snap
index 3ccb38116..9201bd304 100644
--- a/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_accept.snap
+++ b/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_accept.snap
@@ -8,7 +8,7 @@ y
○ post-create:
  echo 'test command'
-❯ Allow and remember? [y/N]
+❯ Allow and remember? [y/N]
◎ Running post-create project hook @ _REPO_.test-approve:
  echo 'test command'
test command
diff --git a/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_decline.snap b/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_decline.snap
index 65b8247db..8b2848d52 100644
--- a/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_decline.snap
+++ b/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_decline.snap
@@ -8,7 +8,7 @@ n
○ post-create:
  echo 'test command'
-❯ Allow and remember? [y/N]
+❯ Allow and remember? [y/N]
○ Commands declined, continuing worktree creation
✓ Created branch test-decline from main and worktree @ _REPO_.test-decline
↳ To customize worktree locations, run wt config create
diff --git a/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_mixed_approved_unapproved_accept.snap b/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_mixed_approved_unapproved_accept.snap
index daa904bc3..c3ce153a7 100644
--- a/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_mixed_approved_unapproved_accept.snap
+++ b/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_mixed_approved_unapproved_accept.snap
@@ -10,7 +10,7 @@ y
  echo 'First command'
○ post-create third:
  echo 'Third command'
-❯ Allow and remember? [y/N]
+❯ Allow and remember? [y/N]
◎ Running post-create project:first @ _REPO_.test-mixed-accept:
  echo 'First command'
First command
diff --git a/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_mixed_approved_unapproved_decline.snap b/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_mixed_approved_unapproved_decline.snap
index f032eb5cf..9d72c2670 100644
--- a/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_mixed_approved_unapproved_decline.snap
+++ b/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_mixed_approved_unapproved_decline.snap
@@ -10,7 +10,7 @@ n
  echo 'First command'
○ post-create third:
  echo 'Third command'
-❯ Allow and remember? [y/N]
+❯ Allow and remember? [y/N]
○ Commands declined, continuing worktree creation
✓ Created branch test-mixed-decline from main and worktree @ _REPO_.test-mixed-decline
↳ To customize worktree locations, run wt config create
diff --git a/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_multiple_commands.snap b/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_multiple_commands.snap
index 570c7cc82..1edd21aef 100644
--- a/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_multiple_commands.snap
+++ b/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_multiple_commands.snap
@@ -12,7 +12,7 @@ y
  echo 'Second command'
○ post-create third:
  echo 'Third command'
-❯ Allow and remember? [y/N]
+❯ Allow and remember? [y/N]
◎ Running post-create project:first @ _REPO_.test-multi:
  echo 'First command'
First command
diff --git a/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_named_commands.snap b/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_named_commands.snap
index 124072532..990445f90 100644
--- a/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_named_commands.snap
+++ b/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_named_commands.snap
@@ -12,7 +12,7 @@ y
  echo 'Building project...'
○ post-create test:
  echo 'Running tests...'
-❯ Allow and remember? [y/N]
+❯ Allow and remember? [y/N]
◎ Running post-create project:install @ _REPO_.test-named:
  echo 'Installing dependencies...'
Installing dependencies...
diff --git a/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_permission_error.snap b/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_permission_error.snap
index a6da2b6ba..23b8eec7c 100644
--- a/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_permission_error.snap
+++ b/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_permission_error.snap
@@ -8,7 +8,7 @@ y
○ post-create:
  echo 'test command'
-❯ Allow and remember? [y/N]
+❯ Allow and remember? [y/N]
▲ Failed to save command approval: Failed to write config file: Permission denied (os error 13)
↳ Approval will be requested again next time.
◎ Running post-create project hook @ _REPO_.test-permission:
diff --git a/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_remove_decline.snap b/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_remove_decline.snap
index 380582b6c..d918305c5 100644
--- a/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_remove_decline.snap
+++ b/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_remove_decline.snap
@@ -8,6 +8,6 @@ n
○ pre-remove:
  echo 'pre-remove hook'
-❯ Allow and remember? [y/N]
+❯ Allow and remember? [y/N]
○ Commands declined, continuing removal
◎ Removing to-remove worktree & branch in background (ancestor of main, ⊂)
diff --git a/tests/snapshots/integration__integration_tests__shell_integration_prompt__pty_tests__prompt_accept.snap b/tests/snapshots/integration__integration_tests__shell_integration_prompt__pty_tests__prompt_accept.snap
index 6d50125ef..c288dd2de 100644
--- a/tests/snapshots/integration__integration_tests__shell_integration_prompt__pty_tests__prompt_accept.snap
+++ b/tests/snapshots/integration__integration_tests__shell_integration_prompt__pty_tests__prompt_accept.snap
@@ -8,7 +8,7 @@ y
↳ To customize worktree locations, run wt config create
▲ Cannot change directory — shell integration not installed
-❯ Install shell integration? [y/N/?]
+❯ Install shell integration? [y/N/?]
✓ Added shell extension & completions for bash @ ~/.bashrc
↳ Skipped zsh; ~/.zshrc not found
↳ Skipped fish; ~/.config/fish/functions not found
diff --git a/tests/snapshots/integration__integration_tests__shell_integration_prompt__pty_tests__prompt_decline.snap b/tests/snapshots/integration__integration_tests__shell_integration_prompt__pty_tests__prompt_decline.snap
index 437bb1f52..dd5efaf63 100644
--- a/tests/snapshots/integration__integration_tests__shell_integration_prompt__pty_tests__prompt_decline.snap
+++ b/tests/snapshots/integration__integration_tests__shell_integration_prompt__pty_tests__prompt_decline.snap
@@ -8,5 +8,5 @@ n
↳ To customize worktree locations, run wt config create
▲ Cannot change directory — shell integration not installed
-❯ Install shell integration? [y/N/?]
+❯ Install shell integration? [y/N/?]
↳ To enable automatic cd, run wt config shell install
diff --git a/tests/snapshots/integration__integration_tests__shell_integration_prompt__pty_tests__prompt_preview_decline.snap b/tests/snapshots/integration__integration_tests__shell_integration_prompt__pty_tests__prompt_preview_decline.snap
index 3ce347e22..8826fd7d6 100644
--- a/tests/snapshots/integration__integration_tests__shell_integration_prompt__pty_tests__prompt_preview_decline.snap
+++ b/tests/snapshots/integration__integration_tests__shell_integration_prompt__pty_tests__prompt_preview_decline.snap
@@ -9,9 +9,9 @@ n
↳ To customize worktree locations, run wt config create
▲ Cannot change directory — shell integration not installed
-❯ Install shell integration? [y/N/?]
+❯ Install shell integration? [y/N/?]
○ Will add shell extension & completions for bash @ ~/.bashrc
  if command -v wt >/dev/null 2>&1; then eval "$(command wt config shell init bash)"; fi
-❯ Install shell integration? [y/N/?]
+❯ Install shell integration? [y/N/?]
↳ To enable automatic cd, run wt config shell install