瀏覽代碼

Move size format out of Column

Way in the past, the size format was the only variable column; the others were all fixed. Now there are many configurable columns and this field was still hanging around. The code that does the rendering just gets the size format as an argument, and now it works the same way as the TimeFormat.
Benjamin Sago 8 年之前
父節點
當前提交
e98c765078
共有 1 個文件被更改,包括 12 次插入6 次删除
  1. 12 6
      src/output/table.rs

+ 12 - 6
src/output/table.rs

@@ -57,7 +57,7 @@ impl Options {
             columns.push(Column::HardLinks);
         }
 
-        columns.push(Column::FileSize(self.size_format));
+        columns.push(Column::FileSize);
 
         if self.blocks {
             columns.push(Column::Blocks);
@@ -98,7 +98,7 @@ impl Options {
 #[derive(Debug)]
 pub enum Column {
     Permissions,
-    FileSize(SizeFormat),
+    FileSize,
     Timestamp(TimeType),
     Blocks,
     User,
@@ -120,7 +120,7 @@ impl Column {
     /// Get the alignment this column should use.
     pub fn alignment(&self) -> Alignment {
         match *self {
-            Column::FileSize(_)
+            Column::FileSize
             | Column::HardLinks
             | Column::Inode
             | Column::Blocks
@@ -134,7 +134,7 @@ impl Column {
     pub fn header(&self) -> &'static str {
         match *self {
             Column::Permissions   => "Permissions",
-            Column::FileSize(_)   => "Size",
+            Column::FileSize      => "Size",
             Column::Timestamp(t)  => t.header(),
             Column::Blocks        => "Blocks",
             Column::User          => "User",
@@ -276,6 +276,7 @@ pub struct Table<'a> {
     env: &'a Environment,
     widths: TableWidths,
     time_format: &'a TimeFormat,
+    size_format: SizeFormat,
 }
 
 #[derive(Clone)]
@@ -287,7 +288,12 @@ impl<'a, 'f> Table<'a> {
     pub fn new(options: &'a Options, dir: Option<&'a Dir>, colours: &'a Colours) -> Table<'a> {
         let colz = options.for_dir(dir);
         let widths = TableWidths::zero(colz.len());
-        Table { columns: colz, colours, env: &options.env, widths, time_format: &options.time_format }
+        Table { colours, widths,
+            columns: colz,
+            env:         &options.env,
+            time_format: &options.time_format,
+            size_format:  options.size_format,
+        }
     }
 
     pub fn widths(&self) -> &TableWidths {
@@ -327,7 +333,7 @@ impl<'a, 'f> Table<'a> {
 
         match *column {
             Column::Permissions    => self.permissions_plus(file, xattrs).render(&self.colours),
-            Column::FileSize(fmt)  => file.size().render(&self.colours, fmt, &self.env.numeric),
+            Column::FileSize       => file.size().render(&self.colours, self.size_format, &self.env.numeric),
             Column::HardLinks      => file.links().render(&self.colours, &self.env.numeric),
             Column::Inode          => file.inode().render(&self.colours),
             Column::Blocks         => file.blocks().render(&self.colours),