mirror of
https://github.com/nushell/nushell.git
synced 2024-12-03 22:06:54 +01:00
e1e7e94261
* Port over the clear command from nushell * cargo fmt
54 lines
1.3 KiB
Rust
54 lines
1.3 KiB
Rust
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,
|
|
}]
|
|
}
|
|
}
|