From 6922c6823ca9e29bf2a69e334bfd2c8a15740dc8 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Mon, 10 May 2021 16:11:52 -0700 Subject: feat(prompt): toggle prompt via configuration file Adds the ability to enable or disable the Whirl Shell from a `Whirl.toml` file. BREAKING CHANGE: `whirsplash.prompt.enable` configuration key created. closes #19 --- Whirl.toml.example | 3 +++ src/config/Whirl.default.toml | 3 +++ src/config/mod.rs | 8 ++++++++ src/subs.rs | 4 +++- 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Whirl.toml.example b/Whirl.toml.example index ed6a874..330a88b 100644 --- a/Whirl.toml.example +++ b/Whirl.toml.example @@ -5,6 +5,9 @@ ip = "0.0.0.0" # DO NOT CHANGE UNLESS YOU KNOW WHAT YOU ARE DOING prompt_ps1 = "[WORLDSMASTER@Whirlsplash ~]$" api.port = 8080 +[whirlsplash.prompt] +enable = false + [distributor] worldsmaster_greeting = "Welcome to Whirlsplash!" port = 6650 # DO NOT CHANGE UNLESS YOU KNOW WHAT YOU ARE DOING diff --git a/src/config/Whirl.default.toml b/src/config/Whirl.default.toml index ed6a874..330a88b 100644 --- a/src/config/Whirl.default.toml +++ b/src/config/Whirl.default.toml @@ -5,6 +5,9 @@ ip = "0.0.0.0" # DO NOT CHANGE UNLESS YOU KNOW WHAT YOU ARE DOING prompt_ps1 = "[WORLDSMASTER@Whirlsplash ~]$" api.port = 8080 +[whirlsplash.prompt] +enable = false + [distributor] worldsmaster_greeting = "Welcome to Whirlsplash!" port = 6650 # DO NOT CHANGE UNLESS YOU KNOW WHAT YOU ARE DOING diff --git a/src/config/mod.rs b/src/config/mod.rs index 6b50086..a71020d 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -10,12 +10,17 @@ pub struct WhirlsplashConfig { pub ip: String, pub prompt_ps1: String, pub api: WhirlsplashApiConfig, + pub prompt: WhirlsplashPromptConfig, } #[derive(Serialize, Deserialize, Debug)] pub struct WhirlsplashApiConfig { pub port: i64, } #[derive(Serialize, Deserialize, Debug)] +pub struct WhirlsplashPromptConfig { + pub enable: bool, +} +#[derive(Serialize, Deserialize, Debug)] pub struct DistributorConfig { pub worldsmaster_greeting: String, pub port: i64, @@ -62,6 +67,9 @@ impl Default for Config { api: WhirlsplashApiConfig { port: 80 }, + prompt: WhirlsplashPromptConfig { + enable: false + }, }, distributor: DistributorConfig { worldsmaster_greeting: "Welcome to Whirlsplash!".to_string(), diff --git a/src/subs.rs b/src/subs.rs index 0a7af5e..5ecf9bd 100644 --- a/src/subs.rs +++ b/src/subs.rs @@ -36,7 +36,9 @@ pub async fn run() -> ! { }), ]; - if std::env::var("DISABLE_PROMPT").unwrap_or_else(|_| "false".to_string()) == "true" { + if std::env::var("DISABLE_PROMPT").unwrap_or_else(|_| "false".to_string()) == "true" + || !Config::get().whirlsplash.prompt.enable + { info!("starting with prompt disabled"); loop { std::thread::sleep(std::time::Duration::default()); -- cgit v1.2.3