summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2019-01-06 19:07:06 -0500
committerJiayi Zhao <jeff.no.zhao@gmail.com>2019-01-06 19:07:06 -0500
commit3058066d5a150c0b48c66c9aec10d260b7e1533f (patch)
tree8e014f39a36934499702a2b7fca002a595db4f8b
parentd10175338a7ab05b6bc786d4e0fc3723bad68a59 (diff)
suppress some warnings and only print file size for regular files
-rw-r--r--lib/wordexp-rs/src/lib.rs1
-rw-r--r--src/joshuto/command.rs1
-rw-r--r--src/joshuto/ui.rs126
-rw-r--r--src/joshuto/window.rs1
4 files changed, 51 insertions, 78 deletions
diff --git a/lib/wordexp-rs/src/lib.rs b/lib/wordexp-rs/src/lib.rs
index 470acef..1671c03 100644
--- a/lib/wordexp-rs/src/lib.rs
+++ b/lib/wordexp-rs/src/lib.rs
@@ -15,6 +15,7 @@ impl <'a>ToCStr for &'a str {
}
}
+#[allow(dead_code)]
pub struct Wordexp {
pub we_wordc: libc::size_t,
pub we_wordv: *const *const libc::c_char,
diff --git a/src/joshuto/command.rs b/src/joshuto/command.rs
index 621e7b1..9c6f7da 100644
--- a/src/joshuto/command.rs
+++ b/src/joshuto/command.rs
@@ -73,6 +73,7 @@ impl std::fmt::Display for CommandKeybind {
}
}
+#[allow(dead_code)]
pub fn split_shell_style(line: &String) -> Vec<&str>
{
let mut args: Vec<&str> = Vec::new();
diff --git a/src/joshuto/ui.rs b/src/joshuto/ui.rs
index d63bdf6..ee8bb60 100644
--- a/src/joshuto/ui.rs
+++ b/src/joshuto/ui.rs
@@ -120,45 +120,66 @@ pub fn wprint_path(win: &window::JoshutoPanel, username: &str,
ncurses::wnoutrefresh(win.win);
}
-/*
-
-fn wprint_file_size(win: &window::JoshutoPanel, file: &fs::DirEntry,
- coord: (i32, i32)) -> usize
+fn wprint_file_size(win: ncurses::WINDOW, mut file_size: f64)
{
- const FILE_UNITS: [&str; 6] = ["B", "K", "M", "G", "T", "E"];
+ const FILE_UNITS: [&str ; 6] = ["B", "KB", "MB", "GB", "TB", "EB"];
const CONV_RATE: f64 = 1024.0;
- match file.metadata() {
+ let mut index = 0;
+ while file_size > CONV_RATE {
+ file_size = file_size / CONV_RATE;
+ index += 1;
+ }
+
+ if file_size >= 1000.0 {
+ ncurses::waddstr(win,
+ format!("{:.0}{}", file_size, FILE_UNITS[index]).as_str());
+ } else if file_size >= 100.0 {
+ ncurses::waddstr(win,
+ format!(" {:.0}{}", file_size, FILE_UNITS[index]).as_str());
+ } else if file_size >= 10.0 {
+ ncurses::waddstr(win,
+ format!("{:.1}{}", file_size, FILE_UNITS[index]).as_str());
+ } else {
+ ncurses::waddstr(win,
+ format!("{:.2}{}", file_size, FILE_UNITS[index]).as_str());
+ }
+ ncurses::waddstr(win, " ");
+}
+
+pub fn wprint_file_info(win: ncurses::WINDOW, file: &structs::JoshutoDirEntry)
+{
+ use std::os::unix::fs::PermissionsExt;
+
+ ncurses::werase(win);
+ ncurses::wmove(win, 0, 0);
+ match fs::symlink_metadata(&file.path) {
Ok(metadata) => {
- let mut file_size = metadata.len() as f64;
- let mut index = 0;
- while file_size > CONV_RATE {
- file_size = file_size / CONV_RATE;
- index += 1;
- }
+ let permissions: fs::Permissions = metadata.permissions();
+ let mode = permissions.mode();
+
+ ncurses::waddstr(win, unix::stringify_mode(mode).as_str());
+ ncurses::waddstr(win, " ");
- ncurses::wmove(win.win, coord.0, win.cols - 6);
- if file_size >= 1000.0 {
- ncurses::waddstr(win.win,
- format!("{:.0} {}", file_size, FILE_UNITS[index]).as_str());
- } else if file_size >= 100.0 {
- ncurses::waddstr(win.win,
- format!(" {:.0} {}", file_size, FILE_UNITS[index]).as_str());
- } else if file_size >= 10.0 {
- ncurses::waddstr(win.win,
- format!("{:.1} {}", file_size, FILE_UNITS[index]).as_str());
+ if metadata.is_dir() {
+ } else if file.path.is_dir() {
+ if mode >> 9 & unix::S_IFLNK >> 9 == mode >> 9 {
+ if let Ok(path) = fs::read_link(&file.path) {
+ ncurses::waddstr(win, " -> ");
+ ncurses::waddstr(win, path.to_str().unwrap());
+ }
+ }
} else {
- ncurses::waddstr(win.win,
- format!("{:.2} {}", file_size, FILE_UNITS[index]).as_str());
+ let file_size = metadata.len() as f64;
+ wprint_file_size(win, file_size);
}
},
Err(e) => {
- ncurses::waddstr(win.win, format!("{:?}", e).as_str());
+ ncurses::waddstr(win, e.to_string().as_str());
},
};
- 6
+ ncurses::wnoutrefresh(win);
}
-*/
fn wprint_file_name(win: &window::JoshutoPanel, file: &structs::JoshutoDirEntry,
coord: (i32, i32))
@@ -199,57 +220,6 @@ fn wprint_file_name(win: &window::JoshutoPanel, file: &structs::JoshutoDirEntry,
ncurses::waddstr(win.win, "…");
}
-pub fn wprint_file_info(win: ncurses::WINDOW, file: &structs::JoshutoDirEntry)
-{
- use std::os::unix::fs::PermissionsExt;
-
- const FILE_UNITS: [&str ; 6] = ["B", "KB", "MB", "GB", "TB", "EB"];
- const CONV_RATE: f64 = 1024.0;
-
- ncurses::werase(win);
- ncurses::wmove(win, 0, 0);
- match fs::symlink_metadata(&file.path) {
- Ok(metadata) => {
- let permissions: fs::Permissions = metadata.permissions();
- let mode = permissions.mode();
-
- let mut file_size = metadata.len() as f64;
- let mut index = 0;
- while file_size > CONV_RATE {
- file_size = file_size / CONV_RATE;
- index += 1;
- }
-
- ncurses::waddstr(win, unix::stringify_mode(mode).as_str());
- ncurses::waddstr(win, " ");
- if file_size >= 1000.0 {
- ncurses::waddstr(win,
- format!("{:.0}{}", file_size, FILE_UNITS[index]).as_str());
- } else if file_size >= 100.0 {
- ncurses::waddstr(win,
- format!(" {:.0}{}", file_size, FILE_UNITS[index]).as_str());
- } else if file_size >= 10.0 {
- ncurses::waddstr(win,
- format!("{:.1}{}", file_size, FILE_UNITS[index]).as_str());
- } else {
- ncurses::waddstr(win,
- format!("{:.2}{}", file_size, FILE_UNITS[index]).as_str());
- }
- ncurses::waddstr(win, " ");
- if mode >> 9 & unix::S_IFLNK >> 9 == mode >> 9 {
- if let Ok(path) = fs::read_link(&file.path) {
- ncurses::waddstr(win, " -> ");
- ncurses::waddstr(win, path.to_str().unwrap());
- }
- }
- },
- Err(e) => {
- ncurses::waddstr(win, e.to_string().as_str());
- },
- };
- ncurses::wnoutrefresh(win);
-}
-
pub fn wprint_direntry(win: &window::JoshutoPanel,
file: &structs::JoshutoDirEntry, coord: (i32, i32))
{
diff --git a/src/joshuto/window.rs b/src/joshuto/window.rs
index eeb08f3..fed3a4d 100644
--- a/src/joshuto/window.rs
+++ b/src/joshuto/window.rs
@@ -32,6 +32,7 @@ impl JoshutoPanel {
ncurses::top_panel(self.panel);
}
+ #[allow(dead_code)]
pub fn move_to_bottom(&self)
{
ncurses::bottom_panel(self.panel);