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;
|
|
|
|
|
|
|
|
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 {
|
2021-03-08 00:57:58 +01:00
|
|
|
"Clears the terminal."
|
2020-01-20 08:05:32 +01:00
|
|
|
}
|
2020-05-18 14:56:01 +02:00
|
|
|
|
2021-04-12 04:35:01 +02:00
|
|
|
fn run(&self, _: CommandArgs) -> Result<InputStream, 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");
|
|
|
|
}
|
2021-04-12 04:35:01 +02:00
|
|
|
Ok(InputStream::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
|
|
|
}
|