summaryrefslogtreecommitdiffstats
path: root/src/output/mod.rs
diff options
context:
space:
mode:
authorBen S <ogham@bsago.me>2016-06-11 16:54:06 +0100
committerBen S <ogham@bsago.me>2016-06-11 16:54:06 +0100
commitb8191670c7271c23a896d5142066e752944f6cd2 (patch)
tree2f1b3bce010d7148a6b39b3f6e57883a27914494 /src/output/mod.rs
parent580ad0cfecda1489517af11acce6081c65174ff8 (diff)
Fix, and add tests for, slashes in link paths
Diffstat (limited to 'src/output/mod.rs')
-rw-r--r--src/output/mod.rs36
1 files changed, 25 insertions, 11 deletions
diff --git a/src/output/mod.rs b/src/output/mod.rs
index 6464e07..f6aa294 100644
--- a/src/output/mod.rs
+++ b/src/output/mod.rs
@@ -24,14 +24,21 @@ pub fn filename(file: &File, colours: &Colours, links: bool) -> TextCellContents
if file.dir.is_none() {
if let Some(ref parent) = file.path.parent() {
- if parent.components().count() > 0 {
- bits.push(Style::default().paint(parent.to_string_lossy().to_string()));
- bits.push(Style::default().paint("/"));
+ let coconut = parent.components().count();
+
+ if coconut == 1 && parent.has_root() {
+ bits.push(colours.symlink_path.paint("/"));
+ }
+ else if coconut > 1 {
+ bits.push(colours.symlink_path.paint(parent.to_string_lossy().to_string()));
+ bits.push(colours.symlink_path.paint("/"));
}
}
}
- bits.push(file_colour(colours, &file).paint(file.name.clone()));
+ if !file.name.is_empty() {
+ bits.push(file_colour(colours, &file).paint(file.name.clone()));
+ }
if links && file.is_link() {
match file.link_target() {
@@ -42,22 +49,29 @@ pub fn filename(file: &File, colours: &Colours, links: bool) -> TextCellContents
if let Some(ref parent) = target.path.parent() {
let coconut = parent.components().count();
- if coconut != 0 {
- if !(coconut == 1 && parent.has_root()) {
- bits.push(colours.symlink_path.paint(parent.to_string_lossy().to_string()));
- }
+
+ if coconut == 1 && parent.has_root() {
+ bits.push(colours.symlink_path.paint("/"));
+ }
+ else if coconut > 1 {
+ bits.push(colours.symlink_path.paint(parent.to_string_lossy().to_string()));
bits.push(colours.symlink_path.paint("/"));
}
}
+ else {
+ bits.push(colours.symlink_path.paint("/"));
+ }
- bits.push(file_colour(colours, &target).paint(target.name));
+ if !target.name.is_empty() {
+ bits.push(file_colour(colours, &target).paint(target.name));
+ }
},
- Err(filename) => {
+ Err(broken_path) => {
bits.push(Style::default().paint(" "));
bits.push(colours.broken_arrow.paint("->"));
bits.push(Style::default().paint(" "));
- bits.push(colours.broken_filename.paint(filename));
+ bits.push(colours.broken_filename.paint(broken_path.display().to_string()));
},
}
}