@@ -4,22 +4,23 @@ use clap_complete::engine::ArgValueCompleter;
44use futures:: StreamExt ;
55use owo_colors:: OwoColorize ;
66use reedline:: {
7- ColumnarMenu , Completer , DefaultHinter , DefaultValidator , EditCommand , Emacs , KeyCode ,
8- KeyModifiers , MenuBuilder , Prompt , PromptEditMode , PromptHistorySearch ,
9- PromptHistorySearchStatus , Reedline , ReedlineEvent , ReedlineMenu , Signal , Suggestion , Vi ,
10- default_emacs_keybindings, default_vi_insert_keybindings, default_vi_normal_keybindings,
7+ ColumnarMenu , Completer , DefaultHinter , DefaultValidator , EditCommand , Emacs ,
8+ FileBackedHistory , KeyCode , KeyModifiers , MenuBuilder , Prompt , PromptEditMode ,
9+ PromptHistorySearch , PromptHistorySearchStatus , Reedline , ReedlineEvent , ReedlineMenu , Signal ,
10+ Suggestion , Vi , default_emacs_keybindings, default_vi_insert_keybindings,
11+ default_vi_normal_keybindings,
1112} ;
1213use rullm_core:: simple:: { SimpleLlm , SimpleLlmClient } ;
1314use rullm_core:: types:: { ChatRequestBuilder , ChatRole , ChatStreamEvent } ;
1415use std:: borrow:: Cow ;
1516use std:: io:: { self , Write } ;
17+ use std:: path:: PathBuf ;
1618use std:: time:: { Duration , Instant } ;
1719
1820use crate :: {
1921 args:: { Cli , CliConfig , model_completer} ,
2022 cli_helpers:: resolve_model,
2123 client,
22- config:: Config ,
2324 output:: OutputLevel ,
2425 spinner:: Spinner ,
2526} ;
@@ -40,7 +41,7 @@ impl ChatArgs {
4041 ) -> Result < ( ) > {
4142 let model_str = resolve_model ( & cli. model , & self . model , & cli_config. config . default_model ) ?;
4243 let client = client:: from_model ( & model_str, cli, cli_config) ?;
43- run_interactive_chat ( & client, None , & cli_config. config , !cli. no_streaming ) . await ?;
44+ run_interactive_chat ( & client, None , & cli_config, !cli. no_streaming ) . await ?;
4445 Ok ( ( ) )
4546 }
4647}
@@ -219,7 +220,7 @@ fn add_common_keybindings(keybindings: &mut reedline::Keybindings) {
219220}
220221
221222/// Setup reedline with all features
222- fn setup_reedline ( vim_mode : bool ) -> Result < Reedline > {
223+ fn setup_reedline ( vim_mode : bool , data_path : & PathBuf ) -> Result < Reedline > {
223224 let completer = Box :: new ( SlashCommandCompleter :: new ( ) ) ;
224225
225226 // Use the interactive menu to select options from the completer
@@ -273,10 +274,16 @@ fn setup_reedline(vim_mode: bool) -> Result<Reedline> {
273274 Box :: new ( Emacs :: new ( keybindings) )
274275 } ;
275276
277+ let history = Box :: new (
278+ FileBackedHistory :: with_file ( 5 , data_path. join ( "history.txt" ) )
279+ . expect ( "Error configuring history with file" ) ,
280+ ) ;
281+
276282 let line_editor = Reedline :: create ( )
277283 . with_completer ( completer)
278284 . with_menu ( ReedlineMenu :: EngineCompleter ( completion_menu) )
279285 . with_hinter ( Box :: new ( DefaultHinter :: default ( ) ) )
286+ . with_history ( history)
280287 . with_validator ( Box :: new ( DefaultValidator ) )
281288 . with_edit_mode ( edit_mode) ;
282289
@@ -340,7 +347,7 @@ async fn handle_slash_command(
340347pub async fn run_interactive_chat (
341348 client : & SimpleLlmClient ,
342349 initial_system : Option < & str > ,
343- config : & Config ,
350+ config : & CliConfig ,
344351 streaming : bool ,
345352) -> Result < ( ) > {
346353 println ! (
@@ -356,7 +363,7 @@ pub async fn run_interactive_chat(
356363 ) ;
357364
358365 let mut conversation = Vec :: new ( ) ;
359- let mut line_editor = setup_reedline ( config. vi_mode ) ?;
366+ let mut line_editor = setup_reedline ( config. config . vi_mode , & config . data_base_path ) ?;
360367 let prompt = ChatPrompt :: new ( client. provider_name ( ) . to_string ( ) ) ;
361368
362369 // Track Ctrl+C presses for double-press exit
0 commit comments