From 1ca34dff7a15c843d7ff7d96192af1581866a940 Mon Sep 17 00:00:00 2001 From: Michael Aaron Murphy <mmstickman@gmail.com> Date: Sat, 20 Oct 2018 18:17:41 +0000 Subject: [PATCH] Fix the prompt with quoted multi-line inputs --- src/lib/shell/binary/prompt.rs | 9 ++++++--- src/lib/shell/binary/terminate.rs | 9 ++++++--- src/lib/shell/flags.rs | 4 ---- src/lib/shell/mod.rs | 14 +++++++++++++- 4 files changed, 25 insertions(+), 11 deletions(-) delete mode 100644 src/lib/shell/flags.rs diff --git a/src/lib/shell/binary/prompt.rs b/src/lib/shell/binary/prompt.rs index e271b054..2a181c5d 100644 --- a/src/lib/shell/binary/prompt.rs +++ b/src/lib/shell/binary/prompt.rs @@ -1,16 +1,19 @@ use parser::shell_expand::expand_string; -use shell::{Capture, Function, Shell}; +use shell::{flags::UNTERMINATED, Capture, Function, Shell}; use std::{io::Read, process}; use sys; pub(crate) fn prompt(shell: &mut Shell) -> String { - if shell.flow_control.block.len() == 0 { + let blocks = shell.flow_control.block.len() + + if shell.flags & UNTERMINATED != 0 { 1 } else { 0 }; + + if blocks == 0 { match prompt_fn(shell) { Some(prompt) => prompt, None => expand_string(&shell.get_str_or_empty("PROMPT"), shell, false).join(" "), } } else { - " ".repeat(shell.flow_control.block.len()) + " ".repeat(blocks) } } diff --git a/src/lib/shell/binary/terminate.rs b/src/lib/shell/binary/terminate.rs index 150a6619..8a72e96f 100644 --- a/src/lib/shell/binary/terminate.rs +++ b/src/lib/shell/binary/terminate.rs @@ -1,4 +1,4 @@ -use super::super::{status::*, Binary, FlowLogic, Shell}; +use shell::{flags::UNTERMINATED, status::*, Binary, FlowLogic, Shell}; use parser::Terminator; pub(crate) fn terminate_script_quotes<I: Iterator<Item = String>>( @@ -51,15 +51,18 @@ pub(crate) fn terminate_script_quotes<I: Iterator<Item = String>>( pub(crate) fn terminate_quotes(shell: &mut Shell, command: String) -> Result<String, ()> { let mut buffer = Terminator::new(command); - while !buffer.is_terminated() { + shell.flags |= UNTERMINATED; + while ! buffer.is_terminated() { if let Some(command) = shell.readln() { - if !command.starts_with('#') { + if ! command.starts_with('#') { buffer.append(&command); } } else { return Err(()); } } + + shell.flags ^= UNTERMINATED; let terminated = buffer.consume(); Ok(terminated) } diff --git a/src/lib/shell/flags.rs b/src/lib/shell/flags.rs deleted file mode 100644 index 430ef982..00000000 --- a/src/lib/shell/flags.rs +++ /dev/null @@ -1,4 +0,0 @@ -pub const ERR_EXIT: u8 = 1; -pub const PRINT_COMMS: u8 = 2; -pub const NO_EXEC: u8 = 4; -pub const HUPONEXIT: u8 = 8; diff --git a/src/lib/shell/mod.rs b/src/lib/shell/mod.rs index 7c1a66fb..cf2823b8 100644 --- a/src/lib/shell/mod.rs +++ b/src/lib/shell/mod.rs @@ -4,7 +4,6 @@ pub(crate) mod colors; mod completer; pub(crate) mod directory_stack; pub(crate) mod escape; -pub mod flags; mod flow; pub(crate) mod flow_control; mod fork; @@ -16,6 +15,19 @@ pub(crate) mod signals; pub mod status; pub mod variables; +pub mod flags { + /// Exit from the shell on the first error. + pub const ERR_EXIT: u8 = 1; + /// Print commands that are to be executed. + pub const PRINT_COMMS: u8 = 2; + /// Do not execute any commands given to the shell. + pub const NO_EXEC: u8 = 4; + /// Hangup on exiting the shell. + pub const HUPONEXIT: u8 = 8; + /// Used by an interactive session to know when the input is not terminated. + pub const UNTERMINATED: u8 = 16; +} + pub use self::{ binary::Binary, fork::{Capture, Fork, IonResult}, }; -- GitLab