mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-12-02 16:18:21 +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
|
/// This is what ls does as well. Without it, the devices will just have
|
||||||
/// file sizes of zero.
|
/// file sizes of zero.
|
||||||
///
|
DeviceIDs(DeviceIDs),
|
||||||
/// 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
|
/// The major and minor device IDs that gets displayed for device files.
|
||||||
DeviceIDs {
|
///
|
||||||
major: u8,
|
/// You can see what these device numbers mean:
|
||||||
minor: u8,
|
/// - 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() {
|
else if self.is_char_device() || self.is_block_device() {
|
||||||
let dev = self.metadata.rdev();
|
let dev = self.metadata.rdev();
|
||||||
f::Size::DeviceIDs {
|
f::Size::DeviceIDs(f::DeviceIDs {
|
||||||
major: (dev / 256) as u8,
|
major: (dev / 256) as u8,
|
||||||
minor: (dev % 256) as u8,
|
minor: (dev % 256) as u8,
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
f::Size::Some(self.metadata.len())
|
f::Size::Some(self.metadata.len())
|
||||||
|
@ -11,9 +11,9 @@ impl f::Size {
|
|||||||
use number_prefix::{Prefixed, Standalone, PrefixNames};
|
use number_prefix::{Prefixed, Standalone, PrefixNames};
|
||||||
|
|
||||||
let size = match *self {
|
let size = match *self {
|
||||||
f::Size::Some(s) => s,
|
f::Size::Some(s) => s,
|
||||||
f::Size::None => return TextCell::blank(colours.punctuation),
|
f::Size::None => return TextCell::blank(colours.punctuation),
|
||||||
f::Size::DeviceIDs { major, minor } => return render_device_ids(colours, major, minor),
|
f::Size::DeviceIDs(ref ids) => return ids.render(colours),
|
||||||
};
|
};
|
||||||
|
|
||||||
let result = match size_format {
|
let result = match size_format {
|
||||||
@ -48,16 +48,18 @@ impl f::Size {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_device_ids(colours: &Colours, major: u8, minor: u8) -> TextCell {
|
impl f::DeviceIDs {
|
||||||
let major = major.to_string();
|
fn render(&self, colours: &Colours) -> TextCell {
|
||||||
let minor = minor.to_string();
|
let major = self.major.to_string();
|
||||||
|
let minor = self.minor.to_string();
|
||||||
|
|
||||||
TextCell {
|
TextCell {
|
||||||
width: DisplayWidth::from(major.len() + 1 + minor.len()),
|
width: DisplayWidth::from(major.len() + 1 + minor.len()),
|
||||||
contents: vec![
|
contents: vec![
|
||||||
colours.size.major.paint(major),
|
colours.size.major.paint(major),
|
||||||
colours.punctuation.paint(","),
|
colours.punctuation.paint(","),
|
||||||
colours.size.minor.paint(minor),
|
colours.size.minor.paint(minor),
|
||||||
].into(),
|
].into(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user