From ba3cc4f15dd4b7457bbcacc64fcdbdbb0362d473 Mon Sep 17 00:00:00 2001 From: sigoden Date: Mon, 30 Oct 2023 13:36:08 +0800 Subject: feat: deprecate history file (#179) --- src/repl/init.rs | 22 ++++------------------ src/repl/mod.rs | 19 ++----------------- 2 files changed, 6 insertions(+), 35 deletions(-) (limited to 'src/repl') diff --git a/src/repl/init.rs b/src/repl/init.rs index 60fce00..420f596 100644 --- a/src/repl/init.rs +++ b/src/repl/init.rs @@ -2,13 +2,13 @@ use super::{ highlighter::ReplHighlighter, prompt::ReplPrompt, validator::ReplValidator, REPL_COMMANDS, }; -use crate::config::{Config, SharedConfig}; +use crate::config::SharedConfig; -use anyhow::{Context, Result}; +use anyhow::Result; use reedline::{ default_emacs_keybindings, default_vi_insert_keybindings, default_vi_normal_keybindings, - ColumnarMenu, DefaultCompleter, EditMode, Emacs, FileBackedHistory, KeyCode, KeyModifiers, - Keybindings, Reedline, ReedlineEvent, ReedlineMenu, Vi, + ColumnarMenu, DefaultCompleter, EditMode, Emacs, KeyCode, KeyModifiers, Keybindings, Reedline, + ReedlineEvent, ReedlineMenu, Vi, }; const MENU_NAME: &str = "completion_menu"; @@ -27,7 +27,6 @@ impl Repl { let completer = Self::create_completer(&config, &commands); let highlighter = ReplHighlighter::new(config.clone(), commands); - let history = Self::create_history()?; let menu = Self::create_menu(); let edit_mode: Box = if config.read().keybindings.is_vi() { let mut normal_keybindings = default_vi_normal_keybindings(); @@ -43,7 +42,6 @@ impl Repl { let mut editor = Reedline::create() .with_completer(Box::new(completer)) .with_highlighter(Box::new(highlighter)) - .with_history(history) .with_menu(menu) .with_edit_mode(edit_mode) .with_quick_completions(true) @@ -73,11 +71,6 @@ impl Repl { ReedlineEvent::MenuNext, ]), ); - keybindings.add_binding( - KeyModifiers::CONTROL, - KeyCode::Char('l'), - ReedlineEvent::ExecuteHostCommand(".clear screen".into()), - ); keybindings.add_binding( KeyModifiers::CONTROL, KeyCode::Char('s'), @@ -89,11 +82,4 @@ impl Repl { let completion_menu = ColumnarMenu::default().with_name(MENU_NAME); ReedlineMenu::EngineCompleter(Box::new(completion_menu)) } - - fn create_history() -> Result> { - Ok(Box::new( - FileBackedHistory::with_file(1000, Config::history_file()?) - .with_context(|| "Failed to setup history file")?, - )) - } } diff --git a/src/repl/mod.rs b/src/repl/mod.rs index a6f173a..7a665ea 100644 --- a/src/repl/mod.rs +++ b/src/repl/mod.rs @@ -11,15 +11,14 @@ pub use self::init::Repl; use crate::config::SharedConfig; use crate::print_now; -use crate::term; -use anyhow::{Context, Result}; +use anyhow::Result; use fancy_regex::Regex; use lazy_static::lazy_static; use reedline::Signal; use std::rc::Rc; -pub const REPL_COMMANDS: [(&str, &str); 14] = [ +pub const REPL_COMMANDS: [(&str, &str); 12] = [ (".info", "Print system-wide information"), (".set", "Modify the configuration temporarily"), (".model", "Choose a model"), @@ -30,8 +29,6 @@ pub const REPL_COMMANDS: [(&str, &str); 14] = [ (".copy", "Copy the last output to the clipboard"), (".read", "Read the contents of a file and submit"), (".edit", "Multi-line editing (CTRL+S to finish)"), - (".history", "Print the REPL history"), - (".clear history", "Clear the REPL history"), (".help", "Print this help message"), (".exit", "Exit the REPL"), ]; @@ -102,22 +99,10 @@ impl Repl { dump_repl_help(); } ".clear" => match args { - Some("screen") => term::clear_screen(0)?, - Some("history") => { - self.editor - .history_mut() - .clear() - .with_context(|| "Failed to clear history")?; - print_now!("\n"); - } Some("role") => handler.handle(ReplCmd::ClearRole)?, Some("session") => handler.handle(ReplCmd::EndSession)?, _ => dump_unknown_command(), }, - ".history" => { - self.editor.print_history()?; - print_now!("\n"); - } ".model" => match args { Some(name) => handler.handle(ReplCmd::SetModel(name.to_string()))?, None => print_now!("Usage: .model \n\n"), -- cgit v1.2.3