Skip to content

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

feat: Differentiate hint types for better UX

Maximilian Roos3f86c7b23a19
diff --git a/src/output/directive.rs b/src/output/directive.rs
index ef0f13d64..d050419d7 100644
--- a/src/output/directive.rs
+++ b/src/output/directive.rs
@@ -37,7 +37,7 @@
use std::io::{self, Write};
use std::path::Path;
-use worktrunk::styling::{INFO_EMOJI, PROGRESS_EMOJI, SUCCESS_EMOJI, WARNING_EMOJI};
+use worktrunk::styling::{HINT_EMOJI, INFO_EMOJI, PROGRESS_EMOJI, SUCCESS_EMOJI, WARNING_EMOJI};
/// Directive output mode for shell integration
///
@@ -63,8 +63,14 @@ impl DirectiveOutput {
io::stderr().flush()
}
- pub fn hint(&mut self, _message: String) -> io::Result<()> {
- // Hints are only for interactive mode - suppress in directive mode
+ pub fn hint(&mut self, message: String) -> io::Result<()> {
+ // Hint messages go to stderr for real-time streaming (not buffered by shell wrapper)
+ writeln!(io::stderr(), "{HINT_EMOJI} {message}")?;
+ io::stderr().flush()
+ }
+
+ pub fn shell_integration_hint(&mut self, _message: String) -> io::Result<()> {
+ // Shell integration hints are suppressed in directive mode
// When users run through shell wrapper, they already have integration
Ok(())
}
diff --git a/src/output/global.rs b/src/output/global.rs
index 7b97d32f9..2a18c5b2a 100644
--- a/src/output/global.rs
+++ b/src/output/global.rs
@@ -82,10 +82,9 @@ pub fn progress(message: impl Into<String>) -> io::Result<()> {
})
}
-/// Emit a hint message (only shown in interactive mode)
+/// Display a hint message
///
-/// Hints are suggestions for interactive users, like "To enable automatic cd, run: wt config shell"
-/// They are shown in interactive mode but suppressed in directive mode (where they don't apply).
+/// Hints are suggestions for users, like "Backup created @ \<sha\>" or "Using fallback commit message"
pub fn hint(message: impl Into<String>) -> io::Result<()> {
OUTPUT_CONTEXT.with(|ctx| {
let msg = message.into();
@@ -96,6 +95,20 @@ pub fn hint(message: impl Into<String>) -> io::Result<()> {
})
}
+/// Display a shell integration hint (suppressed in directive mode)
+///
+/// Shell integration hints like "To enable automatic cd, run: wt config shell" are only
+/// shown in interactive mode since directive mode users already have shell integration
+pub fn shell_integration_hint(message: impl Into<String>) -> io::Result<()> {
+ OUTPUT_CONTEXT.with(|ctx| {
+ let msg = message.into();
+ match &mut *ctx.borrow_mut() {
+ OutputHandler::Interactive(i) => i.shell_integration_hint(msg),
+ OutputHandler::Directive(d) => d.shell_integration_hint(msg),
+ }
+ })
+}
+
/// Emit an info message
///
/// Info messages are neutral status updates like "⚪ No changes detected"
diff --git a/src/output/handlers.rs b/src/output/handlers.rs
index cbbb63628..e24548511 100644
--- a/src/output/handlers.rs
+++ b/src/output/handlers.rs
@@ -111,7 +111,7 @@ pub fn handle_switch_output(
// If no execute command provided: show shell integration hint
// (suppressed in directive mode since user already has integration)
if !has_execute_command {
- super::hint(shell_integration_hint())?;
+ super::shell_integration_hint(shell_integration_hint())?;
}
// Flush output (important for directive mode)
diff --git a/src/output/interactive.rs b/src/output/interactive.rs
index d50ad385c..e8c0c01c2 100644
--- a/src/output/interactive.rs
+++ b/src/output/interactive.rs
@@ -43,6 +43,13 @@ impl InteractiveOutput {
Ok(())
}
+ pub fn shell_integration_hint(&mut self, message: String) -> io::Result<()> {
+ // Shell integration hints work the same as regular hints in interactive mode
+ println!("{HINT_EMOJI} {message}");
+ stdout().flush()?;
+ Ok(())
+ }
+
pub fn info(&mut self, message: String) -> io::Result<()> {
// Info messages automatically include the ⚪ emoji
println!("{INFO_EMOJI} {message}");
diff --git a/src/output/mod.rs b/src/output/mod.rs
index dc0170f30..cc2ab2c30 100644
--- a/src/output/mod.rs
+++ b/src/output/mod.rs
@@ -63,7 +63,7 @@ pub mod interactive;
// Re-export the public API
pub use global::{
OutputMode, change_directory, error, execute, flush, flush_for_stderr_prompt, gutter, hint,
- info, initialize, progress, success, terminate_output, warning,
+ info, initialize, progress, shell_integration_hint, success, terminate_output, warning,
};
// blank_line is only used by select command which is Unix-only