mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-12-26 18:10:13 +00:00
Only highlight escaped characters in file names
Rather than the *entire* file name. The current method is extremely inefficient, but having control characters in file names is also extremely uncommon; it’s something that should be fixed, only eventually.
This commit is contained in:
parent
a53c268c54
commit
eb7e53ef6c
@ -114,13 +114,21 @@ fn coloured_file_name<'a>(file: &File, colours: &Colours) -> Vec<ANSIString<'a>>
|
|||||||
bits.push(colour.paint(file.name.clone()));
|
bits.push(colour.paint(file.name.clone()));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
for c in file.name.chars() {
|
||||||
// The `escape_default` method on `char` is *almost* what we want here, but
|
// The `escape_default` method on `char` is *almost* what we want here, but
|
||||||
// it still escapes non-ASCII UTF-8 characters, which are still printable.'
|
// it still escapes non-ASCII UTF-8 characters, which are still printable.
|
||||||
let escaped_name = file.name.chars()
|
|
||||||
.flat_map(char::escape_default)
|
|
||||||
.collect::<String>();
|
|
||||||
|
|
||||||
bits.push(colours.broken_arrow.paint(escaped_name));
|
if c >= 0x20 as char {
|
||||||
|
// TODO: This allocates way too much,
|
||||||
|
// hence the `all` check above.
|
||||||
|
let mut s = String::new();
|
||||||
|
s.push(c);
|
||||||
|
bits.push(colour.paint(s));
|
||||||
|
} else {
|
||||||
|
let s = c.escape_default().collect::<String>();
|
||||||
|
bits.push(colours.broken_arrow.paint(s));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bits
|
bits
|
||||||
|
6
xtests/file_names
Normal file
6
xtests/file_names
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
ansi: [[31m\u{1b}[0m[34mblue[31m\u{1b}[0m[0m] form-feed: [[31m\u{c}[0m] return: [[31m\r[0m]
|
||||||
|
ascii: hello invalid-utf8-1: [<5B>] tab: [[31m\t[0m]
|
||||||
|
backspace: [[31m\u{8}[0m] invalid-utf8-2: [<5B>(] utf-8: pâté
|
||||||
|
bell: [[31m\u{7}[0m] invalid-utf8-3: [<5B>(] vertical-tab: [[31m\u{b}[0m]
|
||||||
|
emoji: [🆒] invalid-utf8-4: [<5B>(<28>(]
|
||||||
|
escape: [[31m\u{1b}[0m] new-line: [[31m\n[0m]
|
16
xtests/file_names_1
Normal file
16
xtests/file_names_1
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
ansi: [[31m\u{1b}[0m[34mblue[31m\u{1b}[0m[0m]
|
||||||
|
ascii: hello
|
||||||
|
backspace: [[31m\u{8}[0m]
|
||||||
|
bell: [[31m\u{7}[0m]
|
||||||
|
emoji: [🆒]
|
||||||
|
escape: [[31m\u{1b}[0m]
|
||||||
|
form-feed: [[31m\u{c}[0m]
|
||||||
|
invalid-utf8-1: [<5B>]
|
||||||
|
invalid-utf8-2: [<5B>(]
|
||||||
|
invalid-utf8-3: [<5B>(]
|
||||||
|
invalid-utf8-4: [<5B>(<28>(]
|
||||||
|
new-line: [[31m\n[0m]
|
||||||
|
return: [[31m\r[0m]
|
||||||
|
tab: [[31m\t[0m]
|
||||||
|
utf-8: pâté
|
||||||
|
vertical-tab: [[31m\u{b}[0m]
|
6
xtests/file_names_x
Normal file
6
xtests/file_names_x
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
ansi: [[31m\u{1b}[0m[34mblue[31m\u{1b}[0m[0m] ascii: hello backspace: [[31m\u{8}[0m]
|
||||||
|
bell: [[31m\u{7}[0m] emoji: [🆒] escape: [[31m\u{1b}[0m]
|
||||||
|
form-feed: [[31m\u{c}[0m] invalid-utf8-1: [<5B>] invalid-utf8-2: [<5B>(]
|
||||||
|
invalid-utf8-3: [<5B>(] invalid-utf8-4: [<5B>(<28>(] new-line: [[31m\n[0m]
|
||||||
|
return: [[31m\r[0m] tab: [[31m\t[0m] utf-8: pâté
|
||||||
|
vertical-tab: [[31m\u{b}[0m]
|
@ -54,6 +54,10 @@ $exa $testcases/passwd -lgh | diff -q - $results/passwd || exit 1
|
|||||||
sudo -u cassowary $exa $testcases/permissions -lghR 2>&1 | diff -q - $results/permissions_sudo || exit 1
|
sudo -u cassowary $exa $testcases/permissions -lghR 2>&1 | diff -q - $results/permissions_sudo || exit 1
|
||||||
$exa $testcases/permissions -lghR 2>&1 | diff -q - $results/permissions || exit 1
|
$exa $testcases/permissions -lghR 2>&1 | diff -q - $results/permissions || exit 1
|
||||||
|
|
||||||
|
# File names
|
||||||
|
COLUMNS=80 $exa $testcases/file-names 2>&1 | diff -q - $results/file_names || exit 1
|
||||||
|
COLUMNS=80 $exa $testcases/file-names -x 2>&1 | diff -q - $results/file_names_x || exit 1
|
||||||
|
$exa $testcases/file-names -1 2>&1 | diff -q - $results/file_names_1 || exit 1
|
||||||
|
|
||||||
# File types
|
# File types
|
||||||
$exa $testcases/file-names-exts -1 2>&1 | diff -q - $results/file-names-exts || exit 1
|
$exa $testcases/file-names-exts -1 2>&1 | diff -q - $results/file-names-exts || exit 1
|
||||||
|
Loading…
Reference in New Issue
Block a user