2017-05-01 20:54:53 +00:00
|
|
|
use ansi_term::{ANSIString, Style};
|
|
|
|
|
|
|
|
|
Cleanup clippy warnings
warning: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
--> src/output/escape.rs:4:1
|
4 | pub fn escape<'a>(string: String, bits: &mut Vec<ANSIString<'a>>, good: Style, bad: Style) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
warning: this lifetime isn't used in the function definition
--> src/output/escape.rs:4:15
|
4 | pub fn escape<'a>(string: String, bits: &mut Vec<ANSIString<'_>>, good: Style, bad: Style) {
| ^^
|
warning: single-character string constant used as pattern
--> src/output/table.rs:310:41
|
310 | if file.starts_with(":") {
| ^^^ help: try using a `char` instead: `':'`
|
warning: single-character string constant used as pattern
--> src/output/table.rs:310:41
|
310 | if file.starts_with(":") {
| ^^^ help: try using a `char` instead: `':'`
|
warning: methods called `new` usually return `Self`
--> src/output/render/git.rs:38:5
|
38 | fn new(&self) -> Style;
| ^^^^^^^^^^^^^^^^^^^^^^^
|
warning: this lifetime isn't used in the function definition
--> src/output/icons.rs:40:22
|
40 | pub fn iconify_style<'a>(style: Style) -> Style {
| ^^
|
warning: lint `clippy::find_map` has been removed: this lint has been replaced by `manual_find_map`, a more specific lint
--> src/main.rs:11:10
|
11 | #![allow(clippy::find_map)]
| ^^^^^^^^^^^^^^^^
|
warning: redundant else block
--> src/fs/dir.rs:124:18
|
124 | else {
| __________________^
125 | | return None
126 | | }
| |_____________^
|
warning: redundant else block
--> src/options/view.rs:60:18
|
60 | else {
| __________________^
61 | | // the --tree case is handled by the DirAction parser later
62 | | return Ok(Self::Details(details));
63 | | }
| |_____________^
|
warning: all variants have the same postfix: `Bytes`
--> src/output/table.rs:170:1
|
170 | / pub enum SizeFormat {
171 | |
172 | | /// Format the file size using **decimal** prefixes, such as “kilo”,
173 | | /// “mega”, or “giga”.
... |
181 | | JustBytes,
182 | | }
| |_^
|
warning: all variants have the same postfix: `Bytes`
--> src/output/table.rs:171:1
|
171 | / pub enum SizeFormat {
172 | |
173 | | /// Format the file size using **decimal** prefixes, such as “kilo”,
174 | | /// “mega”, or “giga”.
... |
182 | | JustBytes,
183 | | }
| |_^
|
warning: useless use of `format!`
--> src/options/mod.rs:181:50
|
181 | return Err(OptionsError::Unsupported(format!(
| __________________________________________________^
182 | | "Options --git and --git-ignore can't be used because `git` feature was disabled in this build of exa"
183 | | )));
| |_____________^ help: consider using `.to_string()`: `"Options --git and --git-ignore can't be used because `git` feature was disabled in this build of exa".to_string()`
|
warning: stripping a prefix manually
--> src/fs/filter.rs:287:33
|
287 | if n.starts_with('.') { &n[1..] }
| ^^^^^^^
|
warning: case-sensitive file extension comparison
--> src/info/filetype.rs:24:19
|
24 | file.name.ends_with(".ninja") ||
| ^^^^^^^^^^^^^^^^^^^
|
2021-04-30 13:37:31 +00:00
|
|
|
pub fn escape(string: String, bits: &mut Vec<ANSIString<'_>>, good: Style, bad: Style) {
|
2019-10-12 09:42:12 +00:00
|
|
|
if string.chars().all(|c| c >= 0x20 as char && c != 0x7f as char) {
|
2017-05-01 20:54:53 +00:00
|
|
|
bits.push(good.paint(string));
|
2020-10-10 18:49:46 +00:00
|
|
|
return;
|
2017-05-01 20:54:53 +00:00
|
|
|
}
|
|
|
|
|
2020-10-10 18:49:46 +00:00
|
|
|
for c in string.chars() {
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
if c >= 0x20 as char && c != 0x7f as char {
|
|
|
|
// TODO: This allocates way too much,
|
|
|
|
// hence the `all` check above.
|
|
|
|
let mut s = String::new();
|
|
|
|
s.push(c);
|
|
|
|
bits.push(good.paint(s));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
let s = c.escape_default().collect::<String>();
|
|
|
|
bits.push(bad.paint(s));
|
2017-05-01 20:54:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|