diff options
author | Zhenhui Xie <xiezh0831@yahoo.co.jp> | 2020-07-08 06:45:32 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-07 18:45:32 -0400 |
commit | ec76fafff08933f6f31fb99ea974bdb5ae97a0af (patch) | |
tree | bb2c822cdf291635f03d27677c419488ecf77f53 /src/configs | |
parent | 0f52b7b12e8c1a2060aa873a68032937dfa2c044 (diff) |
feat: refactor modules to use format strings (#1374)
Diffstat (limited to 'src/configs')
42 files changed, 392 insertions, 504 deletions
diff --git a/src/configs/aws.rs b/src/configs/aws.rs index 228558a24..89a9d871d 100644 --- a/src/configs/aws.rs +++ b/src/configs/aws.rs @@ -1,48 +1,24 @@ -use crate::config::{ModuleConfig, RootModuleConfig, SegmentConfig}; -use std::collections::HashMap; - -use ansi_term::{Color, Style}; +use crate::config::{ModuleConfig, RootModuleConfig}; use starship_module_config_derive::ModuleConfig; - -#[derive(Clone, PartialEq)] -pub enum AwsItems { - All, - Region, - Profile, -} +use std::collections::HashMap; #[derive(Clone, ModuleConfig)] pub struct AwsConfig<'a> { - pub symbol: SegmentConfig<'a>, - pub profile: SegmentConfig<'a>, - pub region: SegmentConfig<'a>, - pub style: Style, + pub format: &'a str, + pub symbol: &'a str, + pub style: &'a str, pub disabled: bool, - pub displayed_items: AwsItems, pub region_aliases: HashMap<String, &'a str>, } impl<'a> RootModuleConfig<'a> for AwsConfig<'a> { fn new() -> Self { AwsConfig { - symbol: SegmentConfig::new("☁️ "), - profile: SegmentConfig::default(), - region: SegmentConfig::default(), - style: Color::Yellow.bold(), + format: "on [$symbol$profile(\\($region\\))]($style) ", + symbol: "☁️ ", + style: "bold yellow", disabled: false, - displayed_items: AwsItems::All, region_aliases: HashMap::new(), } } } - -impl<'a> ModuleConfig<'a> for AwsItems { - fn from_config(config: &toml::Value) -> Option<Self> { - match config.as_str()? { - "all" => Some(AwsItems::All), - "region" => Some(AwsItems::Region), - "profile" => Some(AwsItems::Profile), - _ => None, - } - } -} diff --git a/src/configs/battery.rs b/src/configs/battery.rs index d86227d79..ec7287705 100644 --- a/src/configs/battery.rs +++ b/src/configs/battery.rs @@ -1,40 +1,39 @@ -use crate::config::{ModuleConfig, RootModuleConfig, SegmentConfig}; +use crate::config::{ModuleConfig, RootModuleConfig}; -use ansi_term::{Color, Style}; use starship_module_config_derive::ModuleConfig; #[derive(Clone, ModuleConfig)] pub struct BatteryConfig<'a> { - pub full_symbol: SegmentConfig<'a>, - pub charging_symbol: SegmentConfig<'a>, - pub discharging_symbol: SegmentConfig<'a>, - pub unknown_symbol: Option<SegmentConfig<'a>>, - pub empty_symbol: Option<SegmentConfig<'a>>, - pub display: Vec<BatteryDisplayConfig>, + pub full_symbol: &'a str, + pub charging_symbol: &'a str, + pub discharging_symbol: &'a str, + pub unknown_symbol: Option<&'a str>, + pub empty_symbol: Option<&'a str>, + pub display: Vec<BatteryDisplayConfig<'a>>, pub disabled: bool, - pub percentage: SegmentConfig<'a>, + pub format: &'a str, } impl<'a> RootModuleConfig<'a> for BatteryConfig<'a> { fn new() -> Self { BatteryConfig { - full_symbol: SegmentConfig::new("•"), - charging_symbol: SegmentConfig::new("↑"), - discharging_symbol: SegmentConfig::new("↓"), + full_symbol: "•", + charging_symbol: "↑", + discharging_symbol: "↓", unknown_symbol: None, empty_symbol: None, + format: "[$symbol$percentage]($style) ", display: vec![BatteryDisplayConfig { threshold: 10, - style: Color::Red.bold(), + style: "red bold", }], disabled: false, - percentage: SegmentConfig::default(), } } } #[derive(Clone, ModuleConfig)] -pub struct BatteryDisplayConfig { +pub struct BatteryDisplayConfig<'a> { pub threshold: i64, - pub style: Style, + pub style: &'a str, } diff --git a/src/configs/character.rs b/src/configs/character.rs index 92f977ebb..7486890e7 100644 --- a/src/configs/character.rs +++ b/src/configs/character.rs @@ -1,28 +1,23 @@ -use crate::config::{ModuleConfig, RootModuleConfig, SegmentConfig}; +use crate::config::{ModuleConfig, RootModuleConfig}; -use ansi_term::{Color, Style}; use starship_module_config_derive::ModuleConfig; #[derive(Clone, ModuleConfig)] pub struct CharacterConfig<'a> { - pub symbol: SegmentConfig<'a>, - pub error_symbol: SegmentConfig<'a>, - pub vicmd_symbol: SegmentConfig<'a>, - pub use_symbol_for_status: bool, - pub style_success: Style, - pub style_failure: Style, + pub format: &'a str, + pub success_symbol: &'a str, + pub error_symbol: &'a str, + pub vicmd_symbol: &'a str, pub disabled: bool, } impl<'a> RootModuleConfig<'a> for CharacterConfig<'a> { fn new() -> Self { CharacterConfig { - symbol: SegmentConfig::new("❯"), - error_symbol: SegmentConfig::new("✖"), - vicmd_symbol: SegmentConfig::new("❮"), - use_symbol_for_status: false, - style_success: Color::Green.bold(), - style_failure: Color::Red.bold(), + format: "$symbol ", + success_symbol: "[❯](bold green)", + error_symbol: "[❯](bold red)", + vicmd_symbol: "[❮](bold green)", disabled: false, } } diff --git a/src/configs/cmd_duration.rs b/src/configs/cmd_duration.rs index f60390158..e7e8c3855 100644 --- a/src/configs/cmd_duration.rs +++ b/src/configs/cmd_duration.rs @@ -1,13 +1,12 @@ use crate::config::{ModuleConfig, RootModuleConfig}; -use ansi_term::{Color, Style}; use starship_module_config_derive::ModuleConfig; #[derive(Clone, ModuleConfig)] pub struct CmdDurationConfig<'a> { pub min_time: i64, - pub prefix: &'a str, - pub style: Style, + pub format: &'a str, + pub style: &'a str, pub show_milliseconds: bool, pub disabled: bool, } @@ -16,9 +15,9 @@ impl<'a> RootModuleConfig<'a> for CmdDurationConfig<'a> { fn new() -> Self { CmdDurationConfig { min_time: 2_000, - prefix: "took ", + format: "took [$duration]($style) ", show_milliseconds: false, - style: Color::Yellow.bold(), + style: "yellow bold", disabled: false, } } diff --git a/src/configs/conda.rs b/src/configs/conda.rs index 8e3f75a22..f05c5bc17 100644 --- a/src/configs/conda.rs +++ b/src/configs/conda.rs @@ -1,14 +1,13 @@ -use crate::config::{ModuleConfig, RootModuleConfig, SegmentConfig}; +use crate::config::{ModuleConfig, RootModuleConfig}; -use ansi_term::{Color, Style}; use starship_module_config_derive::ModuleConfig; #[derive(Clone, ModuleConfig)] pub struct CondaConfig<'a> { pub truncation_length: usize, - pub symbol: SegmentConfig<'a>, - pub environment: SegmentConfig<'a>, - pub style: Style, + pub format: &'a str, + pub symbol: &'a str, + pub style: &'a str, pub disabled: bool, } @@ -16,15 +15,9 @@ impl<'a> RootModuleConfig<'a> for CondaConfig<'a> { fn new() -> Self { CondaConfig { truncation_length: 1, - symbol: SegmentConfig { - value: "C ", - style: None, - }, - environment: SegmentConfig { - value: "", - style: None, - }, - style: Color::Green.bold(), + format: "via [$symbol$environment]($style) ", + symbol: "🅒 ", + style: "green bold", disabled: false, } } diff --git a/src/configs/crystal.rs b/src/configs/crystal.rs index 58455e8e5..6d342253b 100644 --- a/src/configs/crystal.rs +++ b/src/configs/crystal.rs @@ -1,20 +1,21 @@ -use crate::config::{ModuleConfig, RootModuleConfig, SegmentConfig}; +use crate::config::{ModuleConfig, RootModuleConfig}; -use ansi_term::{Color, Style}; use starship_module_config_derive::ModuleConfig; #[derive(Clone, ModuleConfig)] pub struct CrystalConfig<'a> { - pub symbol: SegmentConfig<'a>, - pub style: Style, + pub format: &'a str, + pub symbol: &'a str, + pub style: &'a str, pub disabled: bool, } impl<'a> RootModuleConfig<'a> for CrystalConfig<'a> { fn new() -> Self { CrystalConfig { - symbol: SegmentConfig::new("🔮 "), - style: Color::Red.bold(), + format: "via [$symbol$version]($style) ", + symbol: "🔮 ", + style: "bold red", disabled: false, } } diff --git a/src/configs/custom.rs b/src/configs/custom.rs index 621b39809..31317f1cc 100644 --- a/src/configs/custom.rs +++ b/src/configs/custom.rs @@ -1,6 +1,5 @@ -use crate::config::{ModuleConfig, RootModuleConfig, SegmentConfig, VecOr}; +use crate::config::{ModuleConfig, RootModuleConfig, VecOr}; -use ansi_term::Style; use starship_module_config_derive::ModuleConfig; #[derive(Clone, Default, PartialEq)] @@ -14,15 +13,14 @@ pub struct Directories<'a>(pub Vec<&'a str>); #[derive(Clone, ModuleConfig)] pub struct CustomConfig<'a> { - pub symbol: Option<SegmentConfig<'a>>, + pub format: &'a str, + pub symbol: &'a str, pub command: &'a str, pub when: Option<&'a str>, pub shell: VecOr<&'a str>, pub description: &'a str, - pub style: Option<Style>, + pub style: &'a str, pub disabled: bool, - pub prefix: Option<&'a str>, - pub suffix: Option<&'a str>, pub files: Files<'a>, pub extensions: Extensions<'a>, pub directories: Directories<'a>, @@ -31,15 +29,14 @@ pub struct CustomConfig<'a> { impl<'a> RootModuleConfig<'a> for CustomConfig<'a> { fn new() -> Self { CustomConfig { - symbol: None, + format: "[$symbol$output]($style) ", + symbol: "", command: "", when: None, shell: VecOr::default(), description: "<custom config>", - style: None, + style: "green bold", disabled: false, - prefix: None, - suffix: None, files: Files::default(), extensions: Extensions::default(), directories: Directories::default(), diff --git a/src/configs/directory.rs b/src/configs/directory.rs index 9c6aaf26e..7dd1c5793 100644 --- a/src/configs/directory.rs +++ b/src/configs/directory.rs @@ -1,7 +1,6 @@ use crate::config::{ModuleConfig, RootModuleConfig}; use std::collections::HashMap; -use ansi_term::{Color, Style}; use starship_module_config_derive::ModuleConfig; #[derive(Clone, ModuleConfig)] @@ -11,8 +10,8 @@ pub struct DirectoryConfig<'a> { pub substitutions: HashMap<String, &'a str>, pub fish_style_pwd_dir_length: i64, pub use_logical_path: bool, - pub prefix: &'a str, - pub style: Style, + pub format: &'a str, + pub style: &'a str, pub disabled: bool, } @@ -24,8 +23,8 @@ impl<'a> RootModuleConfig<'a> for DirectoryConfig<'a> { fish_style_pwd_dir_length: 0, substitutions: HashMap::new(), use_logical_path: true, - prefix: "in ", - style: Color::Cyan.bold(), + format: "[$path]($style) ", + style: "cyan bold", disabled: false, } } diff --git a/src/configs/docker_context.rs b/src/configs/docker_context.rs index 79be04294..9aa5fba8c 100644 --- a/src/configs/docker_context.rs +++ b/src/configs/docker_context.rs @@ -1,13 +1,12 @@ -use crate::config::{ModuleConfig, RootModuleConfig, SegmentConfig}; +use crate::config::{ModuleConfig, RootModuleConfig}; -use ansi_term::{Color, Style}; use starship_module_config_derive::ModuleConfig; #[derive(Clone, ModuleConfig)] pub struct DockerContextConfig<'a> { - pub symbol: SegmentConfig<'a>, - pub context: SegmentConfig<'a>, - pub style: Style, + pub symbol: &'a str, + pub style: &'a str, + pub format: &'a str, pub only_with_files: bool, pub disabled: bool, } @@ -15,9 +14,9 @@ pub struct DockerContextConfig<'a> { impl<'a> RootModuleConfig<'a> for DockerContextConfig<'a> { fn new() -> Self { DockerContextConfig { - symbol: SegmentConfig::new("🐳 "), - context: SegmentConfig::default(), - style: Color::Blue.bold(), + symbol: "🐳 ", + style: "blue bold", + format: "via [$symbol$context]($style) ", only_with_files: true, disabled: false, } diff --git a/src/configs/dotnet.rs b/src/configs/dotnet.rs index f6bb59e40..df5018702 100644 --- a/src/configs/dotnet.rs +++ b/src/configs/dotnet.rs @@ -1,25 +1,24 @@ -use crate::config::{ModuleConfig, RootModuleConfig, SegmentConfig}; - -use ansi_term::{Color, Style}; -use starship_module_config_derive::ModuleConfig; - -#[derive(Clone, ModuleConfig)] -pub struct DotnetConfig<'a> { - pub symbol: SegmentConfig<'a>, - pub version: SegmentConfig<'a>, - pub style: Style, - pub heuristic: bool, - pub disabled: bool, -} - -impl<'a> RootModuleConfig<'a> for DotnetConfig<'a> { - fn new() -> Self { - DotnetConfig { - symbol: SegmentConfig::new("•NET "), - version: SegmentConfig::default(), - style: Color::Blue.bold(), - heuristic: true, - disabled: false, - } - } -} +use crate::config::{ModuleConfig, RootModuleConfig};
+
+use starship_module_config_derive::ModuleConfig;
+
+#[derive(Clone, ModuleConfig)]
+pub struct DotnetConfig<'a> {
+ pub format: &'a str,
+ pub symbol: &'a str,
+ pub style: &'a str,
+ pub heuristic: bool,
+ pub disabled: bool,
+}
+
+impl<'a> RootModuleConfig<'a> for DotnetConfig<'a> {
+ fn new() -> Self {
+ DotnetConfig {
+ format: "[$symbol$version( 🎯 $tfm)]($style) ",
+ symbol: "•NET ",
+ style: "blue bold",
+ heuristic: true,
+ disabled: false,
+ }
+ }
+}
diff --git a/src/configs/elixir.rs b/src/configs/elixir.rs index cb9d701e4..21a99cc90 100644 --- a/src/configs/elixir.rs +++ b/src/configs/elixir.rs @@ -1,24 +1,21 @@ -use crate::config::{ModuleConfig, RootModuleConfig, SegmentConfig}; +use crate::config::{ModuleConfig, RootModuleConfig}; -use ansi_term::{Color, Style}; use starship_module_config_derive::ModuleConfig; #[derive(Clone, ModuleConfig)] pub struct ElixirConfig<'a> { - pub symbol: SegmentConfig<'a>, - pub version: SegmentConfig<'a>, - pub otp_version: SegmentConfig<'a>, - pub style: Style, + pub format: &'a str, + pub symbol: &'a str, + pub style: &'a str, pub disabled: bool, } impl<'a> RootModuleConfig<'a> for ElixirConfig<'a> { fn new() -> Self { ElixirConfig { - symbol: SegmentConfig::new("💧 "), - version: SegmentConfig::default(), - otp_version: SegmentConfig::default(), - style: Color::Purple.bold(), + format: "via [$symbol$version \\(OTP $otp_version\\)]($style) ", + symbol: "💧 ", + style: "bold purple", disabled: false, } } diff --git a/src/configs/elm.rs b/src/configs/elm.rs index 5c8e9a968..b88b2edea 100644 --- a/src/configs/elm.rs +++ b/src/configs/elm.rs @@ -1,22 +1,21 @@ -use crate::config::{ModuleConfig, RootModuleConfig, SegmentConfig}; +use crate::config::{ModuleConfig, RootModuleConfig}; -use ansi_term::{Color, Style}; use starship_module_config_derive::ModuleConfig; #[derive(Clone, ModuleConfig)] pub struct ElmConfig<'a> { - pub symbol: SegmentConfig<'a>, - pub version: SegmentConfig<'a>, - pub style: Style, + pub format: &'a str, + pub symbol: &'a str, + pub style: &'a str, pub disabled: bool, } impl<'a> RootModuleConfig<'a> for ElmConfig<'a> { fn new() -> Self { ElmConfig { - symbol: SegmentConfig::new("🌳 "), - version: SegmentConfig::default(), - style: Color::Cyan.bold(), + format: "via [$symbol$version]($style) ", + symbol: "🌳 ", + style: "cyan bold", disabled: false, } } diff --git a/src/configs/env_var.rs b/src/configs/env_var.rs index fc4e6533f..09635aaf7 100644 --- a/src/configs/env_var.rs +++ b/src/configs/env_var.rs @@ -1,28 +1,25 @@ -use crate::config::{ModuleConfig, RootModuleConfig, SegmentConfig}; +use crate::config::{ModuleConfig, RootModuleConfig}; -use ansi_term::{Color, Style}; use starship_module_config_derive::ModuleConfig; #[derive(Clone, ModuleConfig)] pub struct EnvVarConfig<'a> { - pub symbol: Option<SegmentConfig<'a>>, + pub symbol: &'a str, + pub style: &'a str, pub variable: Option<&'a str>, pub default: Option<&'a str>, - pub prefix: &'a str, - pub suffix: &'a str, - pub style: Style, + pub format: &'a str, pub disabled: bool, } impl<'a> RootModuleConfig<'a> for EnvVarConfig<'a> { fn new() -> Self { EnvVarConfig { - symbol: None, + symbol: "", + style: "black bold dimmed", variable: None, default: None, - prefix: "", - suffix: "", - style: Color::Black.bold().dimmed(), + format: "with [$env_value]($style) ", disabled: false, } } diff --git a/src/configs/erlang.rs b/src/configs/erlang.rs index bad77580f..4fd1b729a 100644 --- a/src/configs/erlang.rs +++ b/src/configs/erlang.rs @@ -1,22 +1,21 @@ -use crate::config::{ModuleConfig, RootModuleConfig, SegmentConfig}; +use crate::config::{ModuleConfig, RootModuleConfig}; -use ansi_term::{Color, Style}; use starship_module_config_derive::ModuleConfig; #[derive(Clone, ModuleConfig)] pub struct ErlangConfig<'a> { - pub symbol: SegmentConfig<'a>, - pub version: SegmentConfig<'a>, - pub style: Style, + pub format: &'a str, + pub symbol: &'a str, + pub style: &'a str, pub disabled: bool, } impl<'a> RootModuleConfig<'a> for ErlangConfig<'a> { fn new() -> Self { ErlangConfig { - symbol: SegmentConfig::new("🖧 "), - version: SegmentConfig::default(), - style: Color::Red.bold(), + format: "via [$symbol$version]($style) ", + symbol: "🖧 ", + style: "bold red", disabled: false, } } diff --git a/src/configs/git_branch.rs b/src/configs/git_branch.rs index ff6d87b28..352647986 100644 --- a/src/configs/git_branch.rs +++ b/src/configs/git_branch.rs @@ -1,26 +1,25 @@ -use crate::config::{ModuleConfig, RootModuleConfig, SegmentConfig}; +use crate::config::{ModuleConfig, RootModuleConfig}; -use ansi_term::{Color, Style}; use starship_module_config_derive::ModuleConfig; #[derive(Clone, ModuleConfig)] pub struct GitBranchConfig<'a> { - pub symbol: SegmentConfig<'a>, + pub format: &'a str, + pub symbol: &'a str, + pub style: &'a str, pub truncation_length: i64, pub truncation_symbol: &'a str, - pub branch_name: SegmentConfig<'a>, - pub style: Style, pub disabled: bool, } impl<'a> RootModuleConfig<'a> for GitBranchConfig<'a> { fn new() -> Self { GitBranchConfig { - symbol: SegmentConfig::new(" "), + format: "on [$symbol$branch]($style) ", + symbol: " ", + style: "bold purple", truncation_length: std::i64::MAX, truncation_symbol: "…", - branch_name: SegmentConfig::default(), - style: Color::Purple.bold(), disabled: false, } } diff --git a/src/configs/git_commit.rs b/src/configs/git_commit.rs index 2efe0e3fb..4a9ec22af 100644 --- a/src/configs/git_commit.rs +++ b/src/configs/git_commit.rs @@ -1,15 +1,12 @@ -use crate::config::{ModuleConfig, RootModuleConfig, SegmentConfig}; +use crate::config::{ModuleConfig, RootModuleConfig}; -use ansi_term::{Color, Style}; use starship_module_config_derive::ModuleConfig; #[derive(Clone, ModuleConfig)] pub struct GitCommitConfig<'a> { pub commit_hash_length: usize, - pub hash: SegmentConfig<'a>, - pub prefix: &'a str, - pub suffix: &'a str, - pub style: Style, + pub format: &'a str, + pub style: &'a str, pub only_detached: bool, pub disabled: bool, } @@ -19,10 +16,8 @@ impl<'a> RootModuleConfig<'a> for GitCommitConfig<'a> { GitCommitConfig { // be consistent with git by default, which has DEFAULT_ABBREV set to 7 commit_hash_length: 7, - hash: SegmentConfig::default(), - prefix: "(", - suffix: ") ", - style: Color::Green.bold(), + format: "[\\($hash\\)]($style) ", + style: "green bold", only_detached: true, disabled: false, } diff --git a/src/configs/git_state.rs b/src/configs/git_state.rs index c528e4e6e..f056f53ed 100644 --- a/src/configs/git_state.rs +++ b/src/configs/git_state.rs @@ -1,34 +1,33 @@ -use crate::config::{ModuleConfig, RootModuleConfig, SegmentConfig}; +use crate::config::{ModuleConfig, RootModuleConfig}; -use ansi_term::{Color, Style}; use starship_module_config_derive::ModuleConfig; #[derive(Clone, ModuleConfig)] < |