2020-01-20 08:05:32 +01:00
|
|
|
use crate::prelude::*;
|
2021-01-10 03:50:49 +01:00
|
|
|
use nu_engine::WholeStreamCommand;
|
2020-01-20 08:05:32 +01:00
|
|
|
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]
|
2020-01-20 08:05:32 +01:00
|
|
|
impl WholeStreamCommand for Clear {
|
|
|
|
fn name(&self) -> &str {
|
|
|
|
"clear"
|
|
|
|
}
|
2020-05-18 14:56:01 +02:00
|
|
|
|
2020-01-20 08:05:32 +01:00
|
|
|
fn signature(&self) -> Signature {
|
|
|
|
Signature::build("clear")
|
|
|
|
}
|
2020-05-18 14:56:01 +02:00
|
|
|
|
2020-01-20 08:05:32 +01:00
|
|
|
fn usage(&self) -> &str {
|
2020-09-18 08:13:53 +02:00
|
|
|
"Clears the terminal"
|
2020-01-20 08:05:32 +01:00
|
|
|
}
|
2020-05-18 14:56:01 +02:00
|
|
|
|
2020-12-18 08:53:49 +01:00
|
|
|
async fn run(&self, _: CommandArgs) -> Result<OutputStream, ShellError> {
|
2020-05-30 01:36:04 +02:00
|
|
|
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())
|
2020-01-20 08:05:32 +01:00
|
|
|
}
|
2020-05-18 14:56:01 +02:00
|
|
|
|
|
|
|
fn examples(&self) -> Vec<Example> {
|
|
|
|
vec![Example {
|
2020-05-12 03:00:55 +02:00
|
|
|
description: "Clear the screen",
|
|
|
|
example: "clear",
|
2020-05-18 14:56:01 +02:00
|
|
|
result: None,
|
2020-05-12 03:00:55 +02:00
|
|
|
}]
|
|
|
|
}
|
2020-01-20 08:05:32 +01:00
|
|
|
}
|