From 9cf8e0df992084ce62aa60d0df21e1a5e343e901 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Sun, 16 May 2021 15:44:15 +0000 Subject: feat(builtins): add a neofetch like utility --- src/prompt/builtins.rs | 21 +++++++++++++++++++++ src/prompt/mod.rs | 2 ++ 2 files changed, 23 insertions(+) (limited to 'src') diff --git a/src/prompt/builtins.rs b/src/prompt/builtins.rs index 18a5f8e..d58005a 100644 --- a/src/prompt/builtins.rs +++ b/src/prompt/builtins.rs @@ -3,6 +3,8 @@ use std::{io::Write, str::FromStr}; +use sysinfo::SystemExt; + use crate::config::Config; const FILES: [&str; 2] = ["README.rst", "Whirl.toml"]; @@ -16,6 +18,7 @@ pub enum BuiltIn { Ls, Cat, Config, + Fetch, } impl FromStr for BuiltIn { type Err = (); @@ -30,6 +33,7 @@ impl FromStr for BuiltIn { "ls" => Ok(BuiltIn::Ls), "cat" => Ok(BuiltIn::Cat), "config" => Ok(BuiltIn::Config), + "fetch" => Ok(BuiltIn::Fetch), _ => Err(()), } } @@ -55,6 +59,7 @@ pub fn builtin_help() -> i32 { println!("cat - display the contents of a present file"); println!("config - manipulate the configuration"); println!("help - you are here"); + println!("fetch - a neofetch like utility loosely based on rfetch"); 0 } @@ -119,3 +124,19 @@ pub fn builtin_config(args: &[String]) -> i32 { } 0 } + +pub fn builtin_fetch() -> i32 { + // rfetch: https://github.com/Mangeshrex/rfetch + + let mut sys = sysinfo::System::new(); + sys.refresh_processes(); + + println!(" "); + println!(" .-. os {}", env!("CARGO_PKG_NAME")); + println!(" oo| ker {}", env!("CARGO_PKG_VERSION")); + println!(" / '\\ sh /wsh"); + println!(" (\\_;/) up null"); + println!(" "); + + 0 +} diff --git a/src/prompt/mod.rs b/src/prompt/mod.rs index 3deb4fe..990dd10 100644 --- a/src/prompt/mod.rs +++ b/src/prompt/mod.rs @@ -13,6 +13,7 @@ use crate::{ builtin_cat, builtin_config, builtin_echo, + builtin_fetch, builtin_help, builtin_history, builtin_ls, @@ -82,6 +83,7 @@ impl Prompt { Ok(BuiltIn::Ls) => builtin_ls(), Ok(BuiltIn::Cat) => builtin_cat(&c.args).await, Ok(BuiltIn::Config) => builtin_config(&c.args), + Ok(BuiltIn::Fetch) => builtin_fetch(), _ => { println!("wsh: command not found: {}", &c.keyword); 1 -- cgit v1.2.3