Skip to content

Commit

Permalink
add labels
Browse files Browse the repository at this point in the history
Fix #15
  • Loading branch information
Canop committed Oct 16, 2021
1 parent 98dab67 commit 660c682
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 32 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<a name="v1.2.0"></a>
### v1.2.0 - 2021/10/16
- filesystem labels added to JSON when found
- `-l` launch argument adds a "label" column to the table

<a name="v1.1.0"></a>
### v1.1.0 - 2021/10/08
--units launch argument, to choose between SI units or the old binary ones - Fix #17
Expand Down
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "lfs"
version = "1.2.0-dev"
version = "1.2.0"
authors = ["dystroy <denys.seguret@gmail.com>"]
edition = "2018"
keywords = ["linux", "filesystem", "fs"]
Expand All @@ -12,15 +12,15 @@ readme = "README.md"

[dependencies]
argh = "0.1.4"
crossterm = "0.20.0"
crossterm = "0.21.0"
file-size = "1.0.3"
lfs-core = "0.5.0"
minimad = "0.8.0"
minimad = "0.9.0"
serde ="1.0"
serde_json = "1.0"
termimad = "0.14.0"
termimad = "0.16.3"

[patch.crates-io]
#minimad = { path = "../minimad" }
#termimad = { path = "../termimad" }
# minimad = { path = "../minimad" }
# termimad = { path = "../termimad" }
#lfs-core = { path = "../lfs-core" }
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ pacman -S lfs
```
lfs
```

### All filesystems

By default, **lfs** only shows mount points backed by normal block devices, which are usually the "storage" filesystems you're interested into.

To show them all, use
Expand All @@ -65,13 +68,27 @@ To show them all, use
lfs -a
```

### JSON

To get the output as JSON, do `lfs -j` or `lfs -a -j`.

### Find the filesystem you're interested into

You may pass a path to have only the relevant device shown.
For example:

![lfs dot](doc/lfs-dot.png)

### Show labels

Labels aren't frequently defined, or useful, so they're not displayed by default.

Use `--labels` or `-l` to display them in the table:

![labels](doc/labels.png)

### Other options

Use `lfs --help` to list the other arguments.

## Internals
Expand Down
Binary file added doc/labels.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ pub struct Args {
#[argh(switch, short = 'a')]
pub all: bool,

/// whether to show labels in the table
#[argh(switch, short = 'l')]
pub labels: bool,

/// output as JSON
#[argh(switch, short = 'j')]
pub json: bool,
Expand Down
49 changes: 31 additions & 18 deletions src/fmt_mount.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use {
crate::units::Units,
crate::*,
crossterm::style::Color::*,
lfs_core::*,
minimad::{OwningTemplateExpander, TextTemplate},
minimad::{*, Alignment::*},
termimad::{CompoundStyle, MadSkin, ProgressBar},
};

Expand All @@ -15,46 +15,59 @@ static SIZE_COLOR: u8 = 172;

static BAR_WIDTH: usize = 5;

static MD: &str = r#"
|-:|:-:|:-:|:-:|:-:|-:|:-:|:-:|:-|:-
|id|dev|filesystem|disk|type|used|use%|free|size|mount point
|-:|:-|:-|:-:|:-:|-:|-:|-:|:-
${mount-points
|${id}|${dev-major}:${dev-minor}|${fs}|${disk}|${fs-type}|~~${used}~~|~~${use-percents}~~ `${bar}`|*${available}*|**${size}**|${mount-point}
}
|-:
"#;
pub fn print(mounts: &[Mount], color: bool, args: &Args) {

pub fn print(mounts: &[Mount], color: bool, units: Units) {
let units = args.units;
let mut expander = OwningTemplateExpander::new();
expander.set_default("");
for mount in mounts {
let sub = expander
.sub("mount-points")
.sub("rows")
.set("id", mount.info.id)
.set("dev-major", mount.info.dev.major)
.set("dev-minor", mount.info.dev.minor)
.set("fs", &mount.info.fs)
.set("filesystem", &mount.info.fs)
.set("disk", mount.disk.as_ref().map_or("", |d| d.disk_type()))
.set("fs-type", &mount.info.fs_type)
.set("type", &mount.info.fs_type)
.set("mount-point", mount.info.mount_point.to_string_lossy());
if let Some(label) = &mount.fs_label {
sub.set("label", label);
}
if let Some(stats) = mount.stats.as_ref().filter(|s| s.size() > 0) {
let use_share = stats.use_share();
let pb = ProgressBar::new(use_share as f32, BAR_WIDTH);
sub.set("size", units.fmt(stats.size()))
.set("used", units.fmt(stats.used()))
.set("use-percents", format!("{:.0}%", 100.0 * use_share))
.set("bar", format!("{:<width$}", pb, width = BAR_WIDTH))
.set("available", units.fmt(stats.available()));
.set("free", units.fmt(stats.available()));
}
}
let skin = if color {
make_colored_skin()
} else {
MadSkin::no_style()
};
let template = TextTemplate::from(MD);
skin.print_owning_expander(&expander, &template);

let mut tbl = TableBuilder::default();
tbl
.col(Col::simple("id").align(Right))
.col(Col::new("dev", "${dev-major}:${dev-minor}"))
.col(Col::simple("filesystem"));
if args.labels {
tbl.col(Col::simple("label"));
}
tbl
.col(Col::simple("disk").align_content(Center))
.col(Col::simple("type"))
.col(Col::new("used", "~~${used}~~"))
.col(Col::new("use%", "~~${use-percents}~~ `${bar}`").align_content(Right))
.col(Col::new("free", "*${free}*").align(Right))
.col(Col::new("size", "**${size}**"))
.col(Col::simple("mount point").align(Left));


skin.print_owning_expander_md(&expander, &tbl);
}

fn make_colored_skin() -> MadSkin {
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn main() -> lfs_core::Result<()> {
mounts.sort_by_key(|m| Reverse(m.size()));
let color = args.color.value()
.unwrap_or_else(|| std::io::stdout().is_tty());
fmt_mount::print(&mounts, color, args.units);
fmt_mount::print(&mounts, color, &args);
}
Ok(())
}

0 comments on commit 660c682

Please sign in to comment.