Skip to content

Commit c39358c

Browse files
committed
restores (as much as possible) readline functionality
1 parent fab3fdf commit c39358c

File tree

3 files changed

+601
-14
lines changed

3 files changed

+601
-14
lines changed

crates/chat-cli-ui/src/conduit.rs

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::io::Write as _;
22
use std::marker::PhantomData;
3+
use std::path::PathBuf;
34

45
use crossterm::style::{
56
self,
@@ -10,10 +11,14 @@ use crossterm::{
1011
execute,
1112
queue,
1213
};
13-
use rustyline::DefaultEditor;
14+
use rustyline::EditMode;
1415
use tracing::error;
1516

16-
use crate::legacy_ui_util::ThemeSource;
17+
use crate::legacy_ui_util::{
18+
ThemeSource,
19+
generate_prompt,
20+
rl,
21+
};
1722
use crate::protocol::{
1823
Event,
1924
InputEvent,
@@ -67,10 +72,33 @@ impl ViewEnd {
6772
Interrupt,
6873
}
6974

70-
#[derive(Default, Debug)]
75+
#[derive(Clone, Debug)]
7176
struct PromptSignal {
7277
active_agent: Option<String>,
7378
trust_all: bool,
79+
is_in_tangent_mode: bool,
80+
available_prompts: Vec<String>,
81+
history_path: PathBuf,
82+
available_commands: Vec<String>,
83+
edit_mode: EditMode,
84+
history_hints_enabled: bool,
85+
usage_percentage: Option<f32>,
86+
}
87+
88+
impl Default for PromptSignal {
89+
fn default() -> Self {
90+
Self {
91+
active_agent: Default::default(),
92+
trust_all: Default::default(),
93+
available_prompts: Default::default(),
94+
is_in_tangent_mode: Default::default(),
95+
history_path: Default::default(),
96+
available_commands: Default::default(),
97+
history_hints_enabled: Default::default(),
98+
usage_percentage: Default::default(),
99+
edit_mode: EditMode::Emacs,
100+
}
101+
}
74102
}
75103

76104
#[derive(Default, Debug)]
@@ -233,17 +261,30 @@ impl ViewEnd {
233261
tokio::task::spawn_blocking(move || {
234262
while let Ok(prompt_signal) = prompt_signal_rx.recv() {
235263
let PromptSignal {
236-
active_agent: _,
237-
trust_all: _,
264+
active_agent,
265+
trust_all,
266+
available_prompts,
267+
history_path,
268+
available_commands,
269+
edit_mode,
270+
history_hints_enabled,
271+
is_in_tangent_mode,
272+
usage_percentage,
238273
} = prompt_signal;
239274

240-
// TODO: Actually utilize the info to spawn readline here
241-
let prompt = "> ";
242-
let mut rl = DefaultEditor::new().expect("Failed to spawn readline");
275+
let mut rl = rl(
276+
history_hints_enabled,
277+
edit_mode,
278+
history_path,
279+
available_commands,
280+
available_prompts,
281+
)
282+
.expect("Failed to spawn readline");
243283

244-
// std::thread::sleep(std::time::Duration::from_millis(5000));
284+
let prompt =
285+
generate_prompt(active_agent.as_deref(), trust_all, is_in_tangent_mode, usage_percentage);
245286

246-
match rl.readline(prompt) {
287+
match rl.readline(&prompt) {
247288
Ok(input) => {
248289
_ = incoming_events_tx.send(IncomingEvent::Input(input));
249290
},
@@ -259,12 +300,12 @@ impl ViewEnd {
259300

260301
tokio::spawn(async move {
261302
let mut display_state = DisplayState::default();
303+
let prompt_signal = PromptSignal::default();
262304

263305
loop {
264306
if matches!(display_state, DisplayState::Prompting) {
265-
tracing::info!("## ui: prompting sent");
266307
// TODO: fetch prompt related info from session and send it here
267-
if let Err(e) = prompt_signal_tx.send(Default::default()) {
308+
if let Err(e) = prompt_signal_tx.send(prompt_signal.clone()) {
268309
error!("Error sending prompt signal: {:?}", e);
269310
}
270311
display_state = DisplayState::UserInsertingText;

0 commit comments

Comments
 (0)