Skip to content

Commit

Permalink
Changing history behavior to save duplicate lines
Browse files Browse the repository at this point in the history
Adding currently-inactive parameter to configure max length of history
  • Loading branch information
luketpeterson committed Sep 14, 2023
1 parent 325b8c0 commit 027fdc2
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions repl/src/config_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub const CFG_STRING_STYLE: &str = "ReplStringStyle";
pub const CFG_ERROR_STYLE: &str = "ReplErrorStyle";
pub const CFG_BRACKET_MATCH_STYLE: &str = "ReplBracketMatchStyle";
pub const CFG_BRACKET_MATCH_ENABLED: &str = "ReplBracketMatchEnabled";
pub const CFG_HISTORY_MAX_LEN: &str = "ReplHistoryMaxLen";

#[derive(Default, Debug)]
pub struct ReplParams {
Expand Down
3 changes: 3 additions & 0 deletions repl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,13 @@ fn start_interactive_mode(repl_params: Shared<ReplParams>, mut metta: MettaShim)

//Run the repl init file
metta.load_metta_module(repl_params.borrow().repl_config_metta_path.clone());
let max_len = metta.get_config_int(CFG_HISTORY_MAX_LEN).unwrap_or_else(|| 500);

//Init RustyLine
let config = Config::builder()
.history_ignore_space(true)
.max_history_size(max_len as usize).unwrap()
.history_ignore_dups(false).unwrap()
.completion_type(CompletionType::List)
.edit_mode(EditMode::Emacs)
.build();
Expand Down
3 changes: 3 additions & 0 deletions repl/src/metta_shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ impl MettaShim {
result
}

pub fn get_config_int(&mut self, _config_name: &str) -> Option<isize> {
None //TODO. Make this work when I have reliable value atom bridging
}
}

#[cfg(not(feature = "python"))]
Expand Down
2 changes: 2 additions & 0 deletions repl/src/repl.default.metta
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

; !(pragma! ReplHistoryMaxLen 500) ; TODO: enable this when I have value bridging implemented.

!(pragma! ReplDefaultPrompt "> ")
; !(pragma! ReplStyledPrompt "\x1b[1;32m> \x1b[0m") ; TODO: currently the MeTTa string parser doesn't resolve escape chars, although perhaps it should

Expand Down

0 comments on commit 027fdc2

Please sign in to comment.