--- /dev/null
+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"),
+ }
+ }
+}
+pub mod args;
pub mod arithmetic_ops;
pub mod attributed_variables;
pub mod code_walker;
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::*;
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);
}
#[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
))
}
match result {
Ok(()) => Ok(()),
Err(e) => {
- self.user_input = input_stream(&mut self.machine_st.arena);
+ self.user_input.reset();
return Err(e);
}
}
use crate::parser::ast::*;
use crate::parser::parser::*;
-use crate::arena::*;
use crate::atom_table::*;
use crate::forms::*;
use crate::iterators::*;
}
}
-#[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);
ReadlineStream {
rl,
pending_input: Cursor::new(pending_input.to_owned()),
+ add_history: add_history,
}
}
}
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() {
; 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))
),
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.
disable_init_file :-
asserta('disabled_init_file').
+ignore_machine_arg.
+
arg_type(g).
arg_type(t).
arg_type(g(_)).
Command::cargo_bin(SCRYER_PROLOG)
.unwrap()
.arg("-f")
+ .arg("--no-add-history")
.args(args)
.write_stdin(stdin)
.assert()