summaryrefslogtreecommitdiffstats
path: root/src/repl
diff options
context:
space:
mode:
Diffstat (limited to 'src/repl')
-rw-r--r--src/repl/handler.rs51
-rw-r--r--src/repl/prompt.rs6
2 files changed, 17 insertions, 40 deletions
diff --git a/src/repl/handler.rs b/src/repl/handler.rs
index fd157dc..35a57da 100644
--- a/src/repl/handler.rs
+++ b/src/repl/handler.rs
@@ -115,9 +115,9 @@ impl ReplCmdHandler {
}
ReplCmd::ReadFile(file) => {
let mut contents = String::new();
- let mut file = fs::File::open(file).expect("Unable to open file");
+ let mut file = fs::File::open(file).with_context(|| "Unable to open file")?;
file.read_to_string(&mut contents)
- .expect("Unable to read file");
+ .with_context(|| "Unable to read file")?;
self.handle(ReplCmd::Submit(contents))?;
}
}
@@ -137,23 +137,17 @@ impl ReplCmdHandler {
#[allow(clippy::module_name_repetitions)]
pub struct ReplyStreamHandler {
- sender: Option<Sender<ReplyStreamEvent>>,
+ sender: Sender<ReplyStreamEvent>,
buffer: String,
abort: SharedAbortSignal,
- repl: bool,
}
impl ReplyStreamHandler {
- pub fn new(
- sender: Option<Sender<ReplyStreamEvent>>,
- repl: bool,
- abort: SharedAbortSignal,
- ) -> Self {
+ pub fn new(sender: Sender<ReplyStreamEvent>, abort: SharedAbortSignal) -> Self {
Self {
sender,
abort,
buffer: String::new(),
- repl,
}
}
@@ -162,37 +156,20 @@ impl ReplyStreamHandler {
return Ok(());
}
self.buffer.push_str(text);
- match self.sender.as_ref() {
- Some(tx) => {
- let ret = tx
- .send(ReplyStreamEvent::Text(text.to_string()))
- .with_context(|| "Failed to send StreamEvent:Text");
- self.safe_ret(ret)?;
- }
- None => {
- print_now!("{}", text);
- }
- }
+ let ret = self
+ .sender
+ .send(ReplyStreamEvent::Text(text.to_string()))
+ .with_context(|| "Failed to send StreamEvent:Text");
+ self.safe_ret(ret)?;
Ok(())
}
pub fn done(&mut self) -> Result<()> {
- if let Some(tx) = self.sender.as_ref() {
- let ret = tx
- .send(ReplyStreamEvent::Done)
- .with_context(|| "Failed to send StreamEvent:Done");
- self.safe_ret(ret)?;
- } else {
- if !self.buffer.ends_with('\n') {
- print_now!("\n");
- }
- if self.repl {
- print_now!("\n");
- if cfg!(macos) {
- print_now!("\n");
- }
- }
- }
+ let ret = self
+ .sender
+ .send(ReplyStreamEvent::Done)
+ .with_context(|| "Failed to send StreamEvent:Done");
+ self.safe_ret(ret)?;
Ok(())
}
diff --git a/src/repl/prompt.rs b/src/repl/prompt.rs
index be3763b..f48ce64 100644
--- a/src/repl/prompt.rs
+++ b/src/repl/prompt.rs
@@ -41,15 +41,15 @@ impl ReplPrompt {
}
pub fn get_colors(config: &SharedConfig) -> (Color, nu_ansi_term::Color, Color, Color) {
- let (highlight, light_theme) = config.read().get_render_options();
- if highlight {
+ let render_options = config.read().get_render_options();
+ if render_options.highlight {
(
PROMPT_COLOR,
PROMPT_MULTILINE_COLOR,
INDICATOR_COLOR,
PROMPT_RIGHT_COLOR,
)
- } else if light_theme {
+ } else if render_options.light_theme {
(
Color::Black,
nu_ansi_term::Color::Black,