Skip to content

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

Simplify UTF-8 truncation and command suggestion handling (#4552)

Maximilian Roos43af4828d923
diff --git a/src/completion.rs b/src/completion.rs
index ff91eb57b..0a98750d3 100644
--- a/src/completion.rs
+++ b/src/completion.rs
@@ -792,12 +792,7 @@ fn truncate_template(template: &str) -> &str {
let s = template.trim();
let first_line = s.lines().next().unwrap_or(s);
if first_line.len() > 60 {
- // Find the last char boundary at or before byte 57
- let mut end = 57;
- while end > 0 && !first_line.is_char_boundary(end) {
- end -= 1;
- }
- &first_line[..end]
+ &first_line[..first_line.floor_char_boundary(57)]
} else {
first_line
}
diff --git a/src/llm.rs b/src/llm.rs
index 8c3fd0908..9963bbc19 100644
--- a/src/llm.rs
+++ b/src/llm.rs
@@ -243,10 +243,7 @@ fn truncate_line(line: &str) -> Cow<'_, str> {
if line.len() <= MAX_LINE_LEN {
return Cow::Borrowed(line);
}
- let mut end = MAX_LINE_LEN;
- while !line.is_char_boundary(end) {
- end -= 1;
- }
+ let end = line.floor_char_boundary(MAX_LINE_LEN);
Cow::Owned(format!("{}... (line truncated)", &line[..end]))
}
diff --git a/src/styling/suggest.rs b/src/styling/suggest.rs
index c8520b594..fa0afa9f4 100644
--- a/src/styling/suggest.rs
+++ b/src/styling/suggest.rs
@@ -99,13 +99,11 @@ fn format_command(
// so they're always parsed as flags, not positional arguments.
parts.extend(flags.iter().map(|s| s.to_string()));
- // Check if any arg starts with dash (needs -- separator)
- let needs_separator = args.iter().any(|arg| arg.starts_with('-'));
let mut separator_inserted = false;
for arg in args {
// Insert -- before the first dash-prefixed arg
- if needs_separator && arg.starts_with('-') && !separator_inserted {
+ if arg.starts_with('-') && !separator_inserted {
parts.push("--".to_string());
separator_inserted = true;
}