mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-11-15 17:47:13 +00:00
fix(localip): disable localip module default (#3607)
This commit is contained in:
parent
32aca11c4a
commit
efb16dd9ca
@ -11,12 +11,18 @@ use crate::formatter::StringFormatter;
|
||||
/// is to connect a UDP socket and then reading its local endpoint.
|
||||
///
|
||||
/// Will display the ip if all of the following criteria are met:
|
||||
/// - localip.disabled is absent or false
|
||||
/// - localip.disabled is false
|
||||
/// - localip.ssh_only is false OR the user is currently connected as an SSH session (`$SSH_CONNECTION`)
|
||||
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||
let mut module = context.new_module("localip");
|
||||
let config: LocalipConfig = LocalipConfig::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;
|
||||
};
|
||||
|
||||
let ssh_connection = context.get_env("SSH_CONNECTION");
|
||||
if config.ssh_only && ssh_connection.is_none() {
|
||||
return None;
|
||||
@ -86,6 +92,7 @@ mod tests {
|
||||
.config(toml::toml! {
|
||||
[localip]
|
||||
ssh_only = false
|
||||
disabled = false
|
||||
})
|
||||
.collect();
|
||||
let expected = Some(format!("{} ", style().paint(localip)));
|
||||
@ -99,6 +106,7 @@ mod tests {
|
||||
.config(toml::toml! {
|
||||
[localip]
|
||||
ssh_only = true
|
||||
disabled = false
|
||||
})
|
||||
.collect();
|
||||
let expected = None;
|
||||
@ -114,6 +122,7 @@ mod tests {
|
||||
[localip]
|
||||
ssh_only = true
|
||||
trim_at = ""
|
||||
disabled = false
|
||||
})
|
||||
.env("SSH_CONNECTION", "something")
|
||||
.collect();
|
||||
@ -122,6 +131,16 @@ mod tests {
|
||||
assert_eq!(expected, actual);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn config_blank() {
|
||||
let actual = ModuleRenderer::new("localip")
|
||||
.env("SSH_CONNECTION", "something")
|
||||
.collect();
|
||||
|
||||
let expected = None;
|
||||
assert_eq!(expected, actual);
|
||||
}
|
||||
|
||||
fn style() -> Style {
|
||||
Color::Yellow.bold()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user