feat: Add option to always show the username module (#408)
This commit is contained in:
parent
08340328dd
commit
702ad274cf
|
@ -731,6 +731,7 @@ The module will be shown if any of the following conditions are met:
|
||||||
- The current user is root
|
- The current user is root
|
||||||
- The current user isn't the same as the one that is logged in
|
- The current user isn't the same as the one that is logged in
|
||||||
- The user is currently connected as an SSH session
|
- The user is currently connected as an SSH session
|
||||||
|
- The variable `show_always` is set to true
|
||||||
|
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
|
@ -738,6 +739,7 @@ The module will be shown if any of the following conditions are met:
|
||||||
| ------------ | --------------- | ------------------------------------- |
|
| ------------ | --------------- | ------------------------------------- |
|
||||||
| `style_root` | `"bold red"` | The style used when the user is root. |
|
| `style_root` | `"bold red"` | The style used when the user is root. |
|
||||||
| `style_user` | `"bold yellow"` | The style used for non-root users. |
|
| `style_user` | `"bold yellow"` | The style used for non-root users. |
|
||||||
|
| `show_always`| `false` | Always shows the `username` module. |
|
||||||
| `disabled` | `false` | Disables the `username` module. |
|
| `disabled` | `false` | Disables the `username` module. |
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
|
@ -17,8 +17,11 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||||
|
|
||||||
const ROOT_UID: Option<u32> = Some(0);
|
const ROOT_UID: Option<u32> = Some(0);
|
||||||
let user_uid = get_uid();
|
let user_uid = get_uid();
|
||||||
if user != logname || ssh_connection.is_some() || user_uid == ROOT_UID {
|
|
||||||
let mut module = context.new_module("username");
|
let mut module = context.new_module("username");
|
||||||
|
let show_always = module.config_value_bool("show_always").unwrap_or(false);
|
||||||
|
|
||||||
|
if user != logname || ssh_connection.is_some() || user_uid == ROOT_UID || show_always {
|
||||||
let module_style = get_mod_style(user_uid, &module);
|
let module_style = get_mod_style(user_uid, &module);
|
||||||
module.set_style(module_style);
|
module.set_style(module_style);
|
||||||
module.new_segment("username", &user?);
|
module.new_segment("username", &user?);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use ansi_term::Color;
|
use ansi_term::Color;
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
use crate::common;
|
use crate::common::{self, TestCommand};
|
||||||
|
|
||||||
// TODO: Add tests for if root user (UID == 0)
|
// TODO: Add tests for if root user (UID == 0)
|
||||||
// Requires mocking
|
// Requires mocking
|
||||||
|
@ -61,3 +61,19 @@ fn ssh_connection() -> io::Result<()> {
|
||||||
assert_eq!(expected, actual);
|
assert_eq!(expected, actual);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn show_always() -> io::Result<()> {
|
||||||
|
let output = common::render_module("username")
|
||||||
|
.env("USER", "astronaut")
|
||||||
|
.use_config(toml::toml! {
|
||||||
|
[username]
|
||||||
|
show_always = true})
|
||||||
|
.output()?;
|
||||||
|
let actual = String::from_utf8(output.stdout).unwrap();
|
||||||
|
|
||||||
|
let expected = format!("via {} ", Color::Yellow.bold().paint("astronaut"));
|
||||||
|
|
||||||
|
assert_eq!(expected, actual);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue