Przeglądaj źródła

Merge pull request #105 from cafkafk/issue-103

fix: output wraps in terminal
Christina Sørensen 2 lat temu
rodzic
commit
4733827886
2 zmienionych plików z 10 dodań i 2 usunięć
  1. 1 1
      src/output/file_name.rs
  2. 9 1
      src/output/grid.rs

+ 1 - 1
src/output/file_name.rs

@@ -111,7 +111,7 @@ pub struct FileName<'a, 'dir, C> {
     /// How to handle displaying links.
     link_style: LinkStyle,
 
-    options: Options,
+    pub options: Options,
 }
 
 impl<'a, 'dir, C> FileName<'a, 'dir, C> {

+ 9 - 1
src/output/grid.rs

@@ -5,6 +5,7 @@ use term_grid as tg;
 use crate::fs::File;
 use crate::fs::filter::FileFilter;
 use crate::output::file_name::Options as FileStyle;
+use crate::output::file_name::{ShowIcons, EmbedHyperlinks};
 use crate::theme::Theme;
 
 
@@ -43,12 +44,19 @@ impl<'a> Render<'a> {
         for file in &self.files {
             let filename = self.file_style.for_file(file, self.theme);
             let contents = filename.paint();
+            let width;
+
+            match (filename.options.embed_hyperlinks, filename.options.show_icons) {
+                (EmbedHyperlinks::On, ShowIcons::On(spacing)) => width = filename.bare_width() + 1 + (spacing as usize),
+                (EmbedHyperlinks::On, ShowIcons::Off) => width = filename.bare_width(),
+                (EmbedHyperlinks::Off, _) => width = *contents.width(),
+            };
 
             grid.add(tg::Cell {
                 contents:  contents.strings().to_string(),
                 // with hyperlink escape sequences,
                 // the actual *contents.width() is larger than actually needed, so we take only the filename
-                width:     filename.bare_width(),
+                width:     width,
             });
         }