23 lines
627 B
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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)
}
}