diff options
author | qkzk <qu3nt1n@gmail.com> | 2022-09-25 23:08:56 +0200 |
---|---|---|
committer | qkzk <qu3nt1n@gmail.com> | 2022-09-25 23:08:56 +0200 |
commit | 9fff5085310199c38efd588aaab9de0cf8b8a80d (patch) | |
tree | 6fc839d25bf307a4379805e963f5c0692c3aa3fc | |
parent | 50d6381698fb836607a5e9a999778354b85efe61 (diff) |
dirsymbol & color for every kind. Needs refactoring
-rw-r--r-- | config.yaml | 3 | ||||
-rw-r--r-- | readme.md | 2 | ||||
-rw-r--r-- | src/config_file.rs | 6 | ||||
-rw-r--r-- | src/fileinfo.rs | 48 | ||||
-rw-r--r-- | src/main.rs | 2 | ||||
-rw-r--r-- | stderr.log | 4 |
6 files changed, 61 insertions, 4 deletions
diff --git a/config.yaml b/config.yaml index a5aef2e8..b5d2a808 100644 --- a/config.yaml +++ b/config.yaml @@ -8,9 +8,10 @@ colors: file: white directory: red block: yellow - char: magenta + char: green fifo: blue socket: cyan + symlink: magenta keybindings: # only ASCII char keys are allowed toggle_hidden: a @@ -51,6 +51,8 @@ - [ ] regex - [ ] search - [ ] mark multiple files +- [ ] dirsymbol for sockets and whatever +- [ ] refactor FileInfo, use an enum for FileType and basta ## BUGS diff --git a/src/config_file.rs b/src/config_file.rs index 58f976be..be05c26a 100644 --- a/src/config_file.rs +++ b/src/config_file.rs @@ -11,6 +11,7 @@ pub struct Colors { pub char: String, pub fifo: String, pub socket: String, + pub symlink: String, } impl Colors { @@ -39,6 +40,10 @@ impl Colors { .as_str() .map(|s| s.to_string()) .expect("Couldn't parse config file"); + let symlink = yaml["symlink"] + .as_str() + .map(|s| s.to_string()) + .expect("Couldn't parse config file"); Self { file, directory, @@ -46,6 +51,7 @@ impl Colors { char, fifo, socket, + symlink, } } } diff --git a/src/fileinfo.rs b/src/fileinfo.rs index 779184ee..b5bbfb22 100644 --- a/src/fileinfo.rs +++ b/src/fileinfo.rs @@ -21,6 +21,7 @@ pub struct FileInfo { pub is_char: bool, pub is_fifo: bool, pub is_socket: bool, + pub is_symlink: bool, } impl FileInfo { @@ -39,12 +40,14 @@ impl FileInfo { let mut is_socket: bool = false; let mut is_char: bool = false; let mut is_fifo: bool = false; + let mut is_symlink: bool = false; if let Ok(meta) = direntry.metadata() { is_block = meta.file_type().is_block_device(); is_socket = meta.file_type().is_socket(); is_char = meta.file_type().is_char_device(); is_fifo = meta.file_type().is_fifo(); + is_symlink = meta.file_type().is_symlink(); } Ok(FileInfo { @@ -61,6 +64,7 @@ impl FileInfo { is_char, is_fifo, is_socket, + is_symlink, }) } @@ -237,10 +241,48 @@ fn extract_username(direntry: &DirEntry) -> String { } fn extract_dir_symbol(direntry: &DirEntry) -> String { - match metadata(direntry.path()) { - Ok(path) => String::from(if path.is_dir() { "d" } else { "." }), - Err(_) => String::from("."), + match direntry.metadata() { + Ok(metadata) => { + let file_type = metadata.file_type(); + if file_type.is_dir() { + "d".into() + } else if file_type.is_file() { + ".".into() + } else if file_type.is_symlink() { + "l".into() + } else if file_type.is_block_device() { + "b".into() + } else if file_type.is_fifo() { + "p".into() + } else if file_type.is_socket() { + "s".into() + } else if file_type.is_char_device() { + "c".into() + } else { + ".".into() + } + } + Err(_) => ".".into(), } + // match metadata(direntry.path()) { + // Ok(path) => { + // if path.is_dir() { + // "d".into() + // } else if path.is_symlink() { + // "l".into() + // } else if path.is_fifo() { + // "p".into() + // } else if path.is_block() { + // "b".into() + // } else if path.is_socket() { + // "s".into() + // } else { + // ".".into() + // } + // } + // // String::from(if path.is_dir() { "d" } else { "." }), + // Err(_) => String::from("."), + // } } fn extract_file_size(direntry: &DirEntry) -> u64 { diff --git a/src/main.rs b/src/main.rs index 744a8f80..c81a1bed 100644 --- a/src/main.rs +++ b/src/main.rs @@ -132,6 +132,8 @@ fn fileinfo_attr(fileinfo: &FileInfo, colors: &Colors) -> Attr { attr.fg = str_to_tuikit(&colors.fifo); } else if fileinfo.is_socket { attr.fg = str_to_tuikit(&colors.socket); + } else if fileinfo.is_symlink { + attr.fg = str_to_tuikit(&colors.symlink); } if fileinfo.is_selected { attr.effect = Effect::REVERSE; diff --git a/stderr.log b/stderr.log new file mode 100644 index 00000000..a1677ea8 --- /dev/null +++ b/stderr.log @@ -0,0 +1,4 @@ +error: failed to create directory `/home/quentin/gclem/dev/rust/fm/target/debug` + +Caused by: + Permission denied (os error 13) |