From 74f9251fcddf1b95b5ad2e1d192226bc3083803b Mon Sep 17 00:00:00 2001 From: Nbiba Bedis Date: Fri, 27 Sep 2024 16:47:37 +0100 Subject: [PATCH] don't save options automaticly, add new command to save options --- crates/irust/README.md | 2 ++ crates/irust/src/irust/engine.rs | 5 ----- crates/irust/src/irust/options.rs | 3 --- crates/irust/src/irust/parser.rs | 6 ++++++ crates/irust/src/irust/ra.rs | 3 ++- crates/irust/src/main.rs | 4 +--- 6 files changed, 11 insertions(+), 12 deletions(-) diff --git a/crates/irust/README.md b/crates/irust/README.md index 93d329e..ca9a1e3 100644 --- a/crates/irust/README.md +++ b/crates/irust/README.md @@ -64,6 +64,8 @@ You can try out IRust with no installation or setup (via Gitpod.io) by visiting **:exit** | **:quit** => Exit IRust immediately +**:save_options** => save the options to disk (useful when options where changed at runtime) + **$$** => Shell commands can be interpolated with rust code with '$$', for example: `let a = $$ls -l$$;`, this feature can be [en/dis]abled via the config file **::** => run a shell command, example `::ls` diff --git a/crates/irust/src/irust/engine.rs b/crates/irust/src/irust/engine.rs index e2d784d..3e7e38a 100644 --- a/crates/irust/src/irust/engine.rs +++ b/crates/irust/src/irust/engine.rs @@ -28,8 +28,6 @@ pub struct Engine { macros: HashMap>, buffers: Vec, buffers_idx: usize, - // defaults to false - pub dont_save_options: bool, } impl IRust { @@ -680,9 +678,6 @@ impl IRust { // Give scripts a chance to clean-up self.run_scripts_shutdown_cmds()?; self.history.save()?; - if !self.engine.dont_save_options { - self.options.save()?; - } self.printer.write_newline(&self.buffer); self.printer.cursor.show(); Ok(()) diff --git a/crates/irust/src/irust/options.rs b/crates/irust/src/irust/options.rs index 14780b5..d934143 100644 --- a/crates/irust/src/irust/options.rs +++ b/crates/irust/src/irust/options.rs @@ -182,9 +182,6 @@ impl IRust { || (shell_cmd && self.options.add_shell_cmd_to_history) || (!irust_cmd && !shell_cmd) } - pub fn dont_save_options(&mut self) { - self.engine.dont_save_options = true; - } } #[allow(clippy::upper_case_acronyms)] diff --git a/crates/irust/src/irust/parser.rs b/crates/irust/src/irust/parser.rs index 1e90d96..49c2822 100644 --- a/crates/irust/src/irust/parser.rs +++ b/crates/irust/src/irust/parser.rs @@ -52,6 +52,7 @@ impl IRust { ":irust" => self.irust(), ":sync" => self.sync(), ":exit" | ":quit" => self.exit(), + ":save_options" => self.save_options(), cmd if cmd.starts_with(":help") => self.help(buffer), cmd if cmd.starts_with("::") => self.run_cmd(buffer), cmd if cmd.starts_with(":edit") => self.extern_edit(buffer), @@ -1041,6 +1042,11 @@ impl IRust { self.exit_flag = true; Ok(PrintQueue::default()) } + + fn save_options(&mut self) -> Result { + self.options.save()?; + success!() + } } // These patterns are used to detect statements that don't require to be terminated with ';' diff --git a/crates/irust/src/irust/ra.rs b/crates/irust/src/irust/ra.rs index 330f297..6d2bdd9 100644 --- a/crates/irust/src/irust/ra.rs +++ b/crates/irust/src/irust/ra.rs @@ -23,7 +23,7 @@ pub struct Completer { // suggestions: (Name, definition) suggestions: Vec<(String, String)>, suggestion_idx: usize, - cmds: [String; 30], + cmds: [String; 31], update_lock: bool, pub active_suggestion: Option, } @@ -53,6 +53,7 @@ impl Completer { "toolchain".to_string(), "theme".to_string(), "main_result".to_string(), + "save_options".to_string(), "check_statements".to_string(), "time_release".to_string(), "time".to_string(), diff --git a/crates/irust/src/main.rs b/crates/irust/src/main.rs index 384e7c7..52df545 100644 --- a/crates/irust/src/main.rs +++ b/crates/irust/src/main.rs @@ -77,9 +77,7 @@ fn main() { // Create main IRust interface let mut irust = if matches!(args_result, ArgsResult::ProceedWithDefaultConfig) { - let mut irust = IRust::new(Options::default()); - irust.dont_save_options(); - irust + IRust::new(Options::default()) } else { // Check optional dependencies and warn if they're not present if !cfg!(feature = "no-welcome-screen") {