nushell/crates/nu-command/src/commands/clear.rs

46 lines
1.1 KiB
Rust
Raw Normal View History

use crate::prelude::*;
use nu_engine::WholeStreamCommand;
use nu_errors::ShellError;
use nu_protocol::Signature;
use std::process::Command;
pub struct Clear;
2020-05-29 10:22:52 +02:00
#[async_trait]
impl WholeStreamCommand for Clear {
fn name(&self) -> &str {
"clear"
}
fn signature(&self) -> Signature {
Signature::build("clear")
}
fn usage(&self) -> &str {
2020-09-18 08:13:53 +02:00
"Clears the terminal"
}
async fn run(&self, _: CommandArgs) -> Result<OutputStream, ShellError> {
if cfg!(windows) {
Command::new("cmd")
.args(&["/C", "cls"])
.status()
.expect("failed to execute process");
} else if cfg!(unix) {
Command::new("/bin/sh")
.args(&["-c", "clear"])
.status()
.expect("failed to execute process");
}
Ok(OutputStream::empty())
}
fn examples(&self) -> Vec<Example> {
vec![Example {
2020-05-12 03:00:55 +02:00
description: "Clear the screen",
example: "clear",
result: None,
2020-05-12 03:00:55 +02:00
}]
}
}