mirror of
https://github.com/Llewellynvdm/exa.git
synced 2025-01-16 11:10:32 +00:00
moved icons functionality to grid mode
This commit is contained in:
parent
d962889134
commit
217d1eefa9
@ -35,7 +35,7 @@ use fs::feature::git::GitCache;
|
||||
use options::{Options, Vars};
|
||||
pub use options::vars;
|
||||
pub use options::Misfire;
|
||||
use output::{escape, icons, lines, grid, grid_details, details, View, Mode};
|
||||
use output::{escape, lines, grid, grid_details, details, View, Mode};
|
||||
|
||||
mod fs;
|
||||
mod info;
|
||||
@ -221,11 +221,6 @@ impl<'args, 'w, W: Write + 'w> Exa<'args, 'w, W> {
|
||||
let View { ref mode, ref colours, ref style } = self.options.view;
|
||||
|
||||
match *mode {
|
||||
Mode::Icons(ref opts) => {
|
||||
println!("ICONS MODE");
|
||||
let r = icons::Render { files, colours, style, opts };
|
||||
r.render(self.writer)
|
||||
}
|
||||
Mode::Lines => {
|
||||
let r = lines::Render { files, colours, style };
|
||||
r.render(self.writer)
|
||||
|
@ -1,4 +1,4 @@
|
||||
use output::{View, Mode, grid, details, icons};
|
||||
use output::{View, Mode, grid, details};
|
||||
use output::grid_details::{self, RowThreshold};
|
||||
use output::table::{TimeTypes, Environment, SizeFormat, Columns, Options as TableOptions};
|
||||
use output::time::TimeFormat;
|
||||
@ -63,17 +63,11 @@ impl Mode {
|
||||
|
||||
Ok(Mode::Details(details))
|
||||
}
|
||||
else if matches.has(&flags::ICONS)? {
|
||||
let grid = icons::Options {
|
||||
across: matches.has(&flags::ACROSS)?,
|
||||
console_width: width,
|
||||
};
|
||||
Ok(Mode::Icons(grid))
|
||||
}
|
||||
else {
|
||||
let grid = grid::Options {
|
||||
across: matches.has(&flags::ACROSS)?,
|
||||
console_width: width,
|
||||
icons: matches.has(&flags::ICONS)?,
|
||||
};
|
||||
|
||||
Ok(Mode::Grid(grid))
|
||||
@ -363,9 +357,9 @@ mod test {
|
||||
|
||||
static TEST_ARGS: &[&Arg] = &[ &flags::BINARY, &flags::BYTES, &flags::TIME_STYLE,
|
||||
&flags::TIME, &flags::MODIFIED, &flags::CREATED, &flags::ACCESSED,
|
||||
&flags::HEADER, &flags::GROUP, &flags::INODE, &flags::GIT,
|
||||
&flags::LINKS, &flags::BLOCKS, &flags::LONG, &flags::LEVEL,
|
||||
&flags::GRID, &flags::ACROSS, &flags::ONE_LINE ];
|
||||
&flags::HEADER, &flags::GROUP, &flags::ICONS, &flags::INODE,
|
||||
&flags::GIT, &flags::LINKS, &flags::BLOCKS, &flags::LONG,
|
||||
&flags::LEVEL, &flags::GRID, &flags::ACROSS, &flags::ONE_LINE ];
|
||||
|
||||
macro_rules! test {
|
||||
|
||||
@ -528,10 +522,11 @@ mod test {
|
||||
test!(empty: Mode <- [], None; Both => like Ok(Mode::Grid(_)));
|
||||
|
||||
// Grid views
|
||||
test!(original_g: Mode <- ["-G"], None; Both => like Ok(Mode::Grid(GridOptions { across: false, console_width: _ })));
|
||||
test!(grid: Mode <- ["--grid"], None; Both => like Ok(Mode::Grid(GridOptions { across: false, console_width: _ })));
|
||||
test!(across: Mode <- ["--across"], None; Both => like Ok(Mode::Grid(GridOptions { across: true, console_width: _ })));
|
||||
test!(gracross: Mode <- ["-xG"], None; Both => like Ok(Mode::Grid(GridOptions { across: true, console_width: _ })));
|
||||
test!(original_g: Mode <- ["-G"], None; Both => like Ok(Mode::Grid(GridOptions { across: false, console_width: _, icons: _ })));
|
||||
test!(grid: Mode <- ["--grid"], None; Both => like Ok(Mode::Grid(GridOptions { across: false, console_width: _, icons: _ })));
|
||||
test!(across: Mode <- ["--across"], None; Both => like Ok(Mode::Grid(GridOptions { across: true, console_width: _, icons: _ })));
|
||||
test!(gracross: Mode <- ["-xG"], None; Both => like Ok(Mode::Grid(GridOptions { across: true, console_width: _, icons: _ })));
|
||||
test!(icons: Mode <- ["--icons"], None; Both => like Ok(Mode::Grid(GridOptions { across: _, console_width: _, icons: true})));
|
||||
|
||||
// Lines views
|
||||
test!(lines: Mode <- ["--oneline"], None; Both => like Ok(Mode::Lines));
|
||||
|
@ -5,12 +5,15 @@ use term_grid as tg;
|
||||
use fs::File;
|
||||
use style::Colours;
|
||||
use output::file_name::FileStyle;
|
||||
use output::icons::painted_icon;
|
||||
use output::cell::DisplayWidth;
|
||||
|
||||
|
||||
#[derive(PartialEq, Debug, Copy, Clone)]
|
||||
pub struct Options {
|
||||
pub across: bool,
|
||||
pub console_width: usize,
|
||||
pub icons: bool,
|
||||
}
|
||||
|
||||
impl Options {
|
||||
@ -38,11 +41,16 @@ impl<'a> Render<'a> {
|
||||
grid.reserve(self.files.len());
|
||||
|
||||
for file in self.files.iter() {
|
||||
let icon = if self.opts.icons { Some(painted_icon(&file, &self.style)) } else { None };
|
||||
let filename = self.style.for_file(file, self.colours).paint();
|
||||
let width = filename.width();
|
||||
let width = if self.opts.icons {
|
||||
DisplayWidth::from(2) + filename.width()
|
||||
} else {
|
||||
filename.width()
|
||||
};
|
||||
|
||||
grid.add(tg::Cell {
|
||||
contents: filename.strings().to_string(),
|
||||
contents: format!("{icon}{filename}", icon=&icon.unwrap_or("".to_string()), filename=filename.strings().to_string()),
|
||||
width: *width,
|
||||
});
|
||||
}
|
||||
|
@ -1,71 +1,13 @@
|
||||
use std::io::{Write, Result as IOResult};
|
||||
|
||||
use term_grid as tg;
|
||||
|
||||
use fs::File;
|
||||
use style::Colours;
|
||||
use output::file_name::FileStyle;
|
||||
use output::cell::DisplayWidth;
|
||||
|
||||
pub fn painted_icon(file: &File, style: &FileStyle) -> String {
|
||||
let file_icon = icon(&file).to_string();
|
||||
let painted = style.exts
|
||||
.colour_file(&file)
|
||||
.map_or(file_icon.to_string(), |c| { c.paint(file_icon).to_string() });
|
||||
format!("{} ", painted)
|
||||
|
||||
#[derive(PartialEq, Debug, Copy, Clone)]
|
||||
pub struct Options {
|
||||
pub across: bool,
|
||||
pub console_width: usize,
|
||||
}
|
||||
|
||||
impl Options {
|
||||
pub fn direction(&self) -> tg::Direction {
|
||||
if self.across { tg::Direction::LeftToRight }
|
||||
else { tg::Direction::TopToBottom }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub struct Render<'a> {
|
||||
pub files: Vec<File<'a>>,
|
||||
pub colours: &'a Colours,
|
||||
pub style: &'a FileStyle,
|
||||
pub opts: &'a Options,
|
||||
}
|
||||
|
||||
impl<'a> Render<'a> {
|
||||
pub fn render<W: Write>(&self, w: &mut W) -> IOResult<()> {
|
||||
let mut grid = tg::Grid::new(tg::GridOptions {
|
||||
direction: self.opts.direction(),
|
||||
filling: tg::Filling::Spaces(2),
|
||||
});
|
||||
|
||||
grid.reserve(self.files.len());
|
||||
|
||||
for file in self.files.iter() {
|
||||
let file_icon = icon(&file);
|
||||
let painted_icon = self.style.exts
|
||||
.colour_file(&file)
|
||||
.map_or(file_icon.to_string(), |c| { c.paint(format!("{}", file_icon)).to_string() });
|
||||
let filename = self.style.for_file(file, self.colours).paint();
|
||||
let width = DisplayWidth::from(2) + filename.width();
|
||||
|
||||
grid.add(tg::Cell {
|
||||
contents: format!("{} {}", painted_icon, filename.strings().to_string()),
|
||||
width: *width,
|
||||
});
|
||||
}
|
||||
|
||||
if let Some(display) = grid.fit_into_width(self.opts.console_width) {
|
||||
write!(w, "{}", display)
|
||||
}
|
||||
else {
|
||||
// File names too long for a grid - drop down to just listing them!
|
||||
// This isn’t *quite* the same as the lines view, which also
|
||||
// displays full link paths.
|
||||
for file in self.files.iter() {
|
||||
let name_cell = self.style.for_file(file, self.colours).paint();
|
||||
writeln!(w, "{}", name_cell.strings())?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn icon(file: &File) -> char {
|
||||
@ -121,6 +63,7 @@ fn icon(file: &File) -> char {
|
||||
"r" => '\u{f25d}',
|
||||
"rb" => '\u{e21e}',
|
||||
"rdb" => '\u{e76d}',
|
||||
"rs" => '\u{e7a8}',
|
||||
"rss" => '\u{f09e}',
|
||||
"rubydoc" => '\u{e73b}',
|
||||
"sass" => '\u{e603}',
|
||||
|
@ -34,6 +34,5 @@ pub enum Mode {
|
||||
Grid(grid::Options),
|
||||
Details(details::Options),
|
||||
GridDetails(grid_details::Options),
|
||||
Icons(icons::Options),
|
||||
Lines,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user