diff --git a/src/lib/shell/binary/prompt.rs b/src/lib/shell/binary/prompt.rs index e271b05446e11b461522959577147eee5f1242fa..2a181c5d289165cdf5046625f262a28030342dea 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 150a6619194d2a37832c10e29488a4383188e89b..8a72e96f30817b54039f4461ff2e2fd75546c518 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 430ef9826070bb413f49af93f297e7b8a877bf90..0000000000000000000000000000000000000000 --- 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 7c1a66fb13255b6e3facc43a3a0778f07fd249ef..cf2823b84e8afc3489ee61335af56e5fbfc4ce65 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}, };