Skip to content

Commit

Permalink
feat(prompt): create clear command
Browse files Browse the repository at this point in the history
  • Loading branch information
Fuwn committed Jun 16, 2021
1 parent 878fe71 commit 87e88a4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion crates/whirl_prompt/src/builtins/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions crates/whirl_prompt/src/builtins/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,9 @@ pub fn builtin_fetch() -> i32 {

0
}

pub fn builtin_clear() -> i32 {
println!("\x1B[2J\x1B[1;1H");

0
}
2 changes: 2 additions & 0 deletions crates/whirl_prompt/src/builtins/structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub enum BuiltIn {
Cat,
Config,
Fetch,
Clear,
}
impl FromStr for BuiltIn {
type Err = ();
Expand All @@ -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(()),
}
}
Expand Down
2 changes: 2 additions & 0 deletions crates/whirl_prompt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use whirl_config::Config;
use crate::{
builtins::{
builtin_cat,
builtin_clear,
builtin_config,
builtin_echo,
builtin_fetch,
Expand Down Expand Up @@ -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
Expand Down

1 comment on commit 87e88a4

@Fuwn
Copy link
Member Author

@Fuwn Fuwn commented on 87e88a4 Jun 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.