Răsfoiți Sursa

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.
Benjamin Sago 8 ani în urmă
părinte
comite
bfa65b3bec
5 a modificat fișierele cu 29 adăugiri și 14 ștergeri
  1. 4 2
      src/output/details.rs
  2. 16 5
      src/output/file_name.rs
  3. 5 3
      src/output/grid.rs
  4. 2 2
      src/output/grid_details.rs
  5. 2 2
      src/output/lines.rs

+ 4 - 2
src/output/details.rs

@@ -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);

+ 16 - 5
src/output/file_name.rs

@@ -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.
     ///

+ 5 - 3
src/output/grid.rs

@@ -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(())

+ 2 - 2
src/output/grid_details.rs

@@ -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);

+ 2 - 2
src/output/lines.rs

@@ -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()
     }
 }