Merge pull request #1342 from wkral/no-add-history
Add --no-add-history flag
This commit is contained in:
16
src/machine/args.rs
Normal file
16
src/machine/args.rs
Normal file
@@ -0,0 +1,16 @@
|
||||
use std::collections::BTreeSet;
|
||||
use std::env;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct MachineArgs {
|
||||
pub add_history: bool,
|
||||
}
|
||||
|
||||
impl MachineArgs {
|
||||
pub fn new() -> Self {
|
||||
let args: BTreeSet<String> = env::args().collect();
|
||||
Self {
|
||||
add_history: !args.contains("--no-add-history"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
pub mod args;
|
||||
pub mod arithmetic_ops;
|
||||
pub mod attributed_variables;
|
||||
pub mod code_walker;
|
||||
@@ -25,6 +26,7 @@ use crate::arithmetic::*;
|
||||
use crate::atom_table::*;
|
||||
use crate::forms::*;
|
||||
use crate::instructions::*;
|
||||
use crate::machine::args::*;
|
||||
use crate::machine::compile::*;
|
||||
use crate::machine::copier::*;
|
||||
use crate::machine::heap::*;
|
||||
@@ -396,9 +398,10 @@ impl Machine {
|
||||
pub fn new() -> Self {
|
||||
use ref_thread_local::RefThreadLocal;
|
||||
|
||||
let args = MachineArgs::new();
|
||||
let mut machine_st = MachineState::new();
|
||||
|
||||
let user_input = Stream::stdin(&mut machine_st.arena);
|
||||
let user_input = Stream::stdin(&mut machine_st.arena, args.add_history);
|
||||
let user_output = Stream::stdout(&mut machine_st.arena);
|
||||
let user_error = Stream::stderr(&mut machine_st.arena);
|
||||
|
||||
|
||||
@@ -426,9 +426,9 @@ impl Stream {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn stdin(arena: &mut Arena) -> Stream {
|
||||
pub fn stdin(arena: &mut Arena, add_history: bool) -> Stream {
|
||||
Stream::Readline(arena_alloc!(
|
||||
StreamLayout::new(ReadlineStream::new("")),
|
||||
StreamLayout::new(ReadlineStream::new("", add_history)),
|
||||
arena
|
||||
))
|
||||
}
|
||||
|
||||
@@ -4094,7 +4094,7 @@ impl Machine {
|
||||
match result {
|
||||
Ok(()) => Ok(()),
|
||||
Err(e) => {
|
||||
self.user_input = input_stream(&mut self.machine_st.arena);
|
||||
self.user_input.reset();
|
||||
return Err(e);
|
||||
}
|
||||
}
|
||||
|
||||
14
src/read.rs
14
src/read.rs
@@ -1,7 +1,6 @@
|
||||
use crate::parser::ast::*;
|
||||
use crate::parser::parser::*;
|
||||
|
||||
use crate::arena::*;
|
||||
use crate::atom_table::*;
|
||||
use crate::forms::*;
|
||||
use crate::iterators::*;
|
||||
@@ -78,21 +77,16 @@ fn get_prompt() -> &'static str {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn input_stream(arena: &mut Arena) -> Stream {
|
||||
let input_stream = ReadlineStream::new("");
|
||||
Stream::from_readline_stream(input_stream, arena)
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ReadlineStream {
|
||||
rl: Editor<()>,
|
||||
pending_input: Cursor<String>,
|
||||
add_history: bool,
|
||||
}
|
||||
|
||||
impl ReadlineStream {
|
||||
#[inline]
|
||||
pub fn new(pending_input: &str) -> Self {
|
||||
pub fn new(pending_input: &str, add_history: bool) -> Self {
|
||||
let config = Config::builder().check_cursor_position(true).build();
|
||||
let mut rl = Editor::<()>::with_config(config);
|
||||
|
||||
@@ -108,6 +102,7 @@ impl ReadlineStream {
|
||||
ReadlineStream {
|
||||
rl,
|
||||
pending_input: Cursor::new(pending_input.to_owned()),
|
||||
add_history: add_history,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,6 +138,9 @@ impl ReadlineStream {
|
||||
}
|
||||
|
||||
fn save_history(&mut self) {
|
||||
if !self.add_history {
|
||||
return;
|
||||
};
|
||||
if let Some(mut path) = dirs_next::home_dir() {
|
||||
path.push(HISTORY_FILE);
|
||||
if path.exists() {
|
||||
|
||||
@@ -57,6 +57,7 @@ delegate_task([Arg0|Args], Goals0) :-
|
||||
; member(Arg0, ["-v", "--version"]) -> print_version
|
||||
; member(Arg0, ["-g", "--goal"]) -> gather_goal(g, Args, Goals0)
|
||||
; member(Arg0, ["-f"]) -> disable_init_file
|
||||
; member(Arg0, ["--no-add-history"]) -> ignore_machine_arg
|
||||
; atom_chars(Mod, Arg0),
|
||||
catch(consult(Mod), E, print_exception(E))
|
||||
),
|
||||
@@ -73,7 +74,9 @@ print_help :-
|
||||
write(' -g, --goal GOAL '),
|
||||
write('Run the query GOAL'), nl,
|
||||
write(' -f '),
|
||||
write('Fast startup. Do not load initialization file (~/.scryerrc)'),nl,
|
||||
write('Fast startup. Do not load initialization file (~/.scryerrc)'), nl,
|
||||
write(' --no-add-history '),
|
||||
write('Prevent adding input to history file (~/.scryer_history)'), nl,
|
||||
% write(' '),
|
||||
halt.
|
||||
|
||||
@@ -94,6 +97,8 @@ gather_goal(Type, Args0, Goals) :-
|
||||
disable_init_file :-
|
||||
asserta('disabled_init_file').
|
||||
|
||||
ignore_machine_arg.
|
||||
|
||||
arg_type(g).
|
||||
arg_type(t).
|
||||
arg_type(g(_)).
|
||||
|
||||
@@ -65,6 +65,7 @@ pub fn run_top_level_test_with_args<
|
||||
Command::cargo_bin(SCRYER_PROLOG)
|
||||
.unwrap()
|
||||
.arg("-f")
|
||||
.arg("--no-add-history")
|
||||
.args(args)
|
||||
.write_stdin(stdin)
|
||||
.assert()
|
||||
|
||||
Reference in New Issue
Block a user