diff options
author | Barnaby Keene <accounts@southcla.ws> | 2019-10-20 09:26:27 +0100 |
---|---|---|
committer | Matan Kushner <hello@matchai.me> | 2019-10-20 17:26:27 +0900 |
commit | 2c7e01cd6221b60cc08d2e5873493c00817ee1b6 (patch) | |
tree | 39436a6b06ff4e506135ead8f1c0ad5bcdfee89f /src/modules | |
parent | 48cd6bc519d7f3c1da58a662f65220c552387b41 (diff) |
refactor: improve as-a-library usage by removing ArgMatches depeā¦ (#547)
This removes ArgMatches from the Context struct and replaces it with a simple HashMap. This work is towards getting Starship in a better place for use as a library in other shells written in Rust so they don't need to use a command-line interface to invoke and configure things.
Contributes to #521
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/character.rs | 11 | ||||
-rw-r--r-- | src/modules/cmd_duration.rs | 8 | ||||
-rw-r--r-- | src/modules/jobs.rs | 8 |
3 files changed, 15 insertions, 12 deletions
diff --git a/src/modules/character.rs b/src/modules/character.rs index 45f0c7102..cc9545172 100644 --- a/src/modules/character.rs +++ b/src/modules/character.rs @@ -22,17 +22,20 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> { let config: CharacterConfig = CharacterConfig::try_load(module.config); module.get_prefix().set_value(""); - let arguments = &context.arguments; - let exit_success = arguments.value_of("status_code").unwrap_or("0") == "0"; + let props = &context.properties; + let exit_code_default = std::string::String::from("0"); + let exit_code = props.get("status_code").unwrap_or(&exit_code_default); let shell = std::env::var("STARSHIP_SHELL").unwrap_or_default(); - let keymap = arguments.value_of("keymap").unwrap_or("viins"); + let keymap_default = std::string::String::from("viins"); + let keymap = props.get("keymap").unwrap_or(&keymap_default); + let exit_success = exit_code == "0"; // Match shell "keymap" names to normalized vi modes // NOTE: in vi mode, fish reports normal mode as "default". // Unfortunately, this is also the name of the non-vi default mode. // We do some environment detection in src/init.rs to translate. // The result: in non-vi fish, keymap is always reported as "insert" - let mode = match (shell.as_str(), keymap) { + let mode = match (shell.as_str(), keymap.as_str()) { ("fish", "default") | ("zsh", "vicmd") => ShellEditMode::Normal, _ => ASSUMED_MODE, }; diff --git a/src/modules/cmd_duration.rs b/src/modules/cmd_duration.rs index a0340cb0c..7b31c80c3 100644 --- a/src/modules/cmd_duration.rs +++ b/src/modules/cmd_duration.rs @@ -11,10 +11,10 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> { let mut module = context.new_module("cmd_duration"); let config: CmdDurationConfig = CmdDurationConfig::try_load(module.config); - let arguments = &context.arguments; - let elapsed = arguments - .value_of("cmd_duration") - .unwrap_or("invalid_time") + let props = &context.properties; + let elapsed = props + .get("cmd_duration") + .unwrap_or(&"invalid_time".into()) .parse::<u64>() .ok()?; diff --git a/src/modules/jobs.rs b/src/modules/jobs.rs index e0f2308df..f84c23af0 100644 --- a/src/modules/jobs.rs +++ b/src/modules/jobs.rs @@ -10,10 +10,10 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> { module.set_style(config.style); - let arguments = &context.arguments; - let num_of_jobs = arguments - .value_of("jobs") - .unwrap_or("0") + let props = &context.properties; + let num_of_jobs = props + .get("jobs") + .unwrap_or(&"0".into()) .trim() .parse::<i64>() .ok()?; |