From dcd7360b174fa79487594257e5e965d707cceb4c Mon Sep 17 00:00:00 2001 From: Mark Date: Thu, 20 Jul 2023 09:39:06 -0600 Subject: [PATCH] add EMIT_NEWLINE to add newlines to readline input only after query terms begin to be read (#1074, #1897) --- src/machine/system_calls.rs | 1 + src/read.rs | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/machine/system_calls.rs b/src/machine/system_calls.rs index 0d4b5e92..f9969669 100644 --- a/src/machine/system_calls.rs +++ b/src/machine/system_calls.rs @@ -5797,6 +5797,7 @@ impl Machine { pub(crate) fn read_query_term(&mut self) -> CallResult { self.user_input.reset(); + set_emit_newline(true); set_prompt(true); // let result = self.machine_st.read_term(self.user_input, &mut self.indices); let result = self.machine_st.read_term_from_user_input(self.user_input, &mut self.indices); diff --git a/src/read.rs b/src/read.rs index 3afb4bf9..c21c3016 100644 --- a/src/read.rs +++ b/src/read.rs @@ -80,9 +80,16 @@ impl MachineState { } static mut PROMPT: bool = false; +static mut EMIT_NEWLINE: bool = false; const HISTORY_FILE: &'static str = ".scryer_history"; +pub(crate) fn set_emit_newline(value: bool) { + unsafe { + EMIT_NEWLINE = value; + } +} + pub(crate) fn set_prompt(value: bool) { unsafe { PROMPT = value; @@ -161,10 +168,12 @@ impl ReadlineStream { self.save_history(); PROMPT = false; } - } - if self.pending_input.get_ref().get_ref().chars().last() != Some('\n') { - *self.pending_input.get_mut().get_mut() += "\n"; + if EMIT_NEWLINE { + if self.pending_input.get_ref().get_ref().chars().last() != Some('\n') { + *self.pending_input.get_mut().get_mut() += "\n"; + } + } } Ok(self.pending_input.get_ref().get_ref().len()) -- 2.54.0