From 87e88a41cbc405e7f36c6eeb142b29f99bbcc8f1 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Tue, 15 Jun 2021 17:34:13 -0700 Subject: [PATCH] feat(prompt): create clear command --- crates/whirl_prompt/src/builtins/constants.rs | 3 ++- crates/whirl_prompt/src/builtins/mod.rs | 6 ++++++ crates/whirl_prompt/src/builtins/structures.rs | 2 ++ crates/whirl_prompt/src/lib.rs | 2 ++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/crates/whirl_prompt/src/builtins/constants.rs b/crates/whirl_prompt/src/builtins/constants.rs index 15e7ff2d..1fad9ce2 100644 --- a/crates/whirl_prompt/src/builtins/constants.rs +++ b/crates/whirl_prompt/src/builtins/constants.rs @@ -2,8 +2,9 @@ // SPDX-License-Identifier: GPL-3.0-only pub const FILES: [&str; 2] = ["README.rst", "Config.toml"]; -pub const HELPABLES_BUILTINS: [&str; 8] = [ +pub const HELPABLES_BUILTINS: [&str; 9] = [ "cat - display the contents of a present file", + "clear - clear the display (standard out)", "config - manipulate the configuration", "echo - display a line of predefined text", "exit - end the process", diff --git a/crates/whirl_prompt/src/builtins/mod.rs b/crates/whirl_prompt/src/builtins/mod.rs index 96a2c76a..59dbe485 100644 --- a/crates/whirl_prompt/src/builtins/mod.rs +++ b/crates/whirl_prompt/src/builtins/mod.rs @@ -106,3 +106,9 @@ pub fn builtin_fetch() -> i32 { 0 } + +pub fn builtin_clear() -> i32 { + println!("\x1B[2J\x1B[1;1H"); + + 0 +} diff --git a/crates/whirl_prompt/src/builtins/structures.rs b/crates/whirl_prompt/src/builtins/structures.rs index 39d3510f..48eebaae 100644 --- a/crates/whirl_prompt/src/builtins/structures.rs +++ b/crates/whirl_prompt/src/builtins/structures.rs @@ -13,6 +13,7 @@ pub enum BuiltIn { Cat, Config, Fetch, + Clear, } impl FromStr for BuiltIn { type Err = (); @@ -28,6 +29,7 @@ impl FromStr for BuiltIn { "cat" => Ok(Self::Cat), "config" => Ok(Self::Config), "fetch" => Ok(Self::Fetch), + "clear" => Ok(Self::Clear), _ => Err(()), } } diff --git a/crates/whirl_prompt/src/lib.rs b/crates/whirl_prompt/src/lib.rs index e2cafbbf..3da4840a 100644 --- a/crates/whirl_prompt/src/lib.rs +++ b/crates/whirl_prompt/src/lib.rs @@ -35,6 +35,7 @@ use whirl_config::Config; use crate::{ builtins::{ builtin_cat, + builtin_clear, builtin_config, builtin_echo, builtin_fetch, @@ -106,6 +107,7 @@ impl Prompt { Ok(BuiltIn::Cat) => builtin_cat(&c.args), Ok(BuiltIn::Config) => builtin_config(&c.args), Ok(BuiltIn::Fetch) => builtin_fetch(), + Ok(BuiltIn::Clear) => builtin_clear(), _ => { println!("wsh: command not found: {}", &c.keyword); 1