mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-11-22 20:15:11 +00:00
Make not showing paths in link targets the default
This commit replaces the “two normal cases” of showing a link’s target or not with “one default and one special case” of preferring to hide them, displaying the link targets by setting a flag instead. Doing this simplifies the file name constructor, which gets to remove an argument.
This commit is contained in:
parent
0d613652a7
commit
bfa65b3bec
@ -70,7 +70,7 @@ use options::{FileFilter, RecurseOptions};
|
||||
use output::colours::Colours;
|
||||
use output::cell::TextCell;
|
||||
use output::tree::{TreeTrunk, TreeParams, TreeDepth};
|
||||
use output::file_name::{FileStyle, LinkStyle};
|
||||
use output::file_name::FileStyle;
|
||||
use output::table::{Table, Options as TableOptions, Row as TableRow};
|
||||
|
||||
|
||||
@ -233,7 +233,9 @@ impl<'a> Render<'a> {
|
||||
let row = Row {
|
||||
tree: tree_params,
|
||||
cells: egg.table_row,
|
||||
name: self.style.for_file(&egg.file, LinkStyle::FullLinkPaths, self.colours).paint().promote(),
|
||||
name: self.style.for_file(&egg.file, self.colours)
|
||||
.with_link_paths()
|
||||
.paint().promote(),
|
||||
};
|
||||
|
||||
rows.push(row);
|
||||
|
@ -20,10 +20,14 @@ impl FileStyle {
|
||||
|
||||
/// Create a new `FileName` that prints the given file’s name, painting it
|
||||
/// with the remaining arguments.
|
||||
pub fn for_file<'a, 'dir>(&self, file: &'a File<'dir>, link_style: LinkStyle, colours: &'a Colours) -> FileName<'a, 'dir> {
|
||||
let target = if file.is_link() { Some(file.link_target()) }
|
||||
else { None };
|
||||
FileName { file, colours, target, link_style, classify: self.classify }
|
||||
pub fn for_file<'a, 'dir>(&self, file: &'a File<'dir>, colours: &'a Colours) -> FileName<'a, 'dir> {
|
||||
FileName {
|
||||
file, colours,
|
||||
link_style: LinkStyle::JustFilenames,
|
||||
classify: self.classify,
|
||||
target: if file.is_link() { Some(file.link_target()) }
|
||||
else { None }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,7 +35,7 @@ impl FileStyle {
|
||||
/// When displaying a file name, there needs to be some way to handle broken
|
||||
/// links, depending on how long the resulting Cell can be.
|
||||
#[derive(PartialEq, Debug, Copy, Clone)]
|
||||
pub enum LinkStyle {
|
||||
enum LinkStyle {
|
||||
|
||||
/// Just display the file names, but colour them differently if they’re
|
||||
/// a broken link or can’t be followed.
|
||||
@ -87,6 +91,13 @@ pub struct FileName<'a, 'dir: 'a> {
|
||||
|
||||
impl<'a, 'dir> FileName<'a, 'dir> {
|
||||
|
||||
/// Sets the flag on this file name to display link targets with an
|
||||
/// arrow followed by their path.
|
||||
pub fn with_link_paths(mut self) -> Self {
|
||||
self.link_style = LinkStyle::FullLinkPaths;
|
||||
self
|
||||
}
|
||||
|
||||
/// Paints the name of the file using the colours, resulting in a vector
|
||||
/// of coloured cells that can be printed to the terminal.
|
||||
///
|
||||
|
@ -4,7 +4,7 @@ use term_grid as tg;
|
||||
|
||||
use fs::File;
|
||||
use output::colours::Colours;
|
||||
use output::file_name::{FileStyle, LinkStyle};
|
||||
use output::file_name::FileStyle;
|
||||
|
||||
|
||||
#[derive(PartialEq, Debug, Copy, Clone)]
|
||||
@ -38,7 +38,7 @@ impl<'a> Render<'a> {
|
||||
grid.reserve(self.files.len());
|
||||
|
||||
for file in self.files.iter() {
|
||||
let filename = self.style.for_file(file, LinkStyle::JustFilenames, self.colours).paint();
|
||||
let filename = self.style.for_file(file, self.colours).paint();
|
||||
let width = filename.width();
|
||||
|
||||
grid.add(tg::Cell {
|
||||
@ -52,8 +52,10 @@ impl<'a> Render<'a> {
|
||||
}
|
||||
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, LinkStyle::JustFilenames, self.colours).paint();
|
||||
let name_cell = self.style.for_file(file, self.colours).paint();
|
||||
writeln!(w, "{}", name_cell.strings())?;
|
||||
}
|
||||
Ok(())
|
||||
|
@ -11,7 +11,7 @@ use output::cell::TextCell;
|
||||
use output::colours::Colours;
|
||||
use output::details::{Options as DetailsOptions, Row as DetailsRow, Render as DetailsRender};
|
||||
use output::grid::Options as GridOptions;
|
||||
use output::file_name::{FileStyle, LinkStyle};
|
||||
use output::file_name::FileStyle;
|
||||
use output::table::{Table, Row as TableRow, Options as TableOptions};
|
||||
use output::tree::{TreeParams, TreeDepth};
|
||||
|
||||
@ -52,7 +52,7 @@ impl<'a> Render<'a> {
|
||||
.collect::<Vec<TableRow>>();
|
||||
|
||||
let file_names = self.files.iter()
|
||||
.map(|file| self.style.for_file(file, LinkStyle::JustFilenames, self.colours).paint().promote())
|
||||
.map(|file| self.style.for_file(file, self.colours).paint().promote())
|
||||
.collect::<Vec<TextCell>>();
|
||||
|
||||
let mut last_working_table = self.make_grid(1, options, &file_names, rows.clone(), &drender);
|
||||
|
@ -4,7 +4,7 @@ use ansi_term::ANSIStrings;
|
||||
|
||||
use fs::File;
|
||||
|
||||
use output::file_name::{FileName, FileStyle, LinkStyle};
|
||||
use output::file_name::{FileName, FileStyle};
|
||||
use super::colours::Colours;
|
||||
|
||||
|
||||
@ -26,6 +26,6 @@ impl<'a> Render<'a> {
|
||||
}
|
||||
|
||||
fn render_file<'f>(&self, file: &'f File<'a>) -> FileName<'f, 'a> {
|
||||
self.style.for_file(file, LinkStyle::FullLinkPaths, self.colours)
|
||||
self.style.for_file(file, self.colours).with_link_paths()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user