mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-12-26 01:57:32 +00:00
Display device IDs when listing devices
Override the size column for block and charater devices, so it shows the major and minor device IDs instead (which are in the Metadata struct somewhere). This is what ls does when faced with a device.
This commit is contained in:
parent
de60b95850
commit
ef5fa90660
@ -129,6 +129,16 @@ pub enum Size {
|
||||
///
|
||||
/// See this answer for more: http://unix.stackexchange.com/a/68266
|
||||
None,
|
||||
|
||||
/// This file is a block or character device, so instead of a size, print
|
||||
/// out the file’s major and minor device IDs.
|
||||
///
|
||||
/// This is what ls does as well. Without it, the devices will just have
|
||||
/// file sizes of zero.
|
||||
DeviceIDs {
|
||||
major: u8,
|
||||
minor: u8,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -268,6 +268,13 @@ impl<'dir> File<'dir> {
|
||||
if self.is_directory() {
|
||||
f::Size::None
|
||||
}
|
||||
else if self.is_char_device() || self.is_block_device() {
|
||||
let dev = self.metadata.rdev();
|
||||
f::Size::DeviceIDs {
|
||||
major: (dev / 256) as u8,
|
||||
minor: (dev % 256) as u8,
|
||||
}
|
||||
}
|
||||
else {
|
||||
f::Size::Some(self.metadata.len())
|
||||
}
|
||||
|
@ -70,6 +70,9 @@ pub struct Size {
|
||||
pub numbers: Style,
|
||||
pub unit: Style,
|
||||
|
||||
pub major: Style,
|
||||
pub minor: Style,
|
||||
|
||||
pub scale_byte: Style,
|
||||
pub scale_kilo: Style,
|
||||
pub scale_mega: Style,
|
||||
@ -148,6 +151,9 @@ impl Colours {
|
||||
numbers: Green.bold(),
|
||||
unit: Green.normal(),
|
||||
|
||||
major: Green.bold(),
|
||||
minor: Green.normal(),
|
||||
|
||||
scale_byte: Fixed(118).normal(),
|
||||
scale_kilo: Fixed(190).normal(),
|
||||
scale_mega: Fixed(226).normal(),
|
||||
|
@ -579,8 +579,9 @@ impl<'a, U: Users+Groups+'a> Table<'a, U> {
|
||||
use number_prefix::{Prefixed, Standalone, PrefixNames};
|
||||
|
||||
let size = match size {
|
||||
f::Size::Some(s) => s,
|
||||
f::Size::None => return TextCell::blank(self.opts.colours.punctuation),
|
||||
f::Size::Some(s) => s,
|
||||
f::Size::None => return TextCell::blank(self.opts.colours.punctuation),
|
||||
f::Size::DeviceIDs { major, minor } => return self.render_device_ids(major, minor),
|
||||
};
|
||||
|
||||
let result = match size_format {
|
||||
@ -614,6 +615,20 @@ impl<'a, U: Users+Groups+'a> Table<'a, U> {
|
||||
}
|
||||
}
|
||||
|
||||
fn render_device_ids(&self, major: u8, minor: u8) -> TextCell {
|
||||
let major = major.to_string();
|
||||
let minor = minor.to_string();
|
||||
|
||||
TextCell {
|
||||
width: DisplayWidth::from(major.len() + 1 + minor.len()),
|
||||
contents: vec![
|
||||
self.opts.colours.size.major.paint(major),
|
||||
self.opts.colours.punctuation.paint(","),
|
||||
self.opts.colours.size.minor.paint(minor),
|
||||
].into(),
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(trivial_numeric_casts)]
|
||||
fn render_time(&self, timestamp: f::Time) -> TextCell {
|
||||
// TODO(ogham): This method needs some serious de-duping!
|
||||
|
@ -1,3 +1,3 @@
|
||||
[1;33mbr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m0[0m root [34m 1 Jan 12:34[0m [1;33mblock-device[0m
|
||||
[1;33mcr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m0[0m root [34m 1 Jan 12:34[0m [1;33mchar-device[0m
|
||||
[33m|[1mr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m0[0m root [34m 1 Jan 12:34[0m [33mnamed-pipe[0m
|
||||
[1;33mbr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m3[0m[38;5;244m,[32m60[0m root [34m 1 Jan 12:34[0m [1;33mblock-device[0m
|
||||
[1;33mcr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m14[0m[38;5;244m,[32m40[0m root [34m 1 Jan 12:34[0m [1;33mchar-device[0m
|
||||
[33m|[1mr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m0[0m root [34m 1 Jan 12:34[0m [33mnamed-pipe[0m
|
||||
|
@ -1,3 +1,3 @@
|
||||
[1;33mbr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m0[0m root [34m 1 Jan 12:34[0m [1;33mblock-device[0m
|
||||
[1;33mcr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m0[0m root [34m 1 Jan 12:34[0m [1;33mchar-device[0m
|
||||
[33m|[1mr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m0[0m root [34m 1 Jan 12:34[0m [33mnamed-pipe[0m|
|
||||
[1;33mbr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m3[0m[38;5;244m,[32m60[0m root [34m 1 Jan 12:34[0m [1;33mblock-device[0m
|
||||
[1;33mcr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m14[0m[38;5;244m,[32m40[0m root [34m 1 Jan 12:34[0m [1;33mchar-device[0m
|
||||
[33m|[1mr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m0[0m root [34m 1 Jan 12:34[0m [33mnamed-pipe[0m|
|
||||
|
Loading…
Reference in New Issue
Block a user