Fix bug where paths took up twice as much space

For some reason, the code that calculated the width of a cell with a path in counted the width of the path twice: once from the ANSIStrings containing it, and once more added on afterwards. This meant that the grid view thought that columns were wider than they really were, meaning fewer could be fit into a grid.
This commit is contained in:
Benjamin Sago 2017-05-02 17:40:32 +01:00
parent 437ac0ea60
commit ba1c8c650f
9 changed files with 110 additions and 21 deletions

View File

@ -308,13 +308,7 @@ impl Details {
let mut errors = egg.errors;
let filename = FileName::new(&egg.file, &self.colours).paint(true, self.classify);
let mut width = filename.width();
if egg.file.dir.is_none() {
if let Some(parent) = egg.file.path.parent() {
width = width + 1 + DisplayWidth::from(parent.to_string_lossy().as_ref());
}
}
let width = filename.width();
let name = TextCell {
contents: filename,
@ -459,13 +453,7 @@ impl<'a, U: Users+Groups+'a> Table<'a, U> {
pub fn filename_cell(&self, file: File, links: bool) -> TextCell {
let filename = FileName::new(&file, &self.opts.colours).paint(links, self.opts.classify);
let mut width = filename.width();
if file.dir.is_none() {
if let Some(parent) = file.path.parent() {
width = width + 1 + DisplayWidth::from(parent.to_string_lossy().as_ref());
}
}
let width = filename.width();
TextCell {
contents: filename,

View File

@ -30,13 +30,7 @@ impl Grid {
for file in files.iter() {
let filename = FileName::new(file, &self.colours).paint(false, self.classify);
let mut width = filename.width();
if file.dir.is_none() {
if let Some(parent) = file.path.parent() {
width = width + 1 + DisplayWidth::from(parent.to_string_lossy().as_ref());
}
}
let width = filename.width();
grid.add(grid::Cell {
contents: filename.strings().to_string(),

13
xtests/files_star_100 Normal file
View File

@ -0,0 +1,13 @@
/testcases/files/10_bytes /testcases/files/1_KiB /testcases/files/5_MiB
/testcases/files/10_KiB /testcases/files/1_MiB /testcases/files/6_bytes
/testcases/files/10_MiB /testcases/files/2_bytes /testcases/files/6_KiB
/testcases/files/11_bytes /testcases/files/2_KiB /testcases/files/6_MiB
/testcases/files/11_KiB /testcases/files/2_MiB /testcases/files/7_bytes
/testcases/files/11_MiB /testcases/files/3_bytes /testcases/files/7_KiB
/testcases/files/12_bytes /testcases/files/3_KiB /testcases/files/7_MiB
/testcases/files/12_KiB /testcases/files/3_MiB /testcases/files/8_bytes
/testcases/files/12_MiB /testcases/files/4_bytes /testcases/files/8_KiB
/testcases/files/13_bytes /testcases/files/4_KiB /testcases/files/8_MiB
/testcases/files/13_KiB /testcases/files/4_MiB /testcases/files/9_bytes
/testcases/files/13_MiB /testcases/files/5_bytes /testcases/files/9_KiB
/testcases/files/1_bytes /testcases/files/5_KiB /testcases/files/9_MiB

8
xtests/files_star_150 Normal file
View File

@ -0,0 +1,8 @@
/testcases/files/10_bytes /testcases/files/12_MiB /testcases/files/2_KiB /testcases/files/5_bytes /testcases/files/7_MiB
/testcases/files/10_KiB /testcases/files/13_bytes /testcases/files/2_MiB /testcases/files/5_KiB /testcases/files/8_bytes
/testcases/files/10_MiB /testcases/files/13_KiB /testcases/files/3_bytes /testcases/files/5_MiB /testcases/files/8_KiB
/testcases/files/11_bytes /testcases/files/13_MiB /testcases/files/3_KiB /testcases/files/6_bytes /testcases/files/8_MiB
/testcases/files/11_KiB /testcases/files/1_bytes /testcases/files/3_MiB /testcases/files/6_KiB /testcases/files/9_bytes
/testcases/files/11_MiB /testcases/files/1_KiB /testcases/files/4_bytes /testcases/files/6_MiB /testcases/files/9_KiB
/testcases/files/12_bytes /testcases/files/1_MiB /testcases/files/4_KiB /testcases/files/7_bytes /testcases/files/9_MiB
/testcases/files/12_KiB /testcases/files/2_bytes /testcases/files/4_MiB /testcases/files/7_KiB

6
xtests/files_star_200 Normal file
View File

@ -0,0 +1,6 @@
/testcases/files/10_bytes /testcases/files/12_bytes /testcases/files/1_bytes /testcases/files/3_bytes /testcases/files/5_bytes /testcases/files/7_bytes /testcases/files/9_bytes
/testcases/files/10_KiB /testcases/files/12_KiB /testcases/files/1_KiB /testcases/files/3_KiB /testcases/files/5_KiB /testcases/files/7_KiB /testcases/files/9_KiB
/testcases/files/10_MiB /testcases/files/12_MiB /testcases/files/1_MiB /testcases/files/3_MiB /testcases/files/5_MiB /testcases/files/7_MiB /testcases/files/9_MiB
/testcases/files/11_bytes /testcases/files/13_bytes /testcases/files/2_bytes /testcases/files/4_bytes /testcases/files/6_bytes /testcases/files/8_bytes
/testcases/files/11_KiB /testcases/files/13_KiB /testcases/files/2_KiB /testcases/files/4_KiB /testcases/files/6_KiB /testcases/files/8_KiB
/testcases/files/11_MiB /testcases/files/13_MiB /testcases/files/2_MiB /testcases/files/4_MiB /testcases/files/6_MiB /testcases/files/8_MiB

39
xtests/files_star_lG_100 Normal file
View File

@ -0,0 +1,39 @@
.rw-r--r-- 10 cassowary  1 Jan 12:34 /testcases/files/10_bytes
.rw-r--r-- 10k cassowary  1 Jan 12:34 /testcases/files/10_KiB
.rw-r--r-- 10M cassowary  1 Jan 12:34 /testcases/files/10_MiB
.rw-r--r-- 11 cassowary  1 Jan 12:34 /testcases/files/11_bytes
.rw-r--r-- 11k cassowary  1 Jan 12:34 /testcases/files/11_KiB
.rw-r--r-- 11M cassowary  1 Jan 12:34 /testcases/files/11_MiB
.rw-r--r-- 12 cassowary  1 Jan 12:34 /testcases/files/12_bytes
.rw-r--r-- 12k cassowary  1 Jan 12:34 /testcases/files/12_KiB
.rw-r--r-- 12M cassowary  1 Jan 12:34 /testcases/files/12_MiB
.rw-r--r-- 13 cassowary  1 Jan 12:34 /testcases/files/13_bytes
.rw-r--r-- 13k cassowary  1 Jan 12:34 /testcases/files/13_KiB
.rw-r--r-- 13M cassowary  1 Jan 12:34 /testcases/files/13_MiB
.rw-r--r-- 1 cassowary  1 Jan 12:34 /testcases/files/1_bytes
.rw-r--r-- 1.0k cassowary  1 Jan 12:34 /testcases/files/1_KiB
.rw-r--r-- 1.0M cassowary  1 Jan 12:34 /testcases/files/1_MiB
.rw-r--r-- 2 cassowary  1 Jan 12:34 /testcases/files/2_bytes
.rw-r--r-- 2.0k cassowary  1 Jan 12:34 /testcases/files/2_KiB
.rw-r--r-- 2.1M cassowary  1 Jan 12:34 /testcases/files/2_MiB
.rw-r--r-- 3 cassowary  1 Jan 12:34 /testcases/files/3_bytes
.rw-r--r-- 3.1k cassowary  1 Jan 12:34 /testcases/files/3_KiB
.rw-r--r-- 3.1M cassowary  1 Jan 12:34 /testcases/files/3_MiB
.rw-r--r-- 4 cassowary  1 Jan 12:34 /testcases/files/4_bytes
.rw-r--r-- 4.1k cassowary  1 Jan 12:34 /testcases/files/4_KiB
.rw-r--r-- 4.2M cassowary  1 Jan 12:34 /testcases/files/4_MiB
.rw-r--r-- 5 cassowary  1 Jan 12:34 /testcases/files/5_bytes
.rw-r--r-- 5.1k cassowary  1 Jan 12:34 /testcases/files/5_KiB
.rw-r--r-- 5.2M cassowary  1 Jan 12:34 /testcases/files/5_MiB
.rw-r--r-- 6 cassowary  1 Jan 12:34 /testcases/files/6_bytes
.rw-r--r-- 6.1k cassowary  1 Jan 12:34 /testcases/files/6_KiB
.rw-r--r-- 6.3M cassowary  1 Jan 12:34 /testcases/files/6_MiB
.rw-r--r-- 7 cassowary  1 Jan 12:34 /testcases/files/7_bytes
.rw-r--r-- 7.2k cassowary  1 Jan 12:34 /testcases/files/7_KiB
.rw-r--r-- 7.3M cassowary  1 Jan 12:34 /testcases/files/7_MiB
.rw-r--r-- 8 cassowary  1 Jan 12:34 /testcases/files/8_bytes
.rw-r--r-- 8.2k cassowary  1 Jan 12:34 /testcases/files/8_KiB
.rw-r--r-- 8.4M cassowary  1 Jan 12:34 /testcases/files/8_MiB
.rw-r--r-- 9 cassowary  1 Jan 12:34 /testcases/files/9_bytes
.rw-r--r-- 9.2k cassowary  1 Jan 12:34 /testcases/files/9_KiB
.rw-r--r-- 9.4M cassowary  1 Jan 12:34 /testcases/files/9_MiB

20
xtests/files_star_lG_150 Normal file
View File

@ -0,0 +1,20 @@
.rw-r--r-- 10 cassowary  1 Jan 12:34 /testcases/files/10_bytes .rw-r--r-- 3.1M cassowary  1 Jan 12:34 /testcases/files/3_MiB
.rw-r--r-- 10k cassowary  1 Jan 12:34 /testcases/files/10_KiB .rw-r--r-- 4 cassowary  1 Jan 12:34 /testcases/files/4_bytes
.rw-r--r-- 10M cassowary  1 Jan 12:34 /testcases/files/10_MiB .rw-r--r-- 4.1k cassowary  1 Jan 12:34 /testcases/files/4_KiB
.rw-r--r-- 11 cassowary  1 Jan 12:34 /testcases/files/11_bytes .rw-r--r-- 4.2M cassowary  1 Jan 12:34 /testcases/files/4_MiB
.rw-r--r-- 11k cassowary  1 Jan 12:34 /testcases/files/11_KiB .rw-r--r-- 5 cassowary  1 Jan 12:34 /testcases/files/5_bytes
.rw-r--r-- 11M cassowary  1 Jan 12:34 /testcases/files/11_MiB .rw-r--r-- 5.1k cassowary  1 Jan 12:34 /testcases/files/5_KiB
.rw-r--r-- 12 cassowary  1 Jan 12:34 /testcases/files/12_bytes .rw-r--r-- 5.2M cassowary  1 Jan 12:34 /testcases/files/5_MiB
.rw-r--r-- 12k cassowary  1 Jan 12:34 /testcases/files/12_KiB .rw-r--r-- 6 cassowary  1 Jan 12:34 /testcases/files/6_bytes
.rw-r--r-- 12M cassowary  1 Jan 12:34 /testcases/files/12_MiB .rw-r--r-- 6.1k cassowary  1 Jan 12:34 /testcases/files/6_KiB
.rw-r--r-- 13 cassowary  1 Jan 12:34 /testcases/files/13_bytes .rw-r--r-- 6.3M cassowary  1 Jan 12:34 /testcases/files/6_MiB
.rw-r--r-- 13k cassowary  1 Jan 12:34 /testcases/files/13_KiB .rw-r--r-- 7 cassowary  1 Jan 12:34 /testcases/files/7_bytes
.rw-r--r-- 13M cassowary  1 Jan 12:34 /testcases/files/13_MiB .rw-r--r-- 7.2k cassowary  1 Jan 12:34 /testcases/files/7_KiB
.rw-r--r-- 1 cassowary  1 Jan 12:34 /testcases/files/1_bytes .rw-r--r-- 7.3M cassowary  1 Jan 12:34 /testcases/files/7_MiB
.rw-r--r-- 1.0k cassowary  1 Jan 12:34 /testcases/files/1_KiB .rw-r--r-- 8 cassowary  1 Jan 12:34 /testcases/files/8_bytes
.rw-r--r-- 1.0M cassowary  1 Jan 12:34 /testcases/files/1_MiB .rw-r--r-- 8.2k cassowary  1 Jan 12:34 /testcases/files/8_KiB
.rw-r--r-- 2 cassowary  1 Jan 12:34 /testcases/files/2_bytes .rw-r--r-- 8.4M cassowary  1 Jan 12:34 /testcases/files/8_MiB
.rw-r--r-- 2.0k cassowary  1 Jan 12:34 /testcases/files/2_KiB .rw-r--r-- 9 cassowary  1 Jan 12:34 /testcases/files/9_bytes
.rw-r--r-- 2.1M cassowary  1 Jan 12:34 /testcases/files/2_MiB .rw-r--r-- 9.2k cassowary  1 Jan 12:34 /testcases/files/9_KiB
.rw-r--r-- 3 cassowary  1 Jan 12:34 /testcases/files/3_bytes .rw-r--r-- 9.4M cassowary  1 Jan 12:34 /testcases/files/9_MiB
.rw-r--r-- 3.1k cassowary  1 Jan 12:34 /testcases/files/3_KiB

13
xtests/files_star_lG_200 Normal file
View File

@ -0,0 +1,13 @@
.rw-r--r-- 10 cassowary  1 Jan 12:34 /testcases/files/10_bytes .rw-r--r-- 1.0k cassowary  1 Jan 12:34 /testcases/files/1_KiB .rw-r--r-- 5.2M cassowary  1 Jan 12:34 /testcases/files/5_MiB
.rw-r--r-- 10k cassowary  1 Jan 12:34 /testcases/files/10_KiB .rw-r--r-- 1.0M cassowary  1 Jan 12:34 /testcases/files/1_MiB .rw-r--r-- 6 cassowary  1 Jan 12:34 /testcases/files/6_bytes
.rw-r--r-- 10M cassowary  1 Jan 12:34 /testcases/files/10_MiB .rw-r--r-- 2 cassowary  1 Jan 12:34 /testcases/files/2_bytes .rw-r--r-- 6.1k cassowary  1 Jan 12:34 /testcases/files/6_KiB
.rw-r--r-- 11 cassowary  1 Jan 12:34 /testcases/files/11_bytes .rw-r--r-- 2.0k cassowary  1 Jan 12:34 /testcases/files/2_KiB .rw-r--r-- 6.3M cassowary  1 Jan 12:34 /testcases/files/6_MiB
.rw-r--r-- 11k cassowary  1 Jan 12:34 /testcases/files/11_KiB .rw-r--r-- 2.1M cassowary  1 Jan 12:34 /testcases/files/2_MiB .rw-r--r-- 7 cassowary  1 Jan 12:34 /testcases/files/7_bytes
.rw-r--r-- 11M cassowary  1 Jan 12:34 /testcases/files/11_MiB .rw-r--r-- 3 cassowary  1 Jan 12:34 /testcases/files/3_bytes .rw-r--r-- 7.2k cassowary  1 Jan 12:34 /testcases/files/7_KiB
.rw-r--r-- 12 cassowary  1 Jan 12:34 /testcases/files/12_bytes .rw-r--r-- 3.1k cassowary  1 Jan 12:34 /testcases/files/3_KiB .rw-r--r-- 7.3M cassowary  1 Jan 12:34 /testcases/files/7_MiB
.rw-r--r-- 12k cassowary  1 Jan 12:34 /testcases/files/12_KiB .rw-r--r-- 3.1M cassowary  1 Jan 12:34 /testcases/files/3_MiB .rw-r--r-- 8 cassowary  1 Jan 12:34 /testcases/files/8_bytes
.rw-r--r-- 12M cassowary  1 Jan 12:34 /testcases/files/12_MiB .rw-r--r-- 4 cassowary  1 Jan 12:34 /testcases/files/4_bytes .rw-r--r-- 8.2k cassowary  1 Jan 12:34 /testcases/files/8_KiB
.rw-r--r-- 13 cassowary  1 Jan 12:34 /testcases/files/13_bytes .rw-r--r-- 4.1k cassowary  1 Jan 12:34 /testcases/files/4_KiB .rw-r--r-- 8.4M cassowary  1 Jan 12:34 /testcases/files/8_MiB
.rw-r--r-- 13k cassowary  1 Jan 12:34 /testcases/files/13_KiB .rw-r--r-- 4.2M cassowary  1 Jan 12:34 /testcases/files/4_MiB .rw-r--r-- 9 cassowary  1 Jan 12:34 /testcases/files/9_bytes
.rw-r--r-- 13M cassowary  1 Jan 12:34 /testcases/files/13_MiB .rw-r--r-- 5 cassowary  1 Jan 12:34 /testcases/files/5_bytes .rw-r--r-- 9.2k cassowary  1 Jan 12:34 /testcases/files/9_KiB
.rw-r--r-- 1 cassowary  1 Jan 12:34 /testcases/files/1_bytes .rw-r--r-- 5.1k cassowary  1 Jan 12:34 /testcases/files/5_KiB .rw-r--r-- 9.4M cassowary  1 Jan 12:34 /testcases/files/9_MiB

View File

@ -33,6 +33,10 @@ COLUMNS=120 $exa $testcases/files | diff -q - $results/files_120 || exit 1
COLUMNS=160 $exa $testcases/files | diff -q - $results/files_160 || exit 1
COLUMNS=200 $exa $testcases/files | diff -q - $results/files_200 || exit 1
COLUMNS=100 $exa $testcases/files/* | diff -q - $results/files_star_100 || exit 1
COLUMNS=150 $exa $testcases/files/* | diff -q - $results/files_star_150 || exit 1
COLUMNS=200 $exa $testcases/files/* | diff -q - $results/files_star_200 || exit 1
# Long grid view tests
COLUMNS=40 $exa $testcases/files -lG | diff -q - $results/files_lG_40 || exit 1
@ -41,6 +45,10 @@ COLUMNS=120 $exa $testcases/files -lG | diff -q - $results/files_lG_120 || exit
COLUMNS=160 $exa $testcases/files -lG | diff -q - $results/files_lG_160 || exit 1
COLUMNS=200 $exa $testcases/files -lG | diff -q - $results/files_lG_200 || exit 1
COLUMNS=100 $exa $testcases/files/* -lG | diff -q - $results/files_star_lG_100 || exit 1
COLUMNS=150 $exa $testcases/files/* -lG | diff -q - $results/files_star_lG_150 || exit 1
COLUMNS=200 $exa $testcases/files/* -lG | diff -q - $results/files_star_lG_200 || exit 1
# Attributes
$exa $testcases/attributes -l@T | diff -q - $results/attributes || exit 1