fix(cli): use '> ' as readline prompt when project active

Previously used empty string as readline prompt after printing colored
prefix, which caused cursor positioning issues (large gap between
project name and cursor).

Now the prefix contains 'butler | finances' (colored) and readline
gets '> ' as its prompt, so cursor appears immediately after '> '.
This commit is contained in:
Dhanji R. Prasanna
2026-01-22 10:18:15 +05:30
parent 28dd60d4fc
commit 4d9399f737

View File

@@ -38,15 +38,15 @@ pub fn build_prompt(in_multiline: bool, agent_name: Option<&str>, active_project
.file_name()
.and_then(|n| n.to_str())
.unwrap_or("project");
// Return colored prefix to print, and plain prompt for readline
// Return colored prefix (without "> "), and "> " as the readline prompt
let prefix = format!(
"{} {}| {}>{} ",
"{} {}| {}{}",
base_name,
SetForegroundColor(Color::Blue),
project_name,
ResetColor
);
(prefix, String::new())
(prefix, "> ".to_string())
} else {
(String::new(), format!("{}> ", base_name))
}
@@ -377,11 +377,11 @@ mod tests {
fn test_build_prompt_with_project() {
let project = Some(create_test_project("myapp"));
let (prefix, prompt) = build_prompt(false, None, &project);
// Project name should be in the colored prefix, prompt should be empty
// Project name should be in the colored prefix, prompt should be "> "
assert!(prefix.contains("g3"));
assert!(prefix.contains("myapp"));
assert!(prefix.contains("|"));
assert!(prompt.is_empty());
assert_eq!(prompt, "> ");
}
#[test]
@@ -392,7 +392,7 @@ mod tests {
assert!(prefix.contains("carmack"));
assert!(prefix.contains("myapp"));
assert!(prefix.contains("|"));
assert!(prompt.is_empty());
assert_eq!(prompt, "> ");
}
#[test]
@@ -418,7 +418,7 @@ mod tests {
});
let (prefix, prompt) = build_prompt(false, None, &project);
assert!(prefix.contains("awesome-app"));
assert!(prompt.is_empty());
assert_eq!(prompt, "> ");
}
}