mirror of
https://github.com/nushell/nushell
synced 2024-12-28 05:53:09 +00:00
Port over the clear command from nushell (#373)
* Port over the clear command from nushell * cargo fmt
This commit is contained in:
parent
8c0fa0d26e
commit
e1e7e94261
5 changed files with 61 additions and 0 deletions
|
@ -26,6 +26,7 @@ pub fn create_default_context() -> EngineState {
|
||||||
Benchmark,
|
Benchmark,
|
||||||
BuildString,
|
BuildString,
|
||||||
Cd,
|
Cd,
|
||||||
|
Clear,
|
||||||
Collect,
|
Collect,
|
||||||
Cp,
|
Cp,
|
||||||
Date,
|
Date,
|
||||||
|
|
|
@ -9,6 +9,7 @@ mod filesystem;
|
||||||
mod filters;
|
mod filters;
|
||||||
mod formats;
|
mod formats;
|
||||||
mod math;
|
mod math;
|
||||||
|
mod platform;
|
||||||
mod shells;
|
mod shells;
|
||||||
mod strings;
|
mod strings;
|
||||||
mod system;
|
mod system;
|
||||||
|
@ -28,6 +29,7 @@ pub use filesystem::*;
|
||||||
pub use filters::*;
|
pub use filters::*;
|
||||||
pub use formats::*;
|
pub use formats::*;
|
||||||
pub use math::*;
|
pub use math::*;
|
||||||
|
pub use platform::*;
|
||||||
pub use shells::*;
|
pub use shells::*;
|
||||||
pub use strings::*;
|
pub use strings::*;
|
||||||
pub use system::*;
|
pub use system::*;
|
||||||
|
|
53
crates/nu-command/src/platform/clear.rs
Normal file
53
crates/nu-command/src/platform/clear.rs
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
use nu_protocol::ast::Call;
|
||||||
|
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||||
|
use nu_protocol::{
|
||||||
|
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Value,
|
||||||
|
};
|
||||||
|
use std::process::Command as CommandSys;
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct Clear;
|
||||||
|
|
||||||
|
impl Command for Clear {
|
||||||
|
fn name(&self) -> &str {
|
||||||
|
"clear"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn usage(&self) -> &str {
|
||||||
|
"Clear the terminal."
|
||||||
|
}
|
||||||
|
|
||||||
|
fn signature(&self) -> Signature {
|
||||||
|
Signature::build("clear").category(Category::Platform)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run(
|
||||||
|
&self,
|
||||||
|
_engine_state: &EngineState,
|
||||||
|
_stack: &mut Stack,
|
||||||
|
call: &Call,
|
||||||
|
_input: PipelineData,
|
||||||
|
) -> Result<PipelineData, ShellError> {
|
||||||
|
if cfg!(windows) {
|
||||||
|
CommandSys::new("cmd")
|
||||||
|
.args(["/C", "cls"])
|
||||||
|
.status()
|
||||||
|
.expect("failed to execute process");
|
||||||
|
} else if cfg!(unix) {
|
||||||
|
CommandSys::new("/bin/sh")
|
||||||
|
.args(["-c", "clear"])
|
||||||
|
.status()
|
||||||
|
.expect("failed to execute process");
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(Value::Nothing { span: call.head }.into_pipeline_data())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn examples(&self) -> Vec<Example> {
|
||||||
|
vec![Example {
|
||||||
|
description: "Clear the terminal",
|
||||||
|
example: "clear",
|
||||||
|
result: None,
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
}
|
3
crates/nu-command/src/platform/mod.rs
Normal file
3
crates/nu-command/src/platform/mod.rs
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
mod clear;
|
||||||
|
|
||||||
|
pub use clear::Clear;
|
|
@ -42,6 +42,7 @@ pub enum Category {
|
||||||
Filters,
|
Filters,
|
||||||
Formats,
|
Formats,
|
||||||
Math,
|
Math,
|
||||||
|
Platform,
|
||||||
Shells,
|
Shells,
|
||||||
Strings,
|
Strings,
|
||||||
System,
|
System,
|
||||||
|
@ -62,6 +63,7 @@ impl std::fmt::Display for Category {
|
||||||
Category::Filters => "filters",
|
Category::Filters => "filters",
|
||||||
Category::Formats => "formats",
|
Category::Formats => "formats",
|
||||||
Category::Math => "math",
|
Category::Math => "math",
|
||||||
|
Category::Platform => "platform",
|
||||||
Category::Shells => "shells",
|
Category::Shells => "shells",
|
||||||
Category::Strings => "strings",
|
Category::Strings => "strings",
|
||||||
Category::System => "system",
|
Category::System => "system",
|
||||||
|
|
Loading…
Reference in a new issue