23 lines
627 B
Rust
23 lines
627 B
Rust
use ansi_term::ANSIGenericString;
|
||
use ansi_term::Colour::RGB;
|
||
|
||
use libc::geteuid;
|
||
|
||
pub const USER_SYMBOL: &str = "\u{276F}"; // User indicator symbol: "❯"
|
||
pub const ROOT_COL: ansi_term::Colour = RGB(255, 53, 94); // If the user is root
|
||
pub const NORMIE_COL: ansi_term::Colour = RGB(0, 255, 180); // Regular user
|
||
|
||
// Check if the current user is root
|
||
pub fn is_root() -> bool {
|
||
unsafe { geteuid() == 0 } // Uid for root is 0
|
||
}
|
||
|
||
/// Root user indicator
|
||
pub fn indicator() -> ANSIGenericString<'static, str> {
|
||
if is_root() {
|
||
ROOT_COL.paint(USER_SYMBOL)
|
||
} else {
|
||
NORMIE_COL.paint(USER_SYMBOL)
|
||
}
|
||
}
|