mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-11-10 15:20:55 +00:00
feat(shell): Add style config for shell module (#3108)
* add style config for shell module * update shell docs * fix formatting * update tests
This commit is contained in:
parent
e74f428615
commit
f8e81a1622
@ -2708,17 +2708,18 @@ To enable it, set `disabled` to `false` in your configuration file.
|
|||||||
### Options
|
### Options
|
||||||
|
|
||||||
| Option | Default | Description |
|
| Option | Default | Description |
|
||||||
| ---------------------- | --------------- | ------------------------------------------------------------ |
|
| ---------------------- | ------------------------- | ------------------------------------------------------------ |
|
||||||
| `bash_indicator` | `"bsh"` | A format string used to represent bash. |
|
| `bash_indicator` | `bsh` | A format string used to represent bash. |
|
||||||
| `fish_indicator` | `"fsh"` | A format string used to represent fish. |
|
| `fish_indicator` | `fsh` | A format string used to represent fish. |
|
||||||
| `zsh_indicator` | `"zsh"` | A format string used to represent zsh. |
|
| `zsh_indicator` | `zsh` | A format string used to represent zsh. |
|
||||||
| `powershell_indicator` | `"psh"` | A format string used to represent powershell. |
|
| `powershell_indicator` | `psh` | A format string used to represent powershell. |
|
||||||
| `ion_indicator` | `"ion"` | A format string used to represent ion. |
|
| `ion_indicator` | `ion` | A format string used to represent ion. |
|
||||||
| `elvish_indicator` | `"esh"` | A format string used to represent elvish. |
|
| `elvish_indicator` | `esh` | A format string used to represent elvish. |
|
||||||
| `tcsh_indicator` | `"tsh"` | A format string used to represent tcsh. |
|
| `tcsh_indicator` | `tsh` | A format string used to represent tcsh. |
|
||||||
| `xonsh_indicator` | `"xsh"` | A format string used to represent xonsh. |
|
| `xonsh_indicator` | `xsh` | A format string used to represent xonsh. |
|
||||||
| `unknown_indicator` | `""` | The default value to be displayed when the shell is unknown. |
|
| `unknown_indicator` | | The default value to be displayed when the shell is unknown. |
|
||||||
| `format` | `"$indicator "` | The format for the module. |
|
| `format` | `"[$indicator]($style) "` | The format for the module. |
|
||||||
|
| `style` | `"white bold"` | The style for the module. |
|
||||||
| `disabled` | `true` | Disables the `shell` module. |
|
| `disabled` | `true` | Disables the `shell` module. |
|
||||||
|
|
||||||
### Variables
|
### Variables
|
||||||
@ -2726,6 +2727,9 @@ To enable it, set `disabled` to `false` in your configuration file.
|
|||||||
| Variable | Default | Description |
|
| Variable | Default | Description |
|
||||||
| ----------- | ------- | ---------------------------------------------------------- |
|
| ----------- | ------- | ---------------------------------------------------------- |
|
||||||
| indicator | | Mirrors the value of `indicator` for currently used shell. |
|
| indicator | | Mirrors the value of `indicator` for currently used shell. |
|
||||||
|
| style\* | | Mirrors the value of option `style`. |
|
||||||
|
|
||||||
|
\*: This variable can only be used as a part of a style string
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
@ -2736,6 +2740,7 @@ To enable it, set `disabled` to `false` in your configuration file.
|
|||||||
fish_indicator = ""
|
fish_indicator = ""
|
||||||
powershell_indicator = "_"
|
powershell_indicator = "_"
|
||||||
unknown_indicator = "mystery shell"
|
unknown_indicator = "mystery shell"
|
||||||
|
style = "cyan bold"
|
||||||
disabled = false
|
disabled = false
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -16,13 +16,14 @@ pub struct ShellConfig<'a> {
|
|||||||
pub nu_indicator: &'a str,
|
pub nu_indicator: &'a str,
|
||||||
pub xonsh_indicator: &'a str,
|
pub xonsh_indicator: &'a str,
|
||||||
pub unknown_indicator: &'a str,
|
pub unknown_indicator: &'a str,
|
||||||
|
pub style: &'a str,
|
||||||
pub disabled: bool,
|
pub disabled: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Default for ShellConfig<'a> {
|
impl<'a> Default for ShellConfig<'a> {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
ShellConfig {
|
ShellConfig {
|
||||||
format: "$indicator ",
|
format: "[$indicator]($style) ",
|
||||||
bash_indicator: "bsh",
|
bash_indicator: "bsh",
|
||||||
fish_indicator: "fsh",
|
fish_indicator: "fsh",
|
||||||
zsh_indicator: "zsh",
|
zsh_indicator: "zsh",
|
||||||
@ -33,6 +34,7 @@ impl<'a> Default for ShellConfig<'a> {
|
|||||||
nu_indicator: "nu",
|
nu_indicator: "nu",
|
||||||
xonsh_indicator: "xsh",
|
xonsh_indicator: "xsh",
|
||||||
unknown_indicator: "",
|
unknown_indicator: "",
|
||||||
|
style: "white bold",
|
||||||
disabled: true,
|
disabled: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,10 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
|||||||
},
|
},
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
|
.map_style(|variable| match variable {
|
||||||
|
"style" => Some(Ok(config.style)),
|
||||||
|
_ => None,
|
||||||
|
})
|
||||||
.map(|var| match var {
|
.map(|var| match var {
|
||||||
"bash_indicator" => Some(Ok(config.bash_indicator)),
|
"bash_indicator" => Some(Ok(config.bash_indicator)),
|
||||||
"fish_indicator" => Some(Ok(config.fish_indicator)),
|
"fish_indicator" => Some(Ok(config.fish_indicator)),
|
||||||
@ -80,7 +84,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_bash_default_format() {
|
fn test_bash_default_format() {
|
||||||
let expected = Some(format!("{} ", "bsh"));
|
let expected = Some(format!("{} ", Color::White.bold().paint("bsh")));
|
||||||
let actual = ModuleRenderer::new("shell")
|
let actual = ModuleRenderer::new("shell")
|
||||||
.shell(Shell::Bash)
|
.shell(Shell::Bash)
|
||||||
.config(toml::toml! {
|
.config(toml::toml! {
|
||||||
@ -109,7 +113,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_fish_default_format() {
|
fn test_fish_default_format() {
|
||||||
let expected = Some(format!("{} ", "fsh"));
|
let expected = Some(format!("{} ", Color::White.bold().paint("fsh")));
|
||||||
let actual = ModuleRenderer::new("shell")
|
let actual = ModuleRenderer::new("shell")
|
||||||
.shell(Shell::Fish)
|
.shell(Shell::Fish)
|
||||||
.config(toml::toml! {
|
.config(toml::toml! {
|
||||||
@ -138,7 +142,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_zsh_default_format() {
|
fn test_zsh_default_format() {
|
||||||
let expected = Some(format!("{} ", "zsh"));
|
let expected = Some(format!("{} ", Color::White.bold().paint("zsh")));
|
||||||
let actual = ModuleRenderer::new("shell")
|
let actual = ModuleRenderer::new("shell")
|
||||||
.shell(Shell::Zsh)
|
.shell(Shell::Zsh)
|
||||||
.config(toml::toml! {
|
.config(toml::toml! {
|
||||||
@ -167,7 +171,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_powershell_default_format() {
|
fn test_powershell_default_format() {
|
||||||
let expected = Some(format!("{} ", "psh"));
|
let expected = Some(format!("{} ", Color::White.bold().paint("psh")));
|
||||||
let actual = ModuleRenderer::new("shell")
|
let actual = ModuleRenderer::new("shell")
|
||||||
.shell(Shell::PowerShell)
|
.shell(Shell::PowerShell)
|
||||||
.config(toml::toml! {
|
.config(toml::toml! {
|
||||||
@ -196,7 +200,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_ion_default_format() {
|
fn test_ion_default_format() {
|
||||||
let expected = Some(format!("{} ", "ion"));
|
let expected = Some(format!("{} ", Color::White.bold().paint("ion")));
|
||||||
let actual = ModuleRenderer::new("shell")
|
let actual = ModuleRenderer::new("shell")
|
||||||
.shell(Shell::Ion)
|
.shell(Shell::Ion)
|
||||||
.config(toml::toml! {
|
.config(toml::toml! {
|
||||||
@ -225,7 +229,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_elvish_default_format() {
|
fn test_elvish_default_format() {
|
||||||
let expected = Some(format!("{} ", "esh"));
|
let expected = Some(format!("{} ", Color::White.bold().paint("esh")));
|
||||||
let actual = ModuleRenderer::new("shell")
|
let actual = ModuleRenderer::new("shell")
|
||||||
.shell(Shell::Elvish)
|
.shell(Shell::Elvish)
|
||||||
.config(toml::toml! {
|
.config(toml::toml! {
|
||||||
@ -254,7 +258,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_nu_default_format() {
|
fn test_nu_default_format() {
|
||||||
let expected = Some(format!("{} ", "nu"));
|
let expected = Some(format!("{} ", Color::White.bold().paint("nu")));
|
||||||
let actual = ModuleRenderer::new("shell")
|
let actual = ModuleRenderer::new("shell")
|
||||||
.shell(Shell::Nu)
|
.shell(Shell::Nu)
|
||||||
.config(toml::toml! {
|
.config(toml::toml! {
|
||||||
@ -283,7 +287,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_xonsh_default_format() {
|
fn test_xonsh_default_format() {
|
||||||
let expected = Some(format!("{} ", "xsh"));
|
let expected = Some(format!("{} ", Color::White.bold().paint("xsh")));
|
||||||
let actual = ModuleRenderer::new("shell")
|
let actual = ModuleRenderer::new("shell")
|
||||||
.shell(Shell::Xonsh)
|
.shell(Shell::Xonsh)
|
||||||
.config(toml::toml! {
|
.config(toml::toml! {
|
||||||
@ -341,4 +345,35 @@ mod tests {
|
|||||||
|
|
||||||
assert_eq!(expected, actual);
|
assert_eq!(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_default_style() {
|
||||||
|
let expected = Some(format!("{}", Color::White.bold().paint("fish")));
|
||||||
|
let actual = ModuleRenderer::new("shell")
|
||||||
|
.shell(Shell::Fish)
|
||||||
|
.config(toml::toml! {
|
||||||
|
[shell]
|
||||||
|
format = "[fish]($style)"
|
||||||
|
disabled = false
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
assert_eq!(expected, actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_custom_style() {
|
||||||
|
let expected = Some(format!("{}", Color::Cyan.bold().paint("fish")));
|
||||||
|
let actual = ModuleRenderer::new("shell")
|
||||||
|
.shell(Shell::Fish)
|
||||||
|
.config(toml::toml! {
|
||||||
|
[shell]
|
||||||
|
format = "[fish]($style)"
|
||||||
|
style = "cyan bold"
|
||||||
|
disabled = false
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
assert_eq!(expected, actual);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user