Skip to content

Commit

Permalink
don't save options automaticly, add new command to save options
Browse files Browse the repository at this point in the history
  • Loading branch information
sigmaSd committed Sep 27, 2024
1 parent 5a7e32e commit 74f9251
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 12 deletions.
2 changes: 2 additions & 0 deletions crates/irust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
5 changes: 0 additions & 5 deletions crates/irust/src/irust/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ pub struct Engine {
macros: HashMap<char, Vec<Command>>,
buffers: Vec<Buffer>,
buffers_idx: usize,
// defaults to false
pub dont_save_options: bool,
}

impl IRust {
Expand Down Expand Up @@ -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(())
Expand Down
3 changes: 0 additions & 3 deletions crates/irust/src/irust/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
6 changes: 6 additions & 0 deletions crates/irust/src/irust/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -1041,6 +1042,11 @@ impl IRust {
self.exit_flag = true;
Ok(PrintQueue::default())
}

fn save_options(&mut self) -> Result<PrintQueue> {
self.options.save()?;
success!()
}
}

// These patterns are used to detect statements that don't require to be terminated with ';'
Expand Down
3 changes: 2 additions & 1 deletion crates/irust/src/irust/ra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
}
Expand Down Expand Up @@ -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(),
Expand Down
4 changes: 1 addition & 3 deletions crates/irust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down

0 comments on commit 74f9251

Please sign in to comment.