提交 6edf2c0d 编写于 作者: B Ben S

Highlight the current user

上级 48d8a46d
......@@ -2,6 +2,6 @@ pub enum Column {
Permissions,
FileName,
FileSize(bool),
User,
User(u64),
Group,
}
......@@ -71,7 +71,11 @@ impl<'a> File<'a> {
// Display the ID if the user/group doesn't exist, which
// usually means it was deleted but its files weren't.
User => get_user_name(self.stat.unstable.uid as i32).unwrap_or(self.stat.unstable.uid.to_str()),
User(uid) => {
let style = if uid == self.stat.unstable.uid { Yellow.bold() } else { Plain };
let string = get_user_name(self.stat.unstable.uid as i32).unwrap_or(self.stat.unstable.uid.to_str());
return style.paint(string.as_slice());
},
Group => get_group_name(self.stat.unstable.gid as u32).unwrap_or(self.stat.unstable.gid.to_str()),
}
}
......
......@@ -3,6 +3,7 @@ extern crate getopts;
use file::File;
use std::cmp::lexical_ordering;
use column::{Column, Permissions, FileName, FileSize, User, Group};
use unix::get_current_user_id;
pub enum SortField {
Name, Extension, Size
......@@ -53,7 +54,7 @@ impl Options {
let mut columns = vec![
Permissions,
FileSize(matches.opt_present("binary")),
User,
User(get_current_user_id()),
];
if matches.opt_present("group") {
......
......@@ -31,6 +31,7 @@ mod c {
extern {
pub fn getpwuid(uid: c_int) -> *c_passwd;
pub fn getgrgid(gid: uid_t) -> *c_group;
pub fn getuid() -> libc::c_int;
}
}
......@@ -53,3 +54,7 @@ pub fn get_group_name(gid: u32) -> Option<String> {
return None;
}
}
pub fn get_current_user_id() -> u64 {
unsafe { c::getuid() as u64 }
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册