mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-11-28 15:56:28 +00:00
fix(status): Make status module work even when the status is 0 (#3750)
Co-authored-by: Izhak Jakov <jizhak@ca.ibm.com>
This commit is contained in:
parent
52fa4bbab4
commit
86953272a7
@ -3083,7 +3083,7 @@ format = '[📦 \[$env\]]($style) '
|
|||||||
## Status
|
## Status
|
||||||
|
|
||||||
The `status` module displays the exit code of the previous command.
|
The `status` module displays the exit code of the previous command.
|
||||||
The module will be shown only if the exit code is not `0`.
|
If $success_symbol is empty (default), the module will be shown only if the exit code is not `0`.
|
||||||
The status code will cast to a signed 32-bit integer.
|
The status code will cast to a signed 32-bit integer.
|
||||||
|
|
||||||
::: tip
|
::: tip
|
||||||
@ -3103,7 +3103,7 @@ This module is not supported on nu shell.
|
|||||||
| ----------------------- | ----------------------------------------------------------------------------- | ------------------------------------------------------- |
|
| ----------------------- | ----------------------------------------------------------------------------- | ------------------------------------------------------- |
|
||||||
| `format` | `"[$symbol$status]($style) "` | The format of the module |
|
| `format` | `"[$symbol$status]($style) "` | The format of the module |
|
||||||
| `symbol` | `"✖"` | The symbol displayed on program error |
|
| `symbol` | `"✖"` | The symbol displayed on program error |
|
||||||
| `success_symbol` | `"✔️"` | The symbol displayed on program success |
|
| `success_symbol` | `""` | The symbol displayed on program success |
|
||||||
| `not_executable_symbol` | `"🚫"` | The symbol displayed when file isn't executable |
|
| `not_executable_symbol` | `"🚫"` | The symbol displayed when file isn't executable |
|
||||||
| `not_found_symbol` | `"🔍"` | The symbol displayed when the command can't be found |
|
| `not_found_symbol` | `"🔍"` | The symbol displayed when the command can't be found |
|
||||||
| `sigint_symbol` | `"🧱"` | The symbol displayed on SIGINT (Ctrl + c) |
|
| `sigint_symbol` | `"🧱"` | The symbol displayed on SIGINT (Ctrl + c) |
|
||||||
@ -3140,8 +3140,9 @@ This module is not supported on nu shell.
|
|||||||
|
|
||||||
[status]
|
[status]
|
||||||
style = "bg:blue"
|
style = "bg:blue"
|
||||||
symbol = "🔴"
|
symbol = "🔴 "
|
||||||
format = '[\[$symbol $common_meaning$signal_name$maybe_int\]]($style) '
|
success_symbol = "🟢 SUCCESS"
|
||||||
|
format = '[\[$symbol$common_meaning$signal_name$maybe_int\]]($style) '
|
||||||
map_symbol = true
|
map_symbol = true
|
||||||
disabled = false
|
disabled = false
|
||||||
```
|
```
|
||||||
|
@ -26,7 +26,7 @@ impl<'a> Default for StatusConfig<'a> {
|
|||||||
StatusConfig {
|
StatusConfig {
|
||||||
format: "[$symbol$status]($style) ",
|
format: "[$symbol$status]($style) ",
|
||||||
symbol: "✖",
|
symbol: "✖",
|
||||||
success_symbol: "✔️",
|
success_symbol: "",
|
||||||
not_executable_symbol: "🚫",
|
not_executable_symbol: "🚫",
|
||||||
not_found_symbol: "🔍",
|
not_found_symbol: "🔍",
|
||||||
sigint_symbol: "🧱",
|
sigint_symbol: "🧱",
|
||||||
|
@ -17,7 +17,7 @@ enum PipeStatusStatus<'a> {
|
|||||||
|
|
||||||
/// Creates a module with the status of the last command
|
/// Creates a module with the status of the last command
|
||||||
///
|
///
|
||||||
/// Will display the status only if it is not 0
|
/// Will display the status
|
||||||
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||||
let mut module = context.new_module("status");
|
let mut module = context.new_module("status");
|
||||||
let config = StatusConfig::try_load(module.config);
|
let config = StatusConfig::try_load(module.config);
|
||||||
@ -43,8 +43,9 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
|||||||
false => PipeStatusStatus::Disabled,
|
false => PipeStatusStatus::Disabled,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Exit code is zero and pipestatus is all zero or disabled/missing
|
// Exit code is zero while success_symbol and pipestatus are all zero or disabled/missing
|
||||||
if exit_code == "0"
|
if exit_code == "0"
|
||||||
|
&& config.success_symbol.is_empty()
|
||||||
&& (match pipestatus_status {
|
&& (match pipestatus_status {
|
||||||
PipeStatusStatus::Pipe(ps) => ps.iter().all(|s| s == "0"),
|
PipeStatusStatus::Pipe(ps) => ps.iter().all(|s| s == "0"),
|
||||||
_ => true,
|
_ => true,
|
||||||
@ -176,7 +177,7 @@ fn status_common_meaning(ex: ExitCode) -> Option<&'static str> {
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
match ex {
|
match ex {
|
||||||
0 => Some(""),
|
0 => Some(""), // SUCCESS can be defined by $success_symbol if the user wishes too.
|
||||||
1 => Some("ERROR"),
|
1 => Some("ERROR"),
|
||||||
2 => Some("USAGE"),
|
2 => Some("USAGE"),
|
||||||
126 => Some("NOPERM"),
|
126 => Some("NOPERM"),
|
||||||
@ -228,13 +229,59 @@ mod tests {
|
|||||||
use crate::test::ModuleRenderer;
|
use crate::test::ModuleRenderer;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn success_status() {
|
fn success_status_success_symbol_empty() {
|
||||||
let expected = None;
|
let expected = None;
|
||||||
|
|
||||||
|
// Status code 0 and success_symbol = ""
|
||||||
|
let actual = ModuleRenderer::new("status")
|
||||||
|
.config(toml::toml! {
|
||||||
|
[status]
|
||||||
|
success_symbol = ""
|
||||||
|
disabled = false
|
||||||
|
})
|
||||||
|
.status(0)
|
||||||
|
.collect();
|
||||||
|
assert_eq!(expected, actual);
|
||||||
|
|
||||||
|
// Status code 0 and success_symbol is missing
|
||||||
|
let actual = ModuleRenderer::new("status")
|
||||||
|
.config(toml::toml! {
|
||||||
|
[status]
|
||||||
|
disabled = false
|
||||||
|
})
|
||||||
|
.status(0)
|
||||||
|
.collect();
|
||||||
|
assert_eq!(expected, actual);
|
||||||
|
|
||||||
|
// No status code and success_symbol = ""
|
||||||
|
let actual = ModuleRenderer::new("status")
|
||||||
|
.config(toml::toml! {
|
||||||
|
[status]
|
||||||
|
success_symbol = ""
|
||||||
|
disabled = false
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
assert_eq!(expected, actual);
|
||||||
|
|
||||||
|
// No status code and success_symbol is missing
|
||||||
|
let actual = ModuleRenderer::new("status")
|
||||||
|
.config(toml::toml! {
|
||||||
|
[status]
|
||||||
|
disabled = false
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
assert_eq!(expected, actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn success_status_success_symbol_filled() {
|
||||||
|
let expected = Some(format!("{} ", Color::Red.bold().paint("✔️0")));
|
||||||
|
|
||||||
// Status code 0
|
// Status code 0
|
||||||
let actual = ModuleRenderer::new("status")
|
let actual = ModuleRenderer::new("status")
|
||||||
.config(toml::toml! {
|
.config(toml::toml! {
|
||||||
[status]
|
[status]
|
||||||
|
success_symbol = "✔️"
|
||||||
disabled = false
|
disabled = false
|
||||||
})
|
})
|
||||||
.status(0)
|
.status(0)
|
||||||
@ -245,6 +292,7 @@ mod tests {
|
|||||||
let actual = ModuleRenderer::new("status")
|
let actual = ModuleRenderer::new("status")
|
||||||
.config(toml::toml! {
|
.config(toml::toml! {
|
||||||
[status]
|
[status]
|
||||||
|
success_symbol = "✔️"
|
||||||
disabled = false
|
disabled = false
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
Loading…
Reference in New Issue
Block a user