mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-12-01 01:04:00 +00:00
fix(rprompt): remove lprompt modules from $all
again (#5067)
This commit is contained in:
parent
35241bad92
commit
b9a4b08ac2
124
src/print.rs
124
src/print.rs
@ -12,7 +12,6 @@ use unicode_width::UnicodeWidthChar;
|
|||||||
|
|
||||||
use crate::configs::PROMPT_ORDER;
|
use crate::configs::PROMPT_ORDER;
|
||||||
use crate::context::{Context, Properties, Shell, Target};
|
use crate::context::{Context, Properties, Shell, Target};
|
||||||
use crate::formatter::string_formatter::StringFormatterError;
|
|
||||||
use crate::formatter::{StringFormatter, VariableHolder};
|
use crate::formatter::{StringFormatter, VariableHolder};
|
||||||
use crate::module::Module;
|
use crate::module::Module;
|
||||||
use crate::module::ALL_MODULES;
|
use crate::module::ALL_MODULES;
|
||||||
@ -405,43 +404,65 @@ fn all_modules_uniq(module_list: &BTreeSet<String>) -> Vec<String> {
|
|||||||
/// and the list of all modules used in a format string
|
/// and the list of all modules used in a format string
|
||||||
fn load_formatter_and_modules<'a>(context: &'a Context) -> (StringFormatter<'a>, BTreeSet<String>) {
|
fn load_formatter_and_modules<'a>(context: &'a Context) -> (StringFormatter<'a>, BTreeSet<String>) {
|
||||||
let config = &context.root_config;
|
let config = &context.root_config;
|
||||||
let (formatter, config_param) = match &context.target {
|
|
||||||
Target::Main => (StringFormatter::new(&config.format), "format".to_string()),
|
if context.target == Target::Continuation {
|
||||||
Target::Right => (
|
let cf = &config.continuation_prompt;
|
||||||
StringFormatter::new(&config.right_format),
|
let formatter = StringFormatter::new(cf);
|
||||||
"right_format".to_string(),
|
return match formatter {
|
||||||
),
|
Ok(f) => {
|
||||||
Target::Continuation => (
|
let modules = f.get_variables().into_iter().collect();
|
||||||
StringFormatter::new(&config.continuation_prompt),
|
(f, modules)
|
||||||
"continuation_prompt".to_string(),
|
}
|
||||||
),
|
Err(e) => {
|
||||||
Target::Profile(name) => (
|
log::error!("Error parsing continuation prompt: {e}");
|
||||||
match config.profiles.get(name) {
|
(StringFormatter::raw(">"), BTreeSet::new())
|
||||||
Some(format) => StringFormatter::new(format),
|
}
|
||||||
_ => Err(StringFormatterError::Custom("Invalid Profile".to_string())),
|
};
|
||||||
},
|
}
|
||||||
format!("profile: {}", &name),
|
|
||||||
),
|
let (left_format_str, right_format_str): (&str, &str) = match context.target {
|
||||||
|
Target::Main | Target::Right => (&config.format, &config.right_format),
|
||||||
|
Target::Profile(ref name) => {
|
||||||
|
if let Some(lf) = config.profiles.get(name) {
|
||||||
|
(lf, "")
|
||||||
|
} else {
|
||||||
|
log::error!("Profile {name:?} not found");
|
||||||
|
return (StringFormatter::raw(">"), BTreeSet::new());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Target::Continuation => unreachable!("Continuation prompt should have been handled above"),
|
||||||
};
|
};
|
||||||
|
|
||||||
let rformatter = StringFormatter::new(&config.right_format);
|
let lf = StringFormatter::new(left_format_str);
|
||||||
|
let rf = StringFormatter::new(right_format_str);
|
||||||
|
|
||||||
if formatter.is_err() {
|
if let Err(ref e) = lf {
|
||||||
log::error!("Error parsing `{}`", config_param);
|
let name = if let Target::Profile(ref profile_name) = context.target {
|
||||||
}
|
format!("profile.{profile_name}")
|
||||||
if rformatter.is_err() {
|
} else {
|
||||||
log::error!("Error parsing `right_format`")
|
"format".to_string()
|
||||||
|
};
|
||||||
|
log::error!("Error parsing {name:?}: {e}");
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Err(ref e) = rf {
|
||||||
|
log::error!("Error parsing right_format: {e}");
|
||||||
}
|
}
|
||||||
|
|
||||||
match (formatter, rformatter) {
|
let modules = [&lf, &rf]
|
||||||
(Ok(lf), Ok(rf)) => {
|
.into_iter()
|
||||||
let mut modules: BTreeSet<String> = BTreeSet::new();
|
.flatten()
|
||||||
if context.target != Target::Continuation {
|
.flat_map(|f| f.get_variables())
|
||||||
modules.extend(lf.get_variables());
|
.collect();
|
||||||
modules.extend(rf.get_variables());
|
|
||||||
}
|
let main_formatter = match context.target {
|
||||||
(lf, modules)
|
Target::Main | Target::Profile(_) => lf,
|
||||||
}
|
Target::Right => rf,
|
||||||
|
Target::Continuation => unreachable!("Continuation prompt should have been handled above"),
|
||||||
|
};
|
||||||
|
|
||||||
|
match main_formatter {
|
||||||
|
Ok(f) => (f, modules),
|
||||||
_ => (StringFormatter::raw(">"), BTreeSet::new()),
|
_ => (StringFormatter::raw(">"), BTreeSet::new()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -525,6 +546,43 @@ mod test {
|
|||||||
assert_eq!(expected, actual);
|
assert_eq!(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn prompt_with_all() -> io::Result<()> {
|
||||||
|
let mut context = default_context().set_config(toml::toml! {
|
||||||
|
add_newline = false
|
||||||
|
right_format= "$directory$line_break"
|
||||||
|
format="$all"
|
||||||
|
[character]
|
||||||
|
format=">"
|
||||||
|
});
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
context.current_dir = dir.path().to_path_buf();
|
||||||
|
|
||||||
|
let expected = String::from(">");
|
||||||
|
let actual = get_prompt(context);
|
||||||
|
assert_eq!(expected, actual);
|
||||||
|
dir.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn rprompt_with_all() -> io::Result<()> {
|
||||||
|
let mut context = default_context().set_config(toml::toml! {
|
||||||
|
format= "$directory$line_break"
|
||||||
|
right_format="$all"
|
||||||
|
[character]
|
||||||
|
format=">"
|
||||||
|
});
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
context.current_dir = dir.path().to_path_buf();
|
||||||
|
|
||||||
|
context.target = Target::Right;
|
||||||
|
|
||||||
|
let expected = String::from(">");
|
||||||
|
let actual = get_prompt(context);
|
||||||
|
assert_eq!(expected, actual);
|
||||||
|
dir.close()
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn custom_prompt() {
|
fn custom_prompt() {
|
||||||
let mut context = default_context().set_config(toml::toml! {
|
let mut context = default_context().set_config(toml::toml! {
|
||||||
|
Loading…
Reference in New Issue
Block a user