2021-07-28 16:26:00 +00:00
|
|
|
|
use std::string::ToString;
|
|
|
|
|
|
2022-03-26 09:42:19 +00:00
|
|
|
|
use super::{Context, Module, ModuleConfig};
|
2020-09-25 22:04:51 +00:00
|
|
|
|
|
|
|
|
|
use crate::configs::status::StatusConfig;
|
2021-07-28 16:26:00 +00:00
|
|
|
|
use crate::formatter::{string_formatter::StringFormatterError, StringFormatter};
|
|
|
|
|
use crate::segment::Segment;
|
2020-09-25 22:04:51 +00:00
|
|
|
|
|
2022-02-05 20:13:42 +00:00
|
|
|
|
type ExitCode = i32;
|
2021-01-03 03:09:13 +00:00
|
|
|
|
type SignalNumber = u32;
|
2021-07-28 16:26:00 +00:00
|
|
|
|
#[derive(PartialEq)]
|
|
|
|
|
enum PipeStatusStatus<'a> {
|
|
|
|
|
Disabled,
|
|
|
|
|
NoPipe,
|
|
|
|
|
Pipe(&'a Vec<std::string::String>),
|
|
|
|
|
}
|
2021-01-03 03:09:13 +00:00
|
|
|
|
|
2020-09-25 22:04:51 +00:00
|
|
|
|
/// Creates a module with the status of the last command
|
|
|
|
|
///
|
2022-03-16 20:05:13 +00:00
|
|
|
|
/// Will display the status
|
2020-09-25 22:04:51 +00:00
|
|
|
|
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
2021-09-01 22:18:44 +00:00
|
|
|
|
let mut module = context.new_module("status");
|
|
|
|
|
let config = StatusConfig::try_load(module.config);
|
|
|
|
|
|
|
|
|
|
// As we default to disabled=true, we have to check here after loading our config module,
|
|
|
|
|
// before it was only checking against whatever is in the config starship.toml
|
|
|
|
|
if config.disabled {
|
|
|
|
|
return None;
|
|
|
|
|
};
|
|
|
|
|
|
2022-01-15 09:21:38 +00:00
|
|
|
|
let exit_code = context.properties.status_code.as_deref().unwrap_or("0");
|
2020-09-25 22:04:51 +00:00
|
|
|
|
|
2022-01-15 09:21:38 +00:00
|
|
|
|
let pipestatus_status = match &context.properties.pipestatus {
|
2021-07-28 16:26:00 +00:00
|
|
|
|
None => PipeStatusStatus::Disabled,
|
|
|
|
|
Some(ps) => match ps.len() > 1 {
|
2021-07-29 18:27:46 +00:00
|
|
|
|
true => PipeStatusStatus::Pipe(ps),
|
2021-07-28 16:26:00 +00:00
|
|
|
|
false => PipeStatusStatus::NoPipe,
|
|
|
|
|
},
|
|
|
|
|
};
|
2021-09-01 22:18:44 +00:00
|
|
|
|
|
|
|
|
|
let pipestatus_status = match config.pipestatus {
|
|
|
|
|
true => pipestatus_status,
|
|
|
|
|
false => PipeStatusStatus::Disabled,
|
|
|
|
|
};
|
|
|
|
|
|
2022-03-16 20:05:13 +00:00
|
|
|
|
// Exit code is zero while success_symbol and pipestatus are all zero or disabled/missing
|
2022-01-15 09:21:38 +00:00
|
|
|
|
if exit_code == "0"
|
2022-03-16 20:05:13 +00:00
|
|
|
|
&& config.success_symbol.is_empty()
|
2021-10-03 14:03:09 +00:00
|
|
|
|
&& (match pipestatus_status {
|
|
|
|
|
PipeStatusStatus::Pipe(ps) => ps.iter().all(|s| s == "0"),
|
|
|
|
|
_ => true,
|
|
|
|
|
})
|
2021-07-28 16:26:00 +00:00
|
|
|
|
{
|
|
|
|
|
return None;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-19 13:07:50 +00:00
|
|
|
|
let segment_format = config.pipestatus_segment_format.unwrap_or(config.format);
|
2022-10-07 09:44:14 +00:00
|
|
|
|
let segment_format_with_separator = [segment_format, config.pipestatus_separator].join("");
|
2022-07-19 13:07:50 +00:00
|
|
|
|
|
2024-03-20 21:58:33 +00:00
|
|
|
|
// Create pipestatus segments
|
2021-07-28 16:26:00 +00:00
|
|
|
|
let pipestatus = match pipestatus_status {
|
2024-03-20 21:58:33 +00:00
|
|
|
|
PipeStatusStatus::Pipe(ps) => ps
|
2021-07-28 16:26:00 +00:00
|
|
|
|
.iter()
|
2022-10-07 09:44:14 +00:00
|
|
|
|
.enumerate()
|
|
|
|
|
.filter_map(|(i, ec)| {
|
2024-03-20 21:58:33 +00:00
|
|
|
|
let formatted = format_exit_code(
|
2022-10-07 09:44:14 +00:00
|
|
|
|
ec.as_str(),
|
2024-03-20 21:58:33 +00:00
|
|
|
|
if i == ps.len() - 1 {
|
2022-10-07 09:44:14 +00:00
|
|
|
|
segment_format
|
|
|
|
|
} else {
|
|
|
|
|
&segment_format_with_separator
|
|
|
|
|
},
|
|
|
|
|
None,
|
|
|
|
|
&config,
|
|
|
|
|
context,
|
2024-03-20 21:58:33 +00:00
|
|
|
|
);
|
|
|
|
|
match formatted {
|
|
|
|
|
Ok(segments) => Some(segments),
|
|
|
|
|
Err(e) => {
|
|
|
|
|
log::warn!("Error parsing format string in `status.pipestatus_segment_format`: {e:?}");
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-10-07 09:44:14 +00:00
|
|
|
|
})
|
|
|
|
|
.flatten()
|
2024-03-20 21:58:33 +00:00
|
|
|
|
.collect(),
|
|
|
|
|
_ => Vec::new(),
|
2021-07-28 16:26:00 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let main_format = match pipestatus_status {
|
|
|
|
|
PipeStatusStatus::Pipe(_) => config.pipestatus_format,
|
|
|
|
|
_ => config.format,
|
|
|
|
|
};
|
2024-03-20 21:58:33 +00:00
|
|
|
|
let parsed = format_exit_code(exit_code, main_format, Some(pipestatus), &config, context);
|
2021-07-28 16:26:00 +00:00
|
|
|
|
|
|
|
|
|
module.set_segments(match parsed {
|
|
|
|
|
Ok(segments) => segments,
|
|
|
|
|
Err(_error) => {
|
|
|
|
|
log::warn!("Error parsing format string in `status.format`");
|
2020-09-25 22:04:51 +00:00
|
|
|
|
return None;
|
2021-07-28 16:26:00 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
Some(module)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn format_exit_code<'a>(
|
|
|
|
|
exit_code: &'a str,
|
|
|
|
|
format: &'a str,
|
2024-03-20 21:58:33 +00:00
|
|
|
|
pipestatus: Option<Vec<Segment>>,
|
2021-07-28 16:26:00 +00:00
|
|
|
|
config: &'a StatusConfig,
|
2021-11-01 21:18:45 +00:00
|
|
|
|
context: &'a Context,
|
2021-07-28 16:26:00 +00:00
|
|
|
|
) -> Result<Vec<Segment>, StringFormatterError> {
|
2022-02-05 20:13:42 +00:00
|
|
|
|
// First, parse as i64 to accept both i32 or u32, then normalize to i32.
|
|
|
|
|
let exit_code_int: ExitCode = match exit_code.parse::<i64>() {
|
|
|
|
|
Ok(i) => i as ExitCode,
|
2021-07-28 16:26:00 +00:00
|
|
|
|
Err(_) => {
|
|
|
|
|
log::warn!("Error parsing exit_code string to int");
|
|
|
|
|
return Ok(Vec::new());
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2022-11-05 11:40:46 +00:00
|
|
|
|
let hex_status = format!("0x{exit_code_int:X}");
|
2021-12-21 10:05:28 +00:00
|
|
|
|
|
2021-07-28 16:26:00 +00:00
|
|
|
|
let common_meaning = status_common_meaning(exit_code_int);
|
|
|
|
|
|
|
|
|
|
let raw_signal_number = match config.recognize_signal_code {
|
|
|
|
|
true => status_to_signal(exit_code_int),
|
|
|
|
|
false => None,
|
|
|
|
|
};
|
|
|
|
|
let signal_number = raw_signal_number.map(|sn| sn.to_string());
|
2022-02-25 04:31:01 +00:00
|
|
|
|
let signal_name =
|
|
|
|
|
raw_signal_number.and_then(|sn| status_signal_name(sn).or(signal_number.as_deref()));
|
2021-07-28 16:26:00 +00:00
|
|
|
|
|
|
|
|
|
// If not a signal and not a common meaning, it should at least print the raw exit code number
|
|
|
|
|
let maybe_exit_code_number = match common_meaning.is_none() && signal_name.is_none() {
|
|
|
|
|
true => Some(exit_code),
|
|
|
|
|
false => None,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
StringFormatter::new(format).and_then(|formatter| {
|
|
|
|
|
formatter
|
|
|
|
|
.map_meta(|var, _| match var {
|
|
|
|
|
"symbol" => match exit_code_int {
|
|
|
|
|
0 => Some(config.success_symbol),
|
|
|
|
|
126 if config.map_symbol => Some(config.not_executable_symbol),
|
|
|
|
|
127 if config.map_symbol => Some(config.not_found_symbol),
|
|
|
|
|
130 if config.recognize_signal_code && config.map_symbol => {
|
|
|
|
|
Some(config.sigint_symbol)
|
|
|
|
|
}
|
|
|
|
|
x if (129..256).contains(&x)
|
|
|
|
|
&& config.recognize_signal_code
|
|
|
|
|
&& config.map_symbol =>
|
|
|
|
|
{
|
|
|
|
|
Some(config.signal_symbol)
|
|
|
|
|
}
|
|
|
|
|
_ => Some(config.symbol),
|
|
|
|
|
},
|
|
|
|
|
_ => None,
|
|
|
|
|
})
|
|
|
|
|
.map_style(|variable| match variable {
|
|
|
|
|
"style" => Some(Ok(config.style)),
|
|
|
|
|
_ => None,
|
|
|
|
|
})
|
|
|
|
|
.map(|variable| match variable {
|
|
|
|
|
"status" => Some(Ok(exit_code)),
|
2022-02-05 20:13:42 +00:00
|
|
|
|
"hex_status" => Some(Ok(hex_status.as_ref())),
|
2021-07-28 16:26:00 +00:00
|
|
|
|
"int" => Some(Ok(exit_code)),
|
2021-12-03 06:54:56 +00:00
|
|
|
|
"maybe_int" => Ok(maybe_exit_code_number).transpose(),
|
|
|
|
|
"common_meaning" => Ok(common_meaning).transpose(),
|
2021-07-28 16:26:00 +00:00
|
|
|
|
"signal_number" => Ok(signal_number.as_deref()).transpose(),
|
2021-12-03 06:54:56 +00:00
|
|
|
|
"signal_name" => Ok(signal_name).transpose(),
|
2024-03-20 21:58:33 +00:00
|
|
|
|
_ => None,
|
|
|
|
|
})
|
|
|
|
|
.map_variables_to_segments(|variable| match variable {
|
|
|
|
|
"pipestatus" if pipestatus.is_none() => {
|
|
|
|
|
// We might enter this case if pipestatus hasn't
|
|
|
|
|
// been processed yet, which means that it has been
|
|
|
|
|
// set in format
|
|
|
|
|
log::warn!("pipestatus variable is only available in pipestatus_format");
|
|
|
|
|
None
|
2021-07-28 16:26:00 +00:00
|
|
|
|
}
|
2024-03-20 21:58:33 +00:00
|
|
|
|
"pipestatus" => pipestatus.clone().map(Ok),
|
2021-07-28 16:26:00 +00:00
|
|
|
|
_ => None,
|
|
|
|
|
})
|
2021-11-01 21:18:45 +00:00
|
|
|
|
.parse(None, Some(context))
|
2021-07-28 16:26:00 +00:00
|
|
|
|
})
|
2020-09-25 22:04:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-03 03:09:13 +00:00
|
|
|
|
fn status_common_meaning(ex: ExitCode) -> Option<&'static str> {
|
|
|
|
|
// Over 128 are Signal exit code
|
|
|
|
|
if ex > 128 {
|
|
|
|
|
return None;
|
|
|
|
|
}
|
|
|
|
|
match ex {
|
2022-03-16 20:05:13 +00:00
|
|
|
|
0 => Some(""), // SUCCESS can be defined by $success_symbol if the user wishes too.
|
2021-01-03 03:09:13 +00:00
|
|
|
|
1 => Some("ERROR"),
|
|
|
|
|
2 => Some("USAGE"),
|
2023-10-13 08:56:28 +00:00
|
|
|
|
|
|
|
|
|
// status codes 64-78 from libc
|
|
|
|
|
64 => Some("USAGE"),
|
|
|
|
|
65 => Some("DATAERR"),
|
|
|
|
|
66 => Some("NOINPUT"),
|
|
|
|
|
67 => Some("NOUSER"),
|
|
|
|
|
68 => Some("NOHOST"),
|
|
|
|
|
69 => Some("UNAVAILABLE"),
|
|
|
|
|
70 => Some("SOFTWARE"),
|
|
|
|
|
71 => Some("OSERR"),
|
|
|
|
|
72 => Some("OSFILE"),
|
|
|
|
|
73 => Some("CANTCREAT"),
|
|
|
|
|
74 => Some("IOERR"),
|
|
|
|
|
75 => Some("TEMPFAIL"),
|
|
|
|
|
76 => Some("PROTOCOL"),
|
|
|
|
|
77 => Some("NOPERM"),
|
|
|
|
|
78 => Some("CONFIG"),
|
|
|
|
|
|
2021-01-03 03:09:13 +00:00
|
|
|
|
126 => Some("NOPERM"),
|
|
|
|
|
127 => Some("NOTFOUND"),
|
|
|
|
|
_ => None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn status_to_signal(ex: ExitCode) -> Option<SignalNumber> {
|
|
|
|
|
if ex < 129 {
|
|
|
|
|
return None;
|
|
|
|
|
}
|
|
|
|
|
let sn = ex - 128;
|
|
|
|
|
Some(sn as u32)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn status_signal_name(signal: SignalNumber) -> Option<&'static str> {
|
|
|
|
|
match signal {
|
|
|
|
|
1 => Some("HUP"), // 128 + 1
|
|
|
|
|
2 => Some("INT"), // 128 + 2
|
|
|
|
|
3 => Some("QUIT"), // 128 + 3
|
|
|
|
|
4 => Some("ILL"), // 128 + 4
|
|
|
|
|
5 => Some("TRAP"), // 128 + 5
|
|
|
|
|
6 => Some("IOT"), // 128 + 6
|
|
|
|
|
7 => Some("BUS"), // 128 + 7
|
|
|
|
|
8 => Some("FPE"), // 128 + 8
|
|
|
|
|
9 => Some("KILL"), // 128 + 9
|
|
|
|
|
10 => Some("USR1"), // 128 + 10
|
|
|
|
|
11 => Some("SEGV"), // 128 + 11
|
|
|
|
|
12 => Some("USR2"), // 128 + 12
|
|
|
|
|
13 => Some("PIPE"), // 128 + 13
|
|
|
|
|
14 => Some("ALRM"), // 128 + 14
|
|
|
|
|
15 => Some("TERM"), // 128 + 15
|
|
|
|
|
16 => Some("STKFLT"), // 128 + 16
|
|
|
|
|
17 => Some("CHLD"), // 128 + 17
|
|
|
|
|
18 => Some("CONT"), // 128 + 18
|
|
|
|
|
19 => Some("STOP"), // 128 + 19
|
|
|
|
|
20 => Some("TSTP"), // 128 + 20
|
|
|
|
|
21 => Some("TTIN"), // 128 + 21
|
|
|
|
|
22 => Some("TTOU"), // 128 + 22
|
|
|
|
|
_ => None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-25 22:04:51 +00:00
|
|
|
|
#[cfg(test)]
|
|
|
|
|
mod tests {
|
2022-10-07 09:44:14 +00:00
|
|
|
|
use nu_ansi_term::{Color, Style};
|
2020-09-25 22:04:51 +00:00
|
|
|
|
|
|
|
|
|
use crate::test::ModuleRenderer;
|
|
|
|
|
|
|
|
|
|
#[test]
|
2022-03-16 20:05:13 +00:00
|
|
|
|
fn success_status_success_symbol_empty() {
|
2020-09-25 22:04:51 +00:00
|
|
|
|
let expected = None;
|
|
|
|
|
|
2022-03-16 20:05:13 +00:00
|
|
|
|
// 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")));
|
|
|
|
|
|
2020-09-25 22:04:51 +00:00
|
|
|
|
// Status code 0
|
|
|
|
|
let actual = ModuleRenderer::new("status")
|
|
|
|
|
.config(toml::toml! {
|
|
|
|
|
[status]
|
2022-03-16 20:05:13 +00:00
|
|
|
|
success_symbol = "✔️"
|
2020-09-25 22:04:51 +00:00
|
|
|
|
disabled = false
|
|
|
|
|
})
|
|
|
|
|
.status(0)
|
|
|
|
|
.collect();
|
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
|
|
|
|
|
// No status code
|
|
|
|
|
let actual = ModuleRenderer::new("status")
|
|
|
|
|
.config(toml::toml! {
|
|
|
|
|
[status]
|
2022-03-16 20:05:13 +00:00
|
|
|
|
success_symbol = "✔️"
|
2020-09-25 22:04:51 +00:00
|
|
|
|
disabled = false
|
|
|
|
|
})
|
|
|
|
|
.collect();
|
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
2021-02-11 20:08:17 +00:00
|
|
|
|
fn not_enabled() {
|
2020-09-25 22:04:51 +00:00
|
|
|
|
let expected = None;
|
|
|
|
|
|
|
|
|
|
let actual = ModuleRenderer::new("status").status(1).collect();
|
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
2021-02-11 20:08:17 +00:00
|
|
|
|
fn failure_status() {
|
2020-09-25 22:04:51 +00:00
|
|
|
|
let exit_values = [1, 2, 130];
|
|
|
|
|
|
2021-07-29 18:27:46 +00:00
|
|
|
|
for status in &exit_values {
|
2020-09-25 22:04:51 +00:00
|
|
|
|
let expected = Some(format!(
|
|
|
|
|
"{} ",
|
2022-11-05 11:40:46 +00:00
|
|
|
|
Color::Red.bold().paint(format!("❌{status}"))
|
2020-09-25 22:04:51 +00:00
|
|
|
|
));
|
|
|
|
|
let actual = ModuleRenderer::new("status")
|
|
|
|
|
.config(toml::toml! {
|
|
|
|
|
[status]
|
2022-10-15 12:16:39 +00:00
|
|
|
|
symbol = "❌"
|
2021-01-03 03:09:13 +00:00
|
|
|
|
disabled = false
|
|
|
|
|
})
|
|
|
|
|
.status(*status)
|
|
|
|
|
.collect();
|
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-31 11:35:28 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn failure_plaintext_status() {
|
|
|
|
|
let exit_values = [1, 2, 130];
|
|
|
|
|
|
|
|
|
|
for status in &exit_values {
|
|
|
|
|
let expected = Some(format!(
|
|
|
|
|
"{} ",
|
|
|
|
|
Color::Red.bold().paint(format!("x {status}"))
|
|
|
|
|
));
|
|
|
|
|
let actual = ModuleRenderer::new("status")
|
|
|
|
|
.config(toml::toml! {
|
|
|
|
|
[status]
|
|
|
|
|
symbol = "[x](bold red) "
|
|
|
|
|
disabled = false
|
|
|
|
|
})
|
|
|
|
|
.status(*status)
|
|
|
|
|
.collect();
|
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-21 10:05:28 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn failure_hex_status() {
|
2022-05-23 10:58:27 +00:00
|
|
|
|
let exit_values = [1, 2, 130, -2_147_467_260, 2_147_500_036];
|
2022-02-05 20:13:42 +00:00
|
|
|
|
let string_values = ["0x1", "0x2", "0x82", "0x80004004", "0x80004004"];
|
2021-12-21 10:05:28 +00:00
|
|
|
|
|
|
|
|
|
for (exit_value, string_value) in exit_values.iter().zip(string_values) {
|
|
|
|
|
let expected = Some(format!(
|
|
|
|
|
"{} ",
|
2022-11-05 11:40:46 +00:00
|
|
|
|
Color::Red.bold().paint(format!("❌{string_value}"))
|
2021-12-21 10:05:28 +00:00
|
|
|
|
));
|
|
|
|
|
let actual = ModuleRenderer::new("status")
|
|
|
|
|
.config(toml::toml! {
|
|
|
|
|
[status]
|
2022-10-15 12:16:39 +00:00
|
|
|
|
symbol = "❌"
|
2021-12-21 10:05:28 +00:00
|
|
|
|
disabled = false
|
|
|
|
|
format = "[${symbol}${hex_status}]($style) "
|
|
|
|
|
})
|
|
|
|
|
.status(*exit_value)
|
|
|
|
|
.collect();
|
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-03 03:09:13 +00:00
|
|
|
|
#[test]
|
2021-02-11 20:08:17 +00:00
|
|
|
|
fn signal_name() {
|
2021-01-03 03:09:13 +00:00
|
|
|
|
let exit_values = [1, 2, 126, 127, 130, 101];
|
|
|
|
|
let exit_values_name = [
|
|
|
|
|
Some("ERROR"),
|
|
|
|
|
Some("USAGE"),
|
|
|
|
|
Some("NOPERM"),
|
|
|
|
|
Some("NOTFOUND"),
|
|
|
|
|
Some("INT"),
|
|
|
|
|
None,
|
|
|
|
|
];
|
|
|
|
|
|
2021-09-02 15:48:29 +00:00
|
|
|
|
for (status, name) in exit_values.iter().zip(&exit_values_name) {
|
2021-07-29 18:27:46 +00:00
|
|
|
|
let expected = name.map(std::string::ToString::to_string);
|
2021-01-03 03:09:13 +00:00
|
|
|
|
let actual = ModuleRenderer::new("status")
|
|
|
|
|
.config(toml::toml! {
|
|
|
|
|
[status]
|
|
|
|
|
format = "$common_meaning$signal_name"
|
|
|
|
|
disabled = false
|
|
|
|
|
})
|
|
|
|
|
.status(*status)
|
|
|
|
|
.collect();
|
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
2021-02-11 20:08:17 +00:00
|
|
|
|
fn exit_code_name_no_signal() {
|
2023-10-13 08:56:28 +00:00
|
|
|
|
let exit_values = [
|
|
|
|
|
1, 2, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 126, 127, 130, 101,
|
|
|
|
|
132,
|
|
|
|
|
];
|
2021-01-03 03:09:13 +00:00
|
|
|
|
let exit_values_name = [
|
|
|
|
|
Some("ERROR"),
|
|
|
|
|
Some("USAGE"),
|
2023-10-13 08:56:28 +00:00
|
|
|
|
Some("USAGE"),
|
|
|
|
|
Some("DATAERR"),
|
|
|
|
|
Some("NOINPUT"),
|
|
|
|
|
Some("NOUSER"),
|
|
|
|
|
Some("NOHOST"),
|
|
|
|
|
Some("UNAVAILABLE"),
|
|
|
|
|
Some("SOFTWARE"),
|
|
|
|
|
Some("OSERR"),
|
|
|
|
|
Some("OSFILE"),
|
|
|
|
|
Some("CANTCREAT"),
|
|
|
|
|
Some("IOERR"),
|
|
|
|
|
Some("TEMPFAIL"),
|
|
|
|
|
Some("PROTOCOL"),
|
|
|
|
|
Some("NOPERM"),
|
|
|
|
|
Some("CONFIG"),
|
2021-01-03 03:09:13 +00:00
|
|
|
|
Some("NOPERM"),
|
|
|
|
|
Some("NOTFOUND"),
|
|
|
|
|
None,
|
|
|
|
|
None,
|
|
|
|
|
None,
|
|
|
|
|
];
|
|
|
|
|
|
2021-09-02 15:48:29 +00:00
|
|
|
|
for (status, name) in exit_values.iter().zip(&exit_values_name) {
|
2021-07-29 18:27:46 +00:00
|
|
|
|
let expected = name.map(std::string::ToString::to_string);
|
2021-01-03 03:09:13 +00:00
|
|
|
|
let actual = ModuleRenderer::new("status")
|
|
|
|
|
.config(toml::toml! {
|
|
|
|
|
[status]
|
|
|
|
|
format = "$common_meaning$signal_name"
|
|
|
|
|
recognize_signal_code = false
|
|
|
|
|
disabled = false
|
|
|
|
|
})
|
|
|
|
|
.status(*status)
|
|
|
|
|
.collect();
|
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
2021-02-11 20:08:17 +00:00
|
|
|
|
fn maybe_exit_code_number() {
|
2021-01-03 03:09:13 +00:00
|
|
|
|
let exit_values = [1, 2, 126, 127, 130, 101, 6, -3];
|
|
|
|
|
let exit_values_name = [
|
|
|
|
|
None,
|
|
|
|
|
None,
|
|
|
|
|
None,
|
|
|
|
|
None,
|
|
|
|
|
None,
|
|
|
|
|
Some("101"),
|
|
|
|
|
Some("6"),
|
|
|
|
|
Some("-3"),
|
|
|
|
|
];
|
|
|
|
|
|
2021-09-02 15:48:29 +00:00
|
|
|
|
for (status, name) in exit_values.iter().zip(&exit_values_name) {
|
2021-07-29 18:27:46 +00:00
|
|
|
|
let expected = name.map(std::string::ToString::to_string);
|
2021-01-03 03:09:13 +00:00
|
|
|
|
let actual = ModuleRenderer::new("status")
|
|
|
|
|
.config(toml::toml! {
|
|
|
|
|
[status]
|
|
|
|
|
format = "$maybe_int"
|
|
|
|
|
disabled = false
|
|
|
|
|
})
|
|
|
|
|
.status(*status)
|
|
|
|
|
.collect();
|
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
2021-02-11 20:08:17 +00:00
|
|
|
|
fn special_symbols() {
|
2021-01-03 03:09:13 +00:00
|
|
|
|
let exit_values = [1, 126, 127, 130, 131];
|
|
|
|
|
let exit_values_name = ["🔴", "🚫", "🔍", "🧱", "⚡"];
|
|
|
|
|
|
2021-09-02 15:48:29 +00:00
|
|
|
|
for (status, name) in exit_values.iter().zip(&exit_values_name) {
|
2021-07-29 18:27:46 +00:00
|
|
|
|
let expected = Some((*name).to_string());
|
2021-01-03 03:09:13 +00:00
|
|
|
|
let actual = ModuleRenderer::new("status")
|
|
|
|
|
.config(toml::toml! {
|
|
|
|
|
[status]
|
|
|
|
|
format = "$symbol"
|
|
|
|
|
symbol = "🔴"
|
|
|
|
|
not_executable_symbol = "🚫"
|
|
|
|
|
not_found_symbol = "🔍"
|
|
|
|
|
sigint_symbol = "🧱"
|
|
|
|
|
signal_symbol = "⚡"
|
|
|
|
|
recognize_signal_code = true
|
|
|
|
|
map_symbol = true
|
|
|
|
|
disabled = false
|
|
|
|
|
})
|
|
|
|
|
.status(*status)
|
|
|
|
|
.collect();
|
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
2021-02-11 20:08:17 +00:00
|
|
|
|
fn special_symbols_no_signals() {
|
2021-01-03 03:09:13 +00:00
|
|
|
|
let exit_values = [1, 126, 127, 130, 131];
|
|
|
|
|
let exit_values_name = ["🔴", "🚫", "🔍", "🔴", "🔴"];
|
|
|
|
|
|
2021-09-02 15:48:29 +00:00
|
|
|
|
for (status, name) in exit_values.iter().zip(&exit_values_name) {
|
2021-07-29 18:27:46 +00:00
|
|
|
|
let expected = Some((*name).to_string());
|
2021-01-03 03:09:13 +00:00
|
|
|
|
let actual = ModuleRenderer::new("status")
|
|
|
|
|
.config(toml::toml! {
|
|
|
|
|
[status]
|
|
|
|
|
format = "$symbol"
|
|
|
|
|
symbol = "🔴"
|
|
|
|
|
not_executable_symbol = "🚫"
|
|
|
|
|
not_found_symbol = "🔍"
|
|
|
|
|
sigint_symbol = "🧱"
|
|
|
|
|
signal_symbol = "⚡"
|
|
|
|
|
recognize_signal_code = false
|
|
|
|
|
map_symbol = true
|
2020-09-25 22:04:51 +00:00
|
|
|
|
disabled = false
|
|
|
|
|
})
|
|
|
|
|
.status(*status)
|
|
|
|
|
.collect();
|
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-07-28 16:26:00 +00:00
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn pipeline_uses_pipestatus_format() {
|
|
|
|
|
let exit_values = [
|
2021-10-03 14:03:09 +00:00
|
|
|
|
[0, 1, 0, 0],
|
2021-07-28 16:26:00 +00:00
|
|
|
|
[0, 1, 2, 3],
|
|
|
|
|
[130, 126, 131, 127],
|
|
|
|
|
[1, 1, 1, 1],
|
|
|
|
|
];
|
|
|
|
|
let exit_values_rendered = [
|
2021-10-03 14:03:09 +00:00
|
|
|
|
"PSF 🟢=🔴 🟢 🟢",
|
2021-07-28 16:26:00 +00:00
|
|
|
|
"PSF 🟢=🔴 🔴 🔴",
|
|
|
|
|
"PSF 🧱=🚫 ⚡ 🔍",
|
|
|
|
|
"PSF 🔴=🔴 🔴 🔴",
|
|
|
|
|
];
|
|
|
|
|
|
2021-09-02 15:48:29 +00:00
|
|
|
|
for (status, rendered) in exit_values.iter().zip(&exit_values_rendered) {
|
2021-07-28 16:26:00 +00:00
|
|
|
|
let main_exit_code = status[0];
|
|
|
|
|
let pipe_exit_code = &status[1..];
|
|
|
|
|
|
2021-07-29 18:27:46 +00:00
|
|
|
|
let expected = Some((*rendered).to_string());
|
2021-07-28 16:26:00 +00:00
|
|
|
|
let actual = ModuleRenderer::new("status")
|
|
|
|
|
.config(toml::toml! {
|
|
|
|
|
[status]
|
|
|
|
|
format = "$symbol"
|
|
|
|
|
symbol = "🔴"
|
|
|
|
|
success_symbol = "🟢"
|
|
|
|
|
not_executable_symbol = "🚫"
|
|
|
|
|
not_found_symbol = "🔍"
|
|
|
|
|
sigint_symbol = "🧱"
|
|
|
|
|
signal_symbol = "⚡"
|
|
|
|
|
recognize_signal_code = true
|
|
|
|
|
map_symbol = true
|
|
|
|
|
pipestatus = true
|
|
|
|
|
pipestatus_separator = " "
|
|
|
|
|
pipestatus_format = "PSF $symbol=$pipestatus"
|
|
|
|
|
disabled = false
|
|
|
|
|
})
|
|
|
|
|
.status(main_exit_code)
|
|
|
|
|
.pipestatus(pipe_exit_code)
|
|
|
|
|
.collect();
|
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn pipeline_no_map_symbols() {
|
|
|
|
|
let exit_values = [
|
2021-10-03 14:03:09 +00:00
|
|
|
|
[0, 1, 0, 0],
|
2021-07-28 16:26:00 +00:00
|
|
|
|
[0, 1, 2, 3],
|
|
|
|
|
[130, 126, 131, 127],
|
|
|
|
|
[1, 1, 1, 1],
|
|
|
|
|
];
|
|
|
|
|
let exit_values_rendered = [
|
2021-10-03 14:03:09 +00:00
|
|
|
|
"PSF 🟢=🔴1 🟢0 🟢0",
|
2021-07-28 16:26:00 +00:00
|
|
|
|
"PSF 🟢=🔴1 🔴2 🔴3",
|
|
|
|
|
"PSF INT🔴=🔴126 🔴1313 🔴127",
|
|
|
|
|
"PSF 🔴=🔴1 🔴1 🔴1",
|
|
|
|
|
];
|
|
|
|
|
|
2021-09-02 15:48:29 +00:00
|
|
|
|
for (status, rendered) in exit_values.iter().zip(&exit_values_rendered) {
|
2021-07-28 16:26:00 +00:00
|
|
|
|
let main_exit_code = status[0];
|
|
|
|
|
let pipe_exit_code = &status[1..];
|
|
|
|
|
|
2021-07-29 18:27:46 +00:00
|
|
|
|
let expected = Some((*rendered).to_string());
|
2021-07-28 16:26:00 +00:00
|
|
|
|
let actual = ModuleRenderer::new("status")
|
|
|
|
|
.config(toml::toml! {
|
|
|
|
|
[status]
|
|
|
|
|
format = "$symbol$int$signal_number"
|
|
|
|
|
symbol = "🔴"
|
|
|
|
|
success_symbol = "🟢"
|
|
|
|
|
not_executable_symbol = "🚫"
|
|
|
|
|
not_found_symbol = "🔍"
|
|
|
|
|
sigint_symbol = "🧱"
|
|
|
|
|
signal_symbol = "⚡"
|
|
|
|
|
recognize_signal_code = true
|
|
|
|
|
map_symbol = false
|
|
|
|
|
pipestatus = true
|
|
|
|
|
pipestatus_separator = " "
|
|
|
|
|
pipestatus_format = "PSF $signal_name$symbol=$pipestatus"
|
|
|
|
|
disabled = false
|
|
|
|
|
})
|
|
|
|
|
.status(main_exit_code)
|
|
|
|
|
.pipestatus(pipe_exit_code)
|
|
|
|
|
.collect();
|
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-01 22:18:44 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn successful_pipeline() {
|
|
|
|
|
let pipe_exit_code = [0, 0, 0];
|
|
|
|
|
|
|
|
|
|
let main_exit_code = 0;
|
|
|
|
|
|
|
|
|
|
let expected = None;
|
|
|
|
|
|
|
|
|
|
let actual = ModuleRenderer::new("status")
|
|
|
|
|
.config(toml::toml! {
|
|
|
|
|
[status]
|
|
|
|
|
disabled = false
|
|
|
|
|
})
|
|
|
|
|
.status(main_exit_code)
|
|
|
|
|
.pipestatus(&pipe_exit_code)
|
|
|
|
|
.collect();
|
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-03 14:03:09 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn successful_pipeline_pipestatus_enabled() {
|
|
|
|
|
let pipe_exit_code = [0, 0, 0];
|
|
|
|
|
|
|
|
|
|
let main_exit_code = 0;
|
|
|
|
|
|
|
|
|
|
let expected = None;
|
|
|
|
|
|
|
|
|
|
let actual = ModuleRenderer::new("status")
|
|
|
|
|
.config(toml::toml! {
|
|
|
|
|
[status]
|
|
|
|
|
disabled = false
|
|
|
|
|
pipestatus = true
|
|
|
|
|
})
|
|
|
|
|
.status(main_exit_code)
|
|
|
|
|
.pipestatus(&pipe_exit_code)
|
|
|
|
|
.collect();
|
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-28 16:26:00 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn pipeline_disabled() {
|
2021-09-01 22:18:44 +00:00
|
|
|
|
let exit_values = [[130, 126, 131, 127], [1, 1, 1, 1]];
|
|
|
|
|
let exit_values_rendered = ["F 🧱", "F 🔴"];
|
2021-07-28 16:26:00 +00:00
|
|
|
|
|
2021-09-02 15:48:29 +00:00
|
|
|
|
for (status, rendered) in exit_values.iter().zip(&exit_values_rendered) {
|
2021-07-28 16:26:00 +00:00
|
|
|
|
let main_exit_code = status[0];
|
|
|
|
|
let pipe_exit_code = &status[1..];
|
|
|
|
|
|
2021-07-29 18:27:46 +00:00
|
|
|
|
let expected = Some((*rendered).to_string());
|
2021-07-28 16:26:00 +00:00
|
|
|
|
let actual = ModuleRenderer::new("status")
|
|
|
|
|
.config(toml::toml! {
|
|
|
|
|
[status]
|
|
|
|
|
format = "F $symbol"
|
|
|
|
|
symbol = "🔴"
|
|
|
|
|
success_symbol = "🟢"
|
|
|
|
|
not_executable_symbol = "🚫"
|
|
|
|
|
not_found_symbol = "🔍"
|
|
|
|
|
sigint_symbol = "🧱"
|
|
|
|
|
signal_symbol = "⚡"
|
|
|
|
|
recognize_signal_code = true
|
|
|
|
|
map_symbol = true
|
|
|
|
|
pipestatus = false
|
|
|
|
|
pipestatus_separator = " "
|
|
|
|
|
pipestatus_format = "PSF $symbol=$pipestatus"
|
|
|
|
|
disabled = false
|
|
|
|
|
})
|
|
|
|
|
.status(main_exit_code)
|
|
|
|
|
.pipestatus(pipe_exit_code)
|
|
|
|
|
.collect();
|
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn pipeline_long() {
|
|
|
|
|
let exit_values = [
|
|
|
|
|
[130, 0, 0, 0, 30, 1, 2, 3, 142, 0, 0, 0, 130],
|
|
|
|
|
[1, 0, 0, 0, 30, 127, 126, 3, 142, 0, 230, 0, 2],
|
|
|
|
|
];
|
|
|
|
|
let exit_values_rendered = [
|
|
|
|
|
"PSF 130INT=🟢|🟢|🟢|🔴30|🔴|🔴|🔴3|⚡|🟢|🟢|🟢|🧱",
|
|
|
|
|
"PSF 1ERROR=🟢|🟢|🟢|🔴30|🔍|🚫|🔴3|⚡|🟢|⚡|🟢|🔴",
|
|
|
|
|
];
|
|
|
|
|
|
2021-09-02 15:48:29 +00:00
|
|
|
|
for (status, rendered) in exit_values.iter().zip(&exit_values_rendered) {
|
2021-07-28 16:26:00 +00:00
|
|
|
|
let main_exit_code = status[0];
|
|
|
|
|
let pipe_exit_code = &status[1..];
|
|
|
|
|
|
2021-07-29 18:27:46 +00:00
|
|
|
|
let expected = Some((*rendered).to_string());
|
2021-07-28 16:26:00 +00:00
|
|
|
|
let actual = ModuleRenderer::new("status")
|
|
|
|
|
.config(toml::toml! {
|
|
|
|
|
[status]
|
|
|
|
|
format = "$symbol$maybe_int"
|
|
|
|
|
symbol = "🔴"
|
|
|
|
|
success_symbol = "🟢"
|
|
|
|
|
not_executable_symbol = "🚫"
|
|
|
|
|
not_found_symbol = "🔍"
|
|
|
|
|
sigint_symbol = "🧱"
|
|
|
|
|
signal_symbol = "⚡"
|
|
|
|
|
recognize_signal_code = true
|
|
|
|
|
map_symbol = true
|
|
|
|
|
pipestatus = true
|
|
|
|
|
pipestatus_separator = "|"
|
|
|
|
|
pipestatus_format = "PSF $int$common_meaning$signal_name=$pipestatus"
|
|
|
|
|
disabled = false
|
|
|
|
|
})
|
|
|
|
|
.status(main_exit_code)
|
|
|
|
|
.pipestatus(pipe_exit_code)
|
|
|
|
|
.collect();
|
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-19 13:07:50 +00:00
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn pipestatus_segment_format() {
|
|
|
|
|
let pipe_exit_code = &[0, 1];
|
|
|
|
|
let main_exit_code = 1;
|
|
|
|
|
|
|
|
|
|
let expected = Some("[0]|[1] => <1>".to_string());
|
|
|
|
|
let actual = ModuleRenderer::new("status")
|
|
|
|
|
.config(toml::toml! {
|
|
|
|
|
[status]
|
|
|
|
|
format = "\\($status\\)"
|
|
|
|
|
pipestatus = true
|
|
|
|
|
pipestatus_separator = "|"
|
|
|
|
|
pipestatus_format = "$pipestatus => <$status>"
|
|
|
|
|
pipestatus_segment_format = "\\[$status\\]"
|
|
|
|
|
disabled = false
|
|
|
|
|
})
|
|
|
|
|
.status(main_exit_code)
|
|
|
|
|
.pipestatus(pipe_exit_code)
|
|
|
|
|
.collect();
|
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
}
|
2022-10-07 09:44:14 +00:00
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn pipestatus_separator_format() {
|
|
|
|
|
let pipe_exit_code = &[0, 1, 2];
|
|
|
|
|
let main_exit_code = 2;
|
|
|
|
|
|
2024-03-20 21:58:33 +00:00
|
|
|
|
let style = Style::new().on(Color::Red).fg(Color::White).bold();
|
|
|
|
|
let sep_style = Style::new().on(Color::Green).fg(Color::White).italic();
|
2022-10-07 09:44:14 +00:00
|
|
|
|
let expected = Some(format!(
|
2024-03-20 21:58:33 +00:00
|
|
|
|
"{}{}{}{}{}",
|
|
|
|
|
style.paint("[0"),
|
|
|
|
|
sep_style.paint("|"),
|
|
|
|
|
style.paint("1"),
|
|
|
|
|
sep_style.paint("|"),
|
|
|
|
|
style.paint("2] => <2>"),
|
2022-10-07 09:44:14 +00:00
|
|
|
|
));
|
|
|
|
|
let actual = ModuleRenderer::new("status")
|
|
|
|
|
.config(toml::toml! {
|
|
|
|
|
[status]
|
|
|
|
|
format = "\\($status\\)"
|
|
|
|
|
style = "fg:white bg:red bold"
|
|
|
|
|
pipestatus = true
|
2024-03-20 21:58:33 +00:00
|
|
|
|
pipestatus_separator = "[|](fg:white bg:green italic)"
|
2022-10-07 09:44:14 +00:00
|
|
|
|
pipestatus_format = "[\\[]($style)$pipestatus[\\] => <$status>]($style)"
|
|
|
|
|
pipestatus_segment_format = "[$status]($style)"
|
|
|
|
|
disabled = false
|
|
|
|
|
})
|
|
|
|
|
.status(main_exit_code)
|
|
|
|
|
.pipestatus(pipe_exit_code)
|
|
|
|
|
.collect();
|
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
}
|
2024-03-20 21:58:33 +00:00
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn pipestatus_width() {
|
|
|
|
|
let pipe_exit_code = &[0, 1, 2];
|
|
|
|
|
let main_exit_code = 2;
|
|
|
|
|
|
|
|
|
|
let renderer = ModuleRenderer::new("status")
|
|
|
|
|
.config(toml::toml! {
|
|
|
|
|
format = "$fill$status"
|
|
|
|
|
[status]
|
|
|
|
|
style = "fg:white bg:red bold"
|
|
|
|
|
pipestatus = true
|
|
|
|
|
pipestatus_segment_format = "[$status](bg:blue fg:yellow)"
|
|
|
|
|
disabled = false
|
|
|
|
|
})
|
|
|
|
|
.status(main_exit_code)
|
|
|
|
|
.pipestatus(pipe_exit_code)
|
|
|
|
|
.width(100);
|
|
|
|
|
let context = crate::modules::Context::from(renderer);
|
|
|
|
|
let actual = crate::print::get_prompt(context);
|
|
|
|
|
|
|
|
|
|
let mut escaping = false;
|
|
|
|
|
let mut width = 0;
|
|
|
|
|
for c in actual.chars() {
|
|
|
|
|
if c == '\x1B' {
|
|
|
|
|
escaping = true;
|
|
|
|
|
}
|
|
|
|
|
if escaping {
|
|
|
|
|
escaping = !c.is_ascii_alphabetic();
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
width += 1;
|
|
|
|
|
}
|
|
|
|
|
assert_eq!(width, 100);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn pipestatus_segment_format_err() {
|
|
|
|
|
let pipe_exit_code = &[0, 1, 2];
|
|
|
|
|
let main_exit_code = 2;
|
|
|
|
|
|
|
|
|
|
let expected = Some(format!(
|
|
|
|
|
"{}",
|
|
|
|
|
Style::new()
|
|
|
|
|
.on(Color::Red)
|
|
|
|
|
.fg(Color::White)
|
|
|
|
|
.bold()
|
|
|
|
|
.paint("[] => <2>"),
|
|
|
|
|
));
|
|
|
|
|
let actual = ModuleRenderer::new("status")
|
|
|
|
|
.config(toml::toml! {
|
|
|
|
|
[status]
|
|
|
|
|
style = "fg:white bg:red bold"
|
|
|
|
|
pipestatus = true
|
|
|
|
|
pipestatus_format = "[\\[]($style)$pipestatus[\\] => <$status>]($style)"
|
|
|
|
|
pipestatus_segment_format = "${"
|
|
|
|
|
disabled = false
|
|
|
|
|
})
|
|
|
|
|
.status(main_exit_code)
|
|
|
|
|
.pipestatus(pipe_exit_code)
|
|
|
|
|
.collect();
|
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
}
|
2020-09-25 22:04:51 +00:00
|
|
|
|
}
|