mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-11-05 12:27:53 +00:00
Make DeviceIDs its own type
This is so we can define a render method on it.
This commit is contained in:
parent
24a5d71f4b
commit
ddd34f3b1f
@ -135,14 +135,17 @@ pub enum Size {
|
||||
///
|
||||
/// This is what ls does as well. Without it, the devices will just have
|
||||
/// file sizes of zero.
|
||||
///
|
||||
/// You can see what these device numbers mean:
|
||||
/// - http://www.lanana.org/docs/device-list/
|
||||
/// - http://www.lanana.org/docs/device-list/devices-2.6+.txt
|
||||
DeviceIDs {
|
||||
major: u8,
|
||||
minor: u8,
|
||||
}
|
||||
DeviceIDs(DeviceIDs),
|
||||
}
|
||||
|
||||
/// The major and minor device IDs that gets displayed for device files.
|
||||
///
|
||||
/// You can see what these device numbers mean:
|
||||
/// - http://www.lanana.org/docs/device-list/
|
||||
/// - http://www.lanana.org/docs/device-list/devices-2.6+.txt
|
||||
pub struct DeviceIDs {
|
||||
pub major: u8,
|
||||
pub minor: u8,
|
||||
}
|
||||
|
||||
|
||||
|
@ -273,10 +273,10 @@ impl<'dir> File<'dir> {
|
||||
}
|
||||
else if self.is_char_device() || self.is_block_device() {
|
||||
let dev = self.metadata.rdev();
|
||||
f::Size::DeviceIDs {
|
||||
f::Size::DeviceIDs(f::DeviceIDs {
|
||||
major: (dev / 256) as u8,
|
||||
minor: (dev % 256) as u8,
|
||||
}
|
||||
})
|
||||
}
|
||||
else {
|
||||
f::Size::Some(self.metadata.len())
|
||||
|
@ -11,9 +11,9 @@ impl f::Size {
|
||||
use number_prefix::{Prefixed, Standalone, PrefixNames};
|
||||
|
||||
let size = match *self {
|
||||
f::Size::Some(s) => s,
|
||||
f::Size::None => return TextCell::blank(colours.punctuation),
|
||||
f::Size::DeviceIDs { major, minor } => return render_device_ids(colours, major, minor),
|
||||
f::Size::Some(s) => s,
|
||||
f::Size::None => return TextCell::blank(colours.punctuation),
|
||||
f::Size::DeviceIDs(ref ids) => return ids.render(colours),
|
||||
};
|
||||
|
||||
let result = match size_format {
|
||||
@ -48,16 +48,18 @@ impl f::Size {
|
||||
}
|
||||
}
|
||||
|
||||
fn render_device_ids(colours: &Colours, major: u8, minor: u8) -> TextCell {
|
||||
let major = major.to_string();
|
||||
let minor = minor.to_string();
|
||||
impl f::DeviceIDs {
|
||||
fn render(&self, colours: &Colours) -> TextCell {
|
||||
let major = self.major.to_string();
|
||||
let minor = self.minor.to_string();
|
||||
|
||||
TextCell {
|
||||
width: DisplayWidth::from(major.len() + 1 + minor.len()),
|
||||
contents: vec![
|
||||
colours.size.major.paint(major),
|
||||
colours.punctuation.paint(","),
|
||||
colours.size.minor.paint(minor),
|
||||
].into(),
|
||||
TextCell {
|
||||
width: DisplayWidth::from(major.len() + 1 + minor.len()),
|
||||
contents: vec![
|
||||
colours.size.major.paint(major),
|
||||
colours.punctuation.paint(","),
|
||||
colours.size.minor.paint(minor),
|
||||
].into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user