99//! collection of data rows ([`Row`]), one per filesystem.
1010use unicode_width:: UnicodeWidthStr ;
1111
12- use crate :: blocks:: { SuffixType , to_magnitude_and_suffix} ;
12+ use crate :: Options ;
13+ use crate :: blocks:: { BlockSize , SuffixType , to_magnitude_and_suffix} ;
1314use crate :: columns:: { Alignment , Column } ;
1415use crate :: filesystem:: Filesystem ;
15- use crate :: { BlockSize , Options } ;
16+ use uucore :: format :: human :: format_with_thousands_separator ;
1617use uucore:: fsext:: { FsUsage , MountInfo } ;
1718use uucore:: translate;
1819
@@ -308,12 +309,14 @@ impl<'a> RowFormatter<'a> {
308309 let size = bytes_column. scaled ;
309310 let s = if let Some ( h) = self . options . human_readable {
310311 let size = if self . is_total_row {
311- let BlockSize :: Bytes ( d) = self . options . block_size ;
312+ let BlockSize :: Bytes ( d) = self . options . block_size_config . block_size ;
312313 d * size
313314 } else {
314315 bytes_column. bytes
315316 } ;
316317 to_magnitude_and_suffix ( size. into ( ) , SuffixType :: HumanReadable ( h) , true )
318+ } else if self . options . block_size_config . use_thousands_separator {
319+ format_with_thousands_separator ( size)
317320 } else {
318321 size. to_string ( )
319322 } ;
@@ -421,13 +424,13 @@ impl Header {
421424 HeaderMode :: PosixPortability => {
422425 format ! (
423426 "{}{}" ,
424- options. block_size. as_u64( ) ,
427+ options. block_size_config . block_size. as_u64( ) ,
425428 translate!( "df-blocks-suffix" )
426429 )
427430 }
428431 _ => format ! (
429432 "{}{}" ,
430- options. block_size. to_header( ) ,
433+ options. block_size_config . block_size. to_header( ) ,
431434 translate!( "df-blocks-suffix" )
432435 ) ,
433436 } ,
@@ -490,7 +493,7 @@ impl Table {
490493 // showing all filesystems, then print the data as a row in
491494 // the output table.
492495 if options. show_all_fs || filesystem. usage . blocks > 0 {
493- let row = Row :: from_filesystem ( filesystem, & options. block_size ) ;
496+ let row = Row :: from_filesystem ( filesystem, & options. block_size_config . block_size ) ;
494497 let fmt = RowFormatter :: new ( & row, options, false ) ;
495498 let values = fmt. get_cells ( ) ;
496499 if options. show_total {
@@ -578,7 +581,7 @@ mod tests {
578581 use crate :: blocks:: HumanReadable ;
579582 use crate :: columns:: Column ;
580583 use crate :: table:: { BytesCell , Cell , Header , HeaderMode , Row , RowFormatter , Table } ;
581- use crate :: { BlockSize , Options } ;
584+ use crate :: { BlockSize , BlockSizeConfig , Options } ;
582585
583586 fn init ( ) {
584587 unsafe {
@@ -692,7 +695,10 @@ mod tests {
692695 fn test_header_with_block_size_1024 ( ) {
693696 init ( ) ;
694697 let options = Options {
695- block_size : BlockSize :: Bytes ( 3 * 1024 ) ,
698+ block_size_config : BlockSizeConfig {
699+ block_size : BlockSize :: Bytes ( 3 * 1024 ) ,
700+ use_thousands_separator : false ,
701+ } ,
696702 ..Default :: default ( )
697703 } ;
698704 assert_eq ! (
@@ -772,7 +778,10 @@ mod tests {
772778 fn test_row_formatter ( ) {
773779 init ( ) ;
774780 let options = Options {
775- block_size : BlockSize :: Bytes ( 1 ) ,
781+ block_size_config : BlockSizeConfig {
782+ block_size : BlockSize :: Bytes ( 1 ) ,
783+ use_thousands_separator : false ,
784+ } ,
776785 ..Default :: default ( )
777786 } ;
778787 let row = Row {
@@ -798,7 +807,10 @@ mod tests {
798807 init ( ) ;
799808 let options = Options {
800809 columns : COLUMNS_WITH_FS_TYPE . to_vec ( ) ,
801- block_size : BlockSize :: Bytes ( 1 ) ,
810+ block_size_config : BlockSizeConfig {
811+ block_size : BlockSize :: Bytes ( 1 ) ,
812+ use_thousands_separator : false ,
813+ } ,
802814 ..Default :: default ( )
803815 } ;
804816 let row = Row {
@@ -825,7 +837,10 @@ mod tests {
825837 init ( ) ;
826838 let options = Options {
827839 columns : COLUMNS_WITH_INODES . to_vec ( ) ,
828- block_size : BlockSize :: Bytes ( 1 ) ,
840+ block_size_config : BlockSizeConfig {
841+ block_size : BlockSize :: Bytes ( 1 ) ,
842+ use_thousands_separator : false ,
843+ } ,
829844 ..Default :: default ( )
830845 } ;
831846 let row = Row {
@@ -851,7 +866,10 @@ mod tests {
851866 init ( ) ;
852867 let options = Options {
853868 columns : vec ! [ Column :: Size , Column :: Itotal ] ,
854- block_size : BlockSize :: Bytes ( 100 ) ,
869+ block_size_config : BlockSizeConfig {
870+ block_size : BlockSize :: Bytes ( 100 ) ,
871+ use_thousands_separator : false ,
872+ } ,
855873 ..Default :: default ( )
856874 } ;
857875 let row = Row {
@@ -953,7 +971,10 @@ mod tests {
953971 init ( ) ;
954972 fn get_formatted_values ( bytes : u64 , bytes_used : u64 , bytes_avail : u64 ) -> Vec < Cell > {
955973 let options = Options {
956- block_size : BlockSize :: Bytes ( 1000 ) ,
974+ block_size_config : BlockSizeConfig {
975+ block_size : BlockSize :: Bytes ( 1000 ) ,
976+ use_thousands_separator : false ,
977+ } ,
957978 columns : vec ! [ Column :: Size , Column :: Used , Column :: Avail ] ,
958979 ..Default :: default ( )
959980 } ;
0 commit comments