Explorar o código

Go top-to-bottom, not left-to-right

Ben S %!s(int64=10) %!d(string=hai) anos
pai
achega
89526964c9
Modificáronse 1 ficheiros con 15 adicións e 13 borrados
  1. 15 13
      src/output/grid_details.rs

+ 15 - 13
src/output/grid_details.rs

@@ -40,29 +40,31 @@ impl GridDetails {
 
         let mut tables: Vec<_> = repeat(()).map(|_| make_table()).take(column_count).collect();
 
+        let mut height = files.len() / column_count;
+        if files.len() % column_count != 0 {
+            height += 1;
+        }
+
         for (i, file) in files.iter().enumerate() {
-            tables[i % column_count].add_file(file, 0, false, false);
+            tables[i / height].add_file(file, 0, false, false);
         }
 
-        let direction = grid::Direction::LeftToRight;
+        let columns: Vec<_> = tables.iter().map(|t| t.print_table(false, false)).collect();
 
+        let direction = grid::Direction::TopToBottom;
         let mut grid = grid::Grid::new(grid::GridOptions {
             direction:        direction,
             separator_width:  4,
         });
 
-        let columns: Vec<_> = tables.iter().map(|t| t.print_table(false, false)).collect();
-
-        for row in 0 .. columns[0].len() {
-            for column in columns.iter() {
-                if row < column.len() {
-                    let cell = grid::Cell {
-                        contents: column[row].text.clone(),
-                        width:    column[row].length,
-                    };
+        for column in columns.iter() {
+            for cell in column.iter() {
+                let cell = grid::Cell {
+                    contents: cell.text.clone(),
+                    width:    cell.length,
+                };
 
-                    grid.add(cell);
-                }
+                grid.add(cell);
             }
         }