Procházet zdrojové kódy

fix width of hyperlinked escaped entries

dankeyy před 2 roky
rodič
revize
8196d52dd3
2 změnil soubory, kde provedl 11 přidání a 3 odebrání
  1. 5 0
      src/output/file_name.rs
  2. 6 3
      src/output/grid.rs

+ 5 - 0
src/output/file_name.rs

@@ -388,6 +388,11 @@ impl<'a, 'dir, C: Colours> FileName<'a, 'dir, C> {
             _                            => self.colours.colour_file(self.file),
         }
     }
+
+    /// For grid's use, to cover the case of hyperlink escape sequences
+    pub fn bare_width(&self) -> usize {
+        self.file.name.len()
+    }
 }
 
 

+ 6 - 3
src/output/grid.rs

@@ -41,11 +41,14 @@ impl<'a> Render<'a> {
 
         self.filter.sort_files(&mut self.files);
         for file in &self.files {
-            let filename = self.file_style.for_file(file, self.theme).paint();
+            let filename = self.file_style.for_file(file, self.theme);
+            let contents = filename.paint();
 
             grid.add(tg::Cell {
-                contents:  filename.strings().to_string(),
-                width:     *filename.width(),
+                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(),
                 alignment: tg::Alignment::Left,
             });
         }