summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenys Séguret <cano.petrole@gmail.com>2024-06-03 16:26:35 +0200
committerGitHub <noreply@github.com>2024-06-03 16:26:35 +0200
commit18a6b88f3299eb1254f32c04da2746912b4dc475 (patch)
treef2f251cb14b9c0a6e0fbd60ff8625cd5b06328db
parent91824098b1b855db4e968e0e70b1439c836dfd70 (diff)
parent802acc4764a8ad0a6f1c0645d1cd91e0a5b38826 (diff)
Merge pull request #75 from Canop/free-percent
free_percent column Fix #74
-rw-r--r--CHANGELOG.md3
-rw-r--r--cli/src/col.rs12
-rw-r--r--cli/src/col_expr.rs2
-rw-r--r--cli/src/csv.rs1
-rw-r--r--cli/src/table.rs5
-rw-r--r--website/docs/table.md1
6 files changed, 22 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7a6fdea..8c7fb3b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,6 @@
+### next
+- new column: `free_percent` - Fix #74
+
<a name="v2.8.2"></a>
### v2.8.2 - 2023/10/14
- cross-project dependency versions harmonization to ease vetting
diff --git a/cli/src/col.rs b/cli/src/col.rs
index 95ac649..0e01b7d 100644
--- a/cli/src/col.rs
+++ b/cli/src/col.rs
@@ -95,6 +95,7 @@ col_enum!(
Use "use": "use" default,
UsePercent "use_percent": "use%",
Free "free": "free" default,
+ FreePercent "free_percent": "free%",
Size "size": "size" default,
InodesUsed "inodes_used" "iused": "used inodes",
InodesUse "inodes" "ino" "inodes_use" "iuse": "inodes",
@@ -125,6 +126,7 @@ impl Col {
Self::Use => Alignment::Right,
Self::UsePercent => Alignment::Right,
Self::Free => Alignment::Right,
+ Self::FreePercent => Alignment::Right,
Self::Size => Alignment::Right,
Self::InodesUsed => Alignment::Right,
Self::InodesUse => Alignment::Right,
@@ -147,6 +149,7 @@ impl Col {
Self::Use => "usage graphical view",
Self::UsePercent => "percentage of blocks used",
Self::Free => "free bytes",
+ Self::FreePercent => "percentage of free blocks",
Self::Size => "total size",
Self::InodesUsed => "number of inodes used",
Self::InodesUse => "graphical view of inodes usage",
@@ -182,6 +185,8 @@ impl Col {
(None, None) => Ordering::Equal,
},
Self::Use | Self::UsePercent => |a: &Mount, b: &Mount| match (&a.stats(), &b.stats()) {
+ // the 'use' column shows the percentage of used blocks, so it makes sense
+ // to sort by use_share for it
// SAFETY: use_share() doesn't return NaN
(Some(a), Some(b)) => a.use_share().partial_cmp(&b.use_share()).unwrap(),
(Some(_), None) => Ordering::Greater,
@@ -194,6 +199,12 @@ impl Col {
(None, Some(_)) => Ordering::Less,
(None, None) => Ordering::Equal,
},
+ Self::FreePercent => |a: &Mount, b: &Mount| match (&a.stats(), &b.stats()) {
+ (Some(a), Some(b)) => b.use_share().partial_cmp(&a.use_share()).unwrap(),
+ (Some(_), None) => Ordering::Greater,
+ (None, Some(_)) => Ordering::Less,
+ (None, None) => Ordering::Equal,
+ },
Self::Size => |a: &Mount, b: &Mount| match (&a.stats(), &b.stats()) {
(Some(a), Some(b)) => a.size().cmp(&b.size()),
(Some(_), None) => Ordering::Greater,
@@ -241,6 +252,7 @@ impl Col {
Self::Use => Order::Desc,
Self::UsePercent => Order::Asc,
Self::Free => Order::Asc,
+ Self::FreePercent => Order::Desc,
Self::Size => Order::Desc,
Self::InodesUsed => Order::Asc,
Self::InodesUse => Order::Asc,
diff --git a/cli/src/col_expr.rs b/cli/src/col_expr.rs
index 2abf476..cdcb8c9 100644
--- a/cli/src/col_expr.rs
+++ b/cli/src/col_expr.rs
@@ -109,7 +109,7 @@ impl ColExpr {
mount.stats().as_ref().map(|s| s.use_share()),
parse_float(&self.value)?,
),
- Col::Free => self.operator.eval_option(
+ Col::Free | Col::FreePercent => self.operator.eval_option(
mount.stats().as_ref().map(|s| s.available()),
parse_integer(&self.value)?,
),
diff --git a/cli/src/csv.rs b/cli/src/csv.rs
index 2543154..3acddd2 100644
--- a/cli/src/csv.rs
+++ b/cli/src/csv.rs
@@ -70,6 +70,7 @@ pub fn print(mounts: &[&Mount], args: &Args) -> Result<(), std::io::Error> {
Col::Use => csv.cell_opt(mount.stats().map(|s| s.use_share())),
Col::UsePercent => csv.cell_opt(mount.stats().map(|s| format!("{:.0}%", 100.0 * s.use_share()))),
Col::Free => csv.cell_opt(mount.stats().map(|s| units.fmt(s.available()))),
+ Col::FreePercent => csv.cell_opt(mount.stats().map(|s| format!("{:.0}%", 100.0 * (1.0 - s.use_share())))),
Col::Size => csv.cell_opt(mount.stats().map(|s| units.fmt(s.size()))),
Col::InodesUsed => csv.cell_opt(mount.inodes().map(|i| i.used())),
Col::InodesUse => csv.cell_opt(mount.inodes().map(|i| i.use_share())),
diff --git a/cli/src/table.rs b/cli/src/table.rs
index 2454e53..fcda4d5 100644
--- a/cli/src/table.rs
+++ b/cli/src/table.rs
@@ -45,12 +45,14 @@ pub fn print(mounts: &[&Mount], color: bool, args: &Args) {
}
if let Some(stats) = mount.stats() {
let use_share = stats.use_share();
+ let free_share = 1.0 - use_share;
sub
.set("size", units.fmt(stats.size()))
.set("used", units.fmt(stats.used()))
.set("use-percents", format!("{:.0}%", 100.0 * use_share))
.set_md("bar", progress_bar_md(use_share, BAR_WIDTH, args.ascii))
- .set("free", units.fmt(stats.available()));
+ .set("free", units.fmt(stats.available()))
+ .set("free-percents", format!("{:.0}%", 100.0 * free_share));
if let Some(inodes) = &stats.inodes {
let iuse_share = inodes.use_share();
sub
@@ -90,6 +92,7 @@ pub fn print(mounts: &[&Mount], color: bool, args: &Args) {
Col::Use => "~~${use-percents}~~ ${bar}~~${use-error}~~",
Col::UsePercent => "~~${use-percents}~~",
Col::Free => "*${free}*",
+ Col::FreePercent => "*${free-percents}*",
Col::Size => "**${size}**",
Col::InodesFree => "*${ifree}*",
Col::InodesUsed => "~~${iused}~~",
diff --git a/website/docs/table.md b/website/docs/table.md
index d48a406..dd088b0 100644
--- a/website/docs/table.md
+++ b/website/docs/table.md
@@ -21,6 +21,7 @@ used | ✓ | cumulated size of the occupied blocks
use | ✓ | graphical view of the use share
use_percent | | percentage of occupied blocks
free | ✓ | cumulated size of the available blocks
+free_percent | | percentage of available blocks
size | ✓ | size of the volume
inodesfree | | available inodes
inodesused | | inodes used