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.rsindex 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) -> anystderr().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.rsindex 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() {// Prompteprintln!("{}", 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.rsindex 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.snapindex 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: CRUST_LOG: warnSHELL: ""TERM: alacritty@@ -38,4 +40,4 @@ exit_code: 0[107m [0m [2m[0m[2m[34meval[0m[2m [0m[2m[32m"$([0m[2m[34mwt[0m[2m config shell init bash)"[0m[2m[0m[2m○[22m Prompt formatting:-[36m❯[39m Proceed? [y/N]+[36m❯[39m [36mProceed? [y/N][39mdiff --git a/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_accept.snap b/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_accept.snapindex 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[2m○[22m post-create:[107m [0m [2m[0m[2m[34mecho[0m[2m [0m[2m[32m'test command'[0m[2m-[36m❯[39m Allow and remember? [1m[y/N][22m+[36m❯[39m [36mAllow and remember? [1m[y/N][22m[39m[36m◎[39m [36mRunning post-create project hook @ [1m_REPO_.test-approve[22m:[39m[107m [0m [2m[0m[2m[34mecho[0m[2m [0m[2m[32m'test command'[0m[2mtest commanddiff --git a/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_decline.snap b/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_decline.snapindex 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[2m○[22m post-create:[107m [0m [2m[0m[2m[34mecho[0m[2m [0m[2m[32m'test command'[0m[2m-[36m❯[39m Allow and remember? [1m[y/N][22m+[36m❯[39m [36mAllow and remember? [1m[y/N][22m[39m[2m○[22m Commands declined, continuing worktree creation[32m✓[39m [32mCreated branch [1mtest-decline[22m from [1mmain[22m and worktree @ [1m_REPO_.test-decline[22m[39m[2m↳[22m [2mTo customize worktree locations, run [90mwt config create[39m[22mdiff --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.snapindex 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[107m [0m [2m[0m[2m[34mecho[0m[2m [0m[2m[32m'First command'[0m[2m[2m○[22m post-create [1mthird[22m:[107m [0m [2m[0m[2m[34mecho[0m[2m [0m[2m[32m'Third command'[0m[2m-[36m❯[39m Allow and remember? [1m[y/N][22m+[36m❯[39m [36mAllow and remember? [1m[y/N][22m[39m[36m◎[39m [36mRunning post-create [1mproject:first[22m @ [1m_REPO_.test-mixed-accept[22m:[39m[107m [0m [2m[0m[2m[34mecho[0m[2m [0m[2m[32m'First command'[0m[2mFirst commanddiff --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.snapindex 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[107m [0m [2m[0m[2m[34mecho[0m[2m [0m[2m[32m'First command'[0m[2m[2m○[22m post-create [1mthird[22m:[107m [0m [2m[0m[2m[34mecho[0m[2m [0m[2m[32m'Third command'[0m[2m-[36m❯[39m Allow and remember? [1m[y/N][22m+[36m❯[39m [36mAllow and remember? [1m[y/N][22m[39m[2m○[22m Commands declined, continuing worktree creation[32m✓[39m [32mCreated branch [1mtest-mixed-decline[22m from [1mmain[22m and worktree @ [1m_REPO_.test-mixed-decline[22m[39m[2m↳[22m [2mTo customize worktree locations, run [90mwt config create[39m[22mdiff --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.snapindex 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[107m [0m [2m[0m[2m[34mecho[0m[2m [0m[2m[32m'Second command'[0m[2m[2m○[22m post-create [1mthird[22m:[107m [0m [2m[0m[2m[34mecho[0m[2m [0m[2m[32m'Third command'[0m[2m-[36m❯[39m Allow and remember? [1m[y/N][22m+[36m❯[39m [36mAllow and remember? [1m[y/N][22m[39m[36m◎[39m [36mRunning post-create [1mproject:first[22m @ [1m_REPO_.test-multi[22m:[39m[107m [0m [2m[0m[2m[34mecho[0m[2m [0m[2m[32m'First command'[0m[2mFirst commanddiff --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.snapindex 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[107m [0m [2m[0m[2m[34mecho[0m[2m [0m[2m[32m'Building project...'[0m[2m[2m○[22m post-create [1mtest[22m:[107m [0m [2m[0m[2m[34mecho[0m[2m [0m[2m[32m'Running tests...'[0m[2m-[36m❯[39m Allow and remember? [1m[y/N][22m+[36m❯[39m [36mAllow and remember? [1m[y/N][22m[39m[36m◎[39m [36mRunning post-create [1mproject:install[22m @ [1m_REPO_.test-named[22m:[39m[107m [0m [2m[0m[2m[34mecho[0m[2m [0m[2m[32m'Installing dependencies...'[0m[2mInstalling 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.snapindex 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[2m○[22m post-create:[107m [0m [2m[0m[2m[34mecho[0m[2m [0m[2m[32m'test command'[0m[2m-[36m❯[39m Allow and remember? [1m[y/N][22m+[36m❯[39m [36mAllow and remember? [1m[y/N][22m[39m[33m▲[39m [33mFailed to save command approval: Failed to write config file: Permission denied (os error 13)[39m[2m↳[22m [2mApproval will be requested again next time.[22m[36m◎[39m [36mRunning post-create project hook @ [1m_REPO_.test-permission[22m:[39mdiff --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.snapindex 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[2m○[22m pre-remove:[107m [0m [2m[0m[2m[34mecho[0m[2m [0m[2m[32m'pre-remove hook'[0m[2m-[36m❯[39m Allow and remember? [1m[y/N][22m+[36m❯[39m [36mAllow and remember? [1m[y/N][22m[39m[2m○[22m Commands declined, continuing removal[36m◎ Removing [1mto-remove[22m worktree & branch in background (ancestor of [1mmain[22m,[39m [2m⊂[22m[36m)[39mdiff --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.snapindex 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[2m↳[22m [2mTo customize worktree locations, run [90mwt config create[39m[22m[33m▲[39m [33mCannot change directory — shell integration not installed[39m-[36m❯[39m Install shell integration? [1m[y/N/?][22m+[36m❯[39m [36mInstall shell integration? [1m[y/N/?][22m[39m[32m✓[39m [32mAdded shell extension & completions for [1mbash[22m @ [1m~/.bashrc[22m[39m[2m↳[22m [2mSkipped [90mzsh[39m; [90m~/.zshrc[39m not found[22m[2m↳[22m [2mSkipped [90mfish[39m; [90m~/.config/fish/functions[39m not found[22mdiff --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.snapindex 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[2m↳[22m [2mTo customize worktree locations, run [90mwt config create[39m[22m[33m▲[39m [33mCannot change directory — shell integration not installed[39m-[36m❯[39m Install shell integration? [1m[y/N/?][22m+[36m❯[39m [36mInstall shell integration? [1m[y/N/?][22m[39m[2m↳[22m [2mTo enable automatic cd, run [90mwt config shell install[39m[22mdiff --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.snapindex 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[2m↳[22m [2mTo customize worktree locations, run [90mwt config create[39m[22m[33m▲[39m [33mCannot change directory — shell integration not installed[39m-[36m❯[39m Install shell integration? [1m[y/N/?][22m+[36m❯[39m [36mInstall shell integration? [1m[y/N/?][22m[39m[2m○[22m Will add shell extension & completions for [1mbash[0m @ [1m~/.bashrc[107m [0m [2m[0m[2m[35mif[0m[2m [0m[2m[34mcommand[0m[2m [0m[2m[36m-v[0m[2m wt [0m[2m[36m>[0m[2m/dev/null [0m[2m[33m2[0m[2m>&1; [0m[2m[35mthen[0m[2m [0m[2m[34meval[0m[2m [0m[2m[32m"$([0m[2m[34mcommand[0m[2m wt config shell init bash)"[0m[2m; [0m[2m[35mfi[0m[2m-[36m❯[39m Install shell integration? [1m[y/N/?][22m+[36m❯[39m [36mInstall shell integration? [1m[y/N/?][22m[39m[2m↳[22m [2mTo enable automatic cd, run [90mwt config shell install[39m[22m