From 80624267fd0d2ad94346cde7d462ccc05f74e4e0 Mon Sep 17 00:00:00 2001 From: nibon7 Date: Wed, 7 Sep 2022 16:40:44 +0800 Subject: [PATCH] Pass `TERM` environment var to clear (#6500) * Pass `TERM` environment var to clear * don't panic * use IOErrorSpanned instead of IOError --- crates/nu-command/src/platform/clear.rs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/crates/nu-command/src/platform/clear.rs b/crates/nu-command/src/platform/clear.rs index fdc540bd6..2de74d231 100644 --- a/crates/nu-command/src/platform/clear.rs +++ b/crates/nu-command/src/platform/clear.rs @@ -23,24 +23,31 @@ impl Command for Clear { fn run( &self, - _engine_state: &EngineState, - _stack: &mut Stack, + engine_state: &EngineState, + stack: &mut Stack, call: &Call, _input: PipelineData, ) -> Result { + let span = call.head; + if cfg!(windows) { CommandSys::new("cmd") .args(["/C", "cls"]) .status() - .expect("failed to execute process"); + .map_err(|e| ShellError::IOErrorSpanned(e.to_string(), span))?; } else if cfg!(unix) { - CommandSys::new("/bin/sh") - .args(["-c", "clear"]) + let mut cmd = CommandSys::new("/bin/sh"); + + if let Some(Value::String { val, .. }) = stack.get_env_var(engine_state, "TERM") { + cmd.env("TERM", val); + } + + cmd.args(["-c", "clear"]) .status() - .expect("failed to execute process"); + .map_err(|e| ShellError::IOErrorSpanned(e.to_string(), span))?; } - Ok(Value::Nothing { span: call.head }.into_pipeline_data()) + Ok(Value::Nothing { span }.into_pipeline_data()) } fn examples(&self) -> Vec {