mirror of
https://github.com/lsd-rs/lsd
synced 2024-12-13 21:52:37 +00:00
Added SetuidDir
and SetuidFile
variants to Elem
and FileType
This allows us to display files and directories that have the uid flag set with a red background.
This commit is contained in:
parent
5ad0fb1b21
commit
0d215dca50
3 changed files with 28 additions and 6 deletions
18
src/color.rs
18
src/color.rs
|
@ -9,7 +9,9 @@ pub enum Elem {
|
|||
SymLink,
|
||||
BrokenSymLink,
|
||||
Dir,
|
||||
SetuidDir,
|
||||
ExecutableFile,
|
||||
SetuidFile,
|
||||
Pipe,
|
||||
BlockDevice,
|
||||
CharDevice,
|
||||
|
@ -62,10 +64,18 @@ impl Colors {
|
|||
}
|
||||
|
||||
pub fn colorize<'a>(&self, input: String, elem: &Elem) -> ColoredString<'a> {
|
||||
self.style(elem).paint(input)
|
||||
}
|
||||
|
||||
fn style(&self, elem: &Elem) -> Style {
|
||||
if let Some(ref colors) = self.colors {
|
||||
colors[elem].paint(input)
|
||||
let style_fg = Style::default().fg(colors[elem]);
|
||||
match elem {
|
||||
Elem::SetuidFile | Elem::SetuidDir => style_fg.on(Colour::Fixed(124)),
|
||||
_ => style_fg,
|
||||
}
|
||||
} else {
|
||||
Style::default().paint(input)
|
||||
Style::default()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -82,13 +92,15 @@ impl Colors {
|
|||
m.insert(Elem::Read, Colour::Fixed(40)); // Green3
|
||||
m.insert(Elem::Write, Colour::Fixed(192)); // DarkOliveGreen1
|
||||
m.insert(Elem::Exec, Colour::Fixed(124)); // Red3
|
||||
m.insert(Elem::ExecSticky, Colour::Fixed(13)); // Fuschsia
|
||||
m.insert(Elem::ExecSticky, Colour::Fixed(13)); // Fuchsia
|
||||
m.insert(Elem::NoAccess, Colour::Fixed(168)); // HotPink3
|
||||
|
||||
// File Types
|
||||
m.insert(Elem::File, Colour::Fixed(184)); // Yellow3
|
||||
m.insert(Elem::Dir, Colour::Fixed(33)); // DodgerBlue1
|
||||
m.insert(Elem::SetuidDir, Colour::Fixed(33)); // DodgerBlue1
|
||||
m.insert(Elem::ExecutableFile, Colour::Fixed(40)); // Green3
|
||||
m.insert(Elem::SetuidFile, Colour::Fixed(184)); // Yellow3
|
||||
m.insert(Elem::Pipe, Colour::Fixed(44)); // DarkTurquoise
|
||||
m.insert(Elem::SymLink, Colour::Fixed(44)); // DarkTurquoise
|
||||
m.insert(Elem::BrokenSymLink, Colour::Fixed(124)); // Red3
|
||||
|
|
|
@ -8,8 +8,10 @@ pub enum FileType {
|
|||
BlockDevice,
|
||||
CharDevice,
|
||||
Directory,
|
||||
SetuidDirectory,
|
||||
File,
|
||||
ExecutableFile,
|
||||
SetuidFile,
|
||||
SymLink,
|
||||
Pipe,
|
||||
Socket,
|
||||
|
@ -20,10 +22,14 @@ impl FileType {
|
|||
pub fn new(meta: &Metadata, permissions: &Permissions) -> Self {
|
||||
let file_type = meta.file_type();
|
||||
|
||||
if file_type.is_file() && permissions.is_executable() {
|
||||
if file_type.is_file() && permissions.setuid {
|
||||
FileType::SetuidFile
|
||||
} else if file_type.is_file() && permissions.is_executable() {
|
||||
FileType::ExecutableFile
|
||||
} else if file_type.is_file() && !permissions.is_executable() {
|
||||
FileType::File
|
||||
} else if file_type.is_dir() && permissions.setuid {
|
||||
FileType::SetuidDirectory
|
||||
} else if file_type.is_dir() {
|
||||
FileType::Directory
|
||||
} else if file_type.is_fifo() {
|
||||
|
@ -45,10 +51,12 @@ impl FileType {
|
|||
impl FileType {
|
||||
pub fn render(self, colors: &Colors) -> ColoredString {
|
||||
match self {
|
||||
FileType::File | FileType::ExecutableFile => {
|
||||
FileType::File | FileType::ExecutableFile | FileType::SetuidFile => {
|
||||
colors.colorize(String::from("."), &Elem::File)
|
||||
}
|
||||
FileType::Directory => colors.colorize(String::from("d"), &Elem::Dir),
|
||||
FileType::Directory | FileType::SetuidDirectory => {
|
||||
colors.colorize(String::from("d"), &Elem::Dir)
|
||||
}
|
||||
FileType::Pipe => colors.colorize(String::from("|"), &Elem::Pipe),
|
||||
FileType::SymLink => colors.colorize(String::from("l"), &Elem::SymLink),
|
||||
FileType::BlockDevice => colors.colorize(String::from("b"), &Elem::BlockDevice),
|
||||
|
|
|
@ -43,9 +43,11 @@ impl Name {
|
|||
|
||||
let elem = match self.file_type {
|
||||
FileType::CharDevice => &Elem::CharDevice,
|
||||
FileType::SetuidDirectory => &Elem::SetuidDir,
|
||||
FileType::Directory => &Elem::Dir,
|
||||
FileType::SymLink => &Elem::SymLink,
|
||||
FileType::ExecutableFile => &Elem::ExecutableFile,
|
||||
FileType::SetuidFile => &Elem::SetuidFile,
|
||||
_ => &Elem::File,
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue