summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock25
-rw-r--r--Cargo.toml1
-rw-r--r--src/bulkrename.rs4
-rw-r--r--src/completion.rs3
-rw-r--r--src/display.rs33
-rw-r--r--src/fileinfo.rs20
-rw-r--r--src/git.rs4
7 files changed, 73 insertions, 17 deletions
diff --git a/Cargo.lock b/Cargo.lock
index cfd445b..22193b8 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -749,6 +749,7 @@ dependencies = [
"shellexpand",
"skim",
"syntect",
+ "sysinfo",
"tuikit",
"users",
"zip",
@@ -1112,6 +1113,15 @@ dependencies = [
]
[[package]]
+name = "ntapi"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bc51db7b362b205941f71232e56c625156eb9a929f8cf74a428fd5bc094a4afc"
+dependencies = [
+ "winapi",
+]
+
+[[package]]
name = "num-integer"
version = "0.1.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1847,6 +1857,21 @@ dependencies = [
]
[[package]]
+name = "sysinfo"
+version = "0.26.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c375d5fd899e32847b8566e10598d6e9f1d9b55ec6de3cdf9e7da4bdc51371bc"
+dependencies = [
+ "cfg-if 1.0.0",
+ "core-foundation-sys",
+ "libc",
+ "ntapi",
+ "once_cell",
+ "rayon",
+ "winapi",
+]
+
+[[package]]
name = "term"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index b17ef79..399b221 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -28,6 +28,7 @@ serde_yaml = "0.9.13"
shellexpand = "2.1.2"
skim = { git = "https://github.com/qkzk/skim" }
syntect = "5.0"
+sysinfo = "0.26.7"
tuikit = "*"
users = "0.11.0"
zip = "0.6.3"
diff --git a/src/bulkrename.rs b/src/bulkrename.rs
index f786b56..653b10f 100644
--- a/src/bulkrename.rs
+++ b/src/bulkrename.rs
@@ -122,7 +122,7 @@ impl<'a> Bulkrename<'a> {
fn delete_temp_file(&self) -> Result<(), FmError> {
let filepath = &self.temp_file;
- std::fs::remove_file(&filepath)?;
+ std::fs::remove_file(filepath)?;
Ok(())
}
@@ -136,7 +136,7 @@ impl<'a> Bulkrename<'a> {
fn rename_file(&self, path: &Path, filename: &str) -> Result<(), FmError> {
let mut parent = PathBuf::from(path);
parent.pop();
- std::fs::rename(path, parent.join(&filename))?;
+ std::fs::rename(path, parent.join(filename))?;
Ok(())
}
}
diff --git a/src/completion.rs b/src/completion.rs
index a7ce9d7..23a24d7 100644
--- a/src/completion.rs
+++ b/src/completion.rs
@@ -95,8 +95,7 @@ impl Completion {
.filter(|path| std::path::Path::new(path).exists())
{
let comp: Vec<String> = fs::read_dir(path)?
- .filter(|e| e.is_ok())
- .map(|e| e.unwrap())
+ .filter_map(|e| e.ok())
.filter(|e| {
e.file_type().unwrap().is_file() && filename_startswith(e, input_string)
})
diff --git a/src/display.rs b/src/display.rs
index c5fabbe..8bcbb7f 100644
--- a/src/display.rs
+++ b/src/display.rs
@@ -2,6 +2,7 @@ use std::cmp::min;
use std::sync::Arc;
use log::info;
+use sysinfo::{DiskExt, System, SystemExt};
use tuikit::attr::*;
use tuikit::term::Term;
@@ -23,12 +24,18 @@ pub struct Display {
/// It will print every symbol shown on screen.
pub term: Arc<Term>,
colors: Colors,
+ /// system info
+ sys: System,
}
impl Display {
/// Returns a new `Display` instance from a `tuikit::term::Term` object.
pub fn new(term: Arc<Term>, colors: Colors) -> Self {
- Self { term, colors }
+ Self {
+ term,
+ colors,
+ sys: System::new_all(),
+ }
}
const EDIT_BOX_OFFSET: usize = 10;
@@ -60,8 +67,6 @@ impl Display {
/// The preview in preview mode.
pub fn display_all(&mut self, status: &Status) -> FmResult<()> {
// let status = status.selected_non_mut();
- self.first_line(status)?;
- self.cursor(status)?;
match status.selected_non_mut().mode {
// Mode::Help => self.help(),
Mode::Jump => self.jump_list(status),
@@ -72,7 +77,9 @@ impl Display {
Mode::Shortcut => self.shortcuts(status),
Mode::Marks(MarkAction::New) | Mode::Marks(MarkAction::Jump) => self.marks(status),
_ => self.files(status),
- }
+ }?;
+ self.cursor(status)?;
+ self.first_line(status)
}
/// Reads and returns the `tuikit::term::Term` height.
@@ -91,12 +98,13 @@ impl Display {
let first_row: String = match tab.mode {
Mode::Normal => {
format!(
- "Tab: {}/{} -- Path: {} -- Files: {} -- Sum: {} -- {}",
+ "Tab: {}/{} -- Path: {} -- Files: {} -- Sum: {} -- Avail: {} -- {}",
status.index + 1,
status.len(),
tab.path_content.path_to_str()?,
tab.path_content.files.len(),
human_size(tab.path_content.used_space),
+ human_size(self.disk_space(tab.path_str().unwrap())),
git(&tab.path_content.path)?,
)
}
@@ -237,7 +245,6 @@ impl Display {
fn completion(&mut self, status: &Status) -> FmResult<()> {
let tab = status.selected_non_mut();
self.term.clear()?;
- self.first_line(status)?;
self.term
.set_cursor(0, tab.input.cursor_index + Self::EDIT_BOX_OFFSET)?;
for (row, candidate) in tab.completion.proposals.iter().enumerate() {
@@ -259,7 +266,6 @@ impl Display {
fn confirmation(&mut self, status: &Status) -> FmResult<()> {
let tab = status.selected_non_mut();
self.term.clear()?;
- self.first_line(status)?;
for (row, path) in status.flagged.iter().enumerate() {
self.term.print_with_attr(
row + ContentWindow::WINDOW_MARGIN_TOP + 2,
@@ -309,7 +315,6 @@ impl Display {
fn preview(&mut self, status: &Status) -> FmResult<()> {
let tab = status.selected_non_mut();
self.term.clear()?;
- self.first_line(status)?;
let length = tab.preview.len();
let line_number_width = length.to_string().len();
@@ -401,7 +406,6 @@ impl Display {
fn marks(&mut self, status: &Status) -> FmResult<()> {
let tab = status.selected_non_mut();
self.term.clear()?;
- self.first_line(status)?;
self.term
.print_with_attr(2, 1, "mark path", Self::ATTR_YELLOW)?;
@@ -416,6 +420,17 @@ impl Display {
fn calc_line_row(i: usize, status: &Tab) -> usize {
i + ContentWindow::WINDOW_MARGIN_TOP - status.window.top
}
+
+ fn disk_space(&mut self, path_str: String) -> u64 {
+ self.sys.refresh_disks();
+ let mut size = 0_u64;
+ for disk in self.sys.disks() {
+ if path_str.contains(disk.mount_point().as_os_str().to_str().unwrap()) {
+ size = disk.available_space();
+ };
+ }
+ size
+ }
}
fn format_line_nr_hex(line_nr: usize, width: usize) -> String {
diff --git a/src/fileinfo.rs b/src/fileinfo.rs
index 389cf18..e9a7842 100644
--- a/src/fileinfo.rs
+++ b/src/fileinfo.rs
@@ -4,7 +4,7 @@ use std::path;
use chrono::offset::Local;
use chrono::DateTime;
-use fs_extra::dir::get_size;
+// use fs_extra::dir::get_size;
use tuikit::prelude::{Attr, Color, Effect};
use users::get_user_by_uid;
@@ -247,7 +247,7 @@ impl PathContent {
files[selected].select();
}
let reverse = false;
- let used_space = get_size(&path)?;
+ let used_space = get_size(path.clone()).unwrap_or_default();
Ok(Self {
path,
@@ -505,3 +505,19 @@ fn extract_extension_from_filename(filename: &str) -> &str {
.and_then(std::ffi::OsStr::to_str)
.unwrap_or_default()
}
+
+fn get_size(path: path::PathBuf) -> FmResult<u64> {
+ let mut result = 0;
+
+ if path.is_dir() {
+ for entry in read_dir(&path)? {
+ let _path = entry?.path();
+ if _path.is_file() {
+ result += _path.metadata()?.len();
+ }
+ }
+ } else {
+ result = path.metadata()?.len();
+ }
+ Ok(result)
+}
diff --git a/src/git.rs b/src/git.rs
index 6c9e47f..ab6cf1f 100644
--- a/src/git.rs
+++ b/src/git.rs
@@ -76,12 +76,12 @@ fn parse_porcelain2(data: String) -> Option<GitStatus> {
}
pub fn git(path: &Path) -> Result<String, Box<dyn Error>> {
- if std::env::set_current_dir(&path).is_err() {
+ if std::env::set_current_dir(path).is_err() {
// The path may not exist. It should never happen.
return Ok("".to_owned());
}
let output = process::Command::new("git")
- .args(&[
+ .args([
"status",
"--porcelain=v2",
"-z",