summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2019-06-05 14:27:08 -0400
committerJiayi Zhao <jeff.no.zhao@gmail.com>2019-06-05 14:27:08 -0400
commit530973aea3fa46c469541bc291513a75e3aacd3e (patch)
treed31a6676038c7d7d6bba9a7feefadd71cebc0ecd /src
parent8799211cf9e7547416618725a86463444ed9e342 (diff)
add support for displaying owner and group of files
Diffstat (limited to 'src')
-rw-r--r--src/io/metadata.rs15
-rw-r--r--src/tab.rs17
-rw-r--r--src/ui.rs37
3 files changed, 56 insertions, 13 deletions
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,
})
}
}
diff --git a/src/tab.rs b/src/tab.rs
index dd84ebc..94ff5aa 100644
--- a/src/tab.rs
+++ b/src/tab.rs
@@ -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) {
diff --git a/src/ui.rs b/src/ui.rs
index 3b169d2..7fd0dfe 100644
--- a/src/ui.rs
+++ b/src/ui.rs
@@ -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) {