Fix lack of history for ; interpreter submissions

This commit is contained in:
NGnius (Graham) 2022-07-09 00:27:40 -04:00
parent c9c1ab88b9
commit d7a8e74bd8

View file

@ -338,6 +338,10 @@ fn read_loop<F: FnMut(&mut ReplState, &CliArgs)>(args: &CliArgs, state: &mut Rep
} }
';' => { ';' => {
if state.in_literal.is_none() { if state.in_literal.is_none() {
state
.terminal
.write_line("")
.expect(TERMINAL_WRITE_ERROR);
let statement = state.statement_buf.iter().collect::<String>(); let statement = state.statement_buf.iter().collect::<String>();
let statement_result = statement.trim(); let statement_result = statement.trim();
if !statement_result.starts_with('?') { if !statement_result.starts_with('?') {
@ -348,29 +352,19 @@ fn read_loop<F: FnMut(&mut ReplState, &CliArgs)>(args: &CliArgs, state: &mut Rep
execute(state, args); execute(state, args);
state.statement_buf.clear(); state.statement_buf.clear();
} }
} let last_line = state.current_line[0..state.current_line.len() - 1].iter().collect::<String>();
} state.current_line.clear();
'\n' => { if !last_line.is_empty()
let statement = state.statement_buf.iter().collect::<String>(); && ((!state.history.is_empty()
let statement_result = statement.trim(); && state.history[state.history.len() - 1] != last_line)
if statement_result.starts_with('?') { || state.history.is_empty())
//println!("Got {}", statement_result.unwrap());
repl_commands(statement_result, state, args);
state.statement_buf.clear();
} else if state.bracket_depth == 0
&& state.in_literal.is_none()
&& state.curly_depth == 0
{ {
state.statement_buf.push(';'); state.history.push(last_line);
state
.writer
.write(state.statement_buf.iter().collect::<String>().as_bytes())
.expect(INTERPRETER_WRITE_ERROR);
execute(state, args);
state.statement_buf.clear();
} }
state.selected_history = 0;
prompt(state, args); prompt(state, args);
} }
}
_ => {} _ => {}
} }
} }