Skip to content

Commit a5ffd10

Browse files
committed
merge main
2 parents 244cbbc + 3aa06eb commit a5ffd10

File tree

8 files changed

+417
-100
lines changed

8 files changed

+417
-100
lines changed

Cargo.lock

Lines changed: 23 additions & 54 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/chat-cli/src/cli/chat/input_source.rs

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,33 @@ mod inner {
3131
}
3232
}
3333

34+
impl Drop for InputSource {
35+
fn drop(&mut self) {
36+
self.save_history().unwrap();
37+
}
38+
}
3439
impl InputSource {
3540
pub fn new(os: &Os, sender: PromptQuerySender, receiver: PromptQueryResponseReceiver) -> Result<Self> {
3641
Ok(Self(inner::Inner::Readline(rl(os, sender, receiver)?)))
3742
}
3843

44+
/// Save history to file
45+
pub fn save_history(&mut self) -> Result<()> {
46+
if let inner::Inner::Readline(rl) = &mut self.0 {
47+
if let Some(helper) = rl.helper() {
48+
let history_path = helper.get_history_path();
49+
50+
// Create directory if it doesn't exist
51+
if let Some(parent) = history_path.parent() {
52+
std::fs::create_dir_all(parent)?;
53+
}
54+
55+
rl.append_history(&history_path)?;
56+
}
57+
}
58+
Ok(())
59+
}
60+
3961
#[cfg(unix)]
4062
pub fn put_skim_command_selector(
4163
&mut self,
@@ -78,12 +100,9 @@ impl InputSource {
78100
let curr_line = rl.readline(prompt);
79101
match curr_line {
80102
Ok(line) => {
81-
let _ = rl.add_history_entry(line.as_str());
82-
83-
if let Some(helper) = rl.helper_mut() {
84-
helper.update_hinter_history(&line);
103+
if Self::should_append_history(&line) {
104+
let _ = rl.add_history_entry(line.as_str());
85105
}
86-
87106
Ok(Some(line))
88107
},
89108
Err(ReadlineError::Interrupted | ReadlineError::Eof) => Ok(None),
@@ -97,6 +116,18 @@ impl InputSource {
97116
}
98117
}
99118

119+
fn should_append_history(line: &str) -> bool {
120+
let trimmed = line.trim().to_lowercase();
121+
if trimmed.is_empty() {
122+
return false;
123+
}
124+
125+
if matches!(trimmed.as_str(), "y" | "n" | "t") {
126+
return false;
127+
}
128+
true
129+
}
130+
100131
// We're keeping this method for potential future use
101132
#[allow(dead_code)]
102133
pub fn set_buffer(&mut self, content: &str) {

0 commit comments

Comments
 (0)