diff options
author | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-06-05 14:27:08 -0400 |
---|---|---|
committer | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-06-05 14:27:08 -0400 |
commit | 530973aea3fa46c469541bc291513a75e3aacd3e (patch) | |
tree | d31a6676038c7d7d6bba9a7feefadd71cebc0ecd | |
parent | 8799211cf9e7547416618725a86463444ed9e342 (diff) |
add support for displaying owner and group of files
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | src/io/metadata.rs | 15 | ||||
-rw-r--r-- | src/tab.rs | 17 | ||||
-rw-r--r-- | src/ui.rs | 37 |
4 files changed, 57 insertions, 13 deletions
@@ -23,6 +23,7 @@ structopt = "0.2.14" text_io = "^0" toml = "^0" unicode-width = "^0" +users = "^0" whoami = "^0" xdg = "^2" diff --git a/src/io/metadata.rs b/src/io/metadata.rs index 5405512..341e8f2 100644 --- a/src/io/metadata.rs +++ b/src/io/metadata.rs @@ -6,22 +6,37 @@ pub struct JoshutoMetadata { pub modified: time::SystemTime, pub permissions: fs::Permissions, pub file_type: fs::FileType, + #[cfg(unix)] + pub uid: u32, + #[cfg(unix)] + pub gid: u32, } impl JoshutoMetadata { pub fn from(path: &path::Path) -> Result<Self, io::Error> { + #[cfg(unix)] + use std::os::unix::fs::MetadataExt; + let metadata = fs::symlink_metadata(path)?; let len = metadata.len(); let modified = metadata.modified()?; let permissions = metadata.permissions(); let file_type = metadata.file_type(); + #[cfg(unix)] + let uid = metadata.uid(); + #[cfg(unix)] + let gid = metadata.gid(); Ok(JoshutoMetadata { len, modified, permissions, file_type, + #[cfg(unix)] + uid, + #[cfg(unix)] + gid, }) } } @@ -63,20 +63,11 @@ impl JoshutoTab { pub fn refresh_file_status(&self, win: &JoshutoPanel) { ncurses::werase(win.win); ncurses::wmove(win.win, 0, 0); - - if let Some(entry) = self.curr_list.get_curr_ref() { - ui::wprint_file_mode(win.win, entry); - ncurses::waddstr(win.win, " "); - if let Some(index) = self.curr_list.index { - ncurses::waddstr( - win.win, - format!("{}/{} ", index + 1, self.curr_list.contents.len()).as_str(), - ); - } - ncurses::waddstr(win.win, " "); - ui::wprint_file_info(win.win, entry); + if let Some(index) = self.curr_list.index { + let entry = &self.curr_list.contents[index]; + let len = self.curr_list.contents.len(); + ui::wprint_file_status(win, entry, index, len); } - win.queue_for_refresh(); } pub fn refresh_path_status(&self, win: &JoshutoPanel, tilde_in_titlebar: bool) { @@ -1,6 +1,9 @@ use std::fs; use std::time; +use users::UsersCache; +use users::mock::{Groups, Users}; + use crate::config::{JoshutoColorTheme, JoshutoConfig}; use crate::context::JoshutoContext; use crate::io::{JoshutoDirEntry, JoshutoDirList}; @@ -238,6 +241,37 @@ pub fn display_contents( win.queue_for_refresh(); } +pub fn wprint_file_status(win: &window::JoshutoPanel, entry: &JoshutoDirEntry, index: usize, len: usize) { + wprint_file_mode(win.win, entry); + + ncurses::waddch(win.win, ' ' as ncurses::chtype); + ncurses::waddstr( + win.win, + format!("{}/{} ", index + 1, len).as_str(), + ); + + let usercache: UsersCache = UsersCache::new(); + match usercache.get_user_by_uid(entry.metadata.uid) { + Some(s) => match s.name().to_str() { + Some(name) => ncurses::waddstr(win.win, name), + None => ncurses::waddstr(win.win, "OsStr error"), + } + None => ncurses::waddstr(win.win, "unknown user"), + }; + ncurses::waddch(win.win, ' ' as ncurses::chtype); + match usercache.get_group_by_gid(entry.metadata.gid) { + Some(s) => match s.name().to_str() { + Some(name) => ncurses::waddstr(win.win, name), + None => ncurses::waddstr(win.win, "OsStr error"), + } + None => ncurses::waddstr(win.win, "unknown user"), + }; + + ncurses::waddstr(win.win, " "); + wprint_file_info(win.win, entry); + win.queue_for_refresh(); +} + pub fn wprint_file_mode(win: ncurses::WINDOW, file: &JoshutoDirEntry) { use std::os::unix::fs::PermissionsExt; @@ -249,6 +283,8 @@ pub fn wprint_file_mode(win: ncurses::WINDOW, file: &JoshutoDirEntry) { } pub fn wprint_file_info(win: ncurses::WINDOW, file: &JoshutoDirEntry) { + #[cfg(unix)] + { use std::os::unix::fs::PermissionsExt; let mode = file.metadata.permissions.mode(); @@ -276,6 +312,7 @@ pub fn wprint_file_info(win: ncurses::WINDOW, file: &JoshutoDirEntry) { ncurses::waddstr(win, &s); } */ + } } pub fn redraw_tab_view(win: &window::JoshutoPanel, context: &JoshutoContext) { |