2017-08-20 19:29:23 +00:00
|
|
|
use ansi_term::{ANSIString, Style};
|
2017-05-21 16:01:22 +00:00
|
|
|
|
2018-12-07 23:43:31 +00:00
|
|
|
use crate::output::cell::{TextCell, DisplayWidth};
|
|
|
|
use crate::fs::fields as f;
|
2017-05-21 15:59:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
impl f::Git {
|
2020-10-10 14:30:19 +00:00
|
|
|
pub fn render(self, colours: &dyn Colours) -> TextCell {
|
2017-05-21 15:59:02 +00:00
|
|
|
TextCell {
|
|
|
|
width: DisplayWidth::from(2),
|
|
|
|
contents: vec![
|
2017-05-21 16:01:22 +00:00
|
|
|
self.staged.render(colours),
|
|
|
|
self.unstaged.render(colours),
|
2017-05-21 15:59:02 +00:00
|
|
|
].into(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-20 19:29:23 +00:00
|
|
|
|
2017-05-21 16:01:22 +00:00
|
|
|
impl f::GitStatus {
|
2020-10-10 14:30:19 +00:00
|
|
|
fn render(self, colours: &dyn Colours) -> ANSIString<'static> {
|
|
|
|
match self {
|
2020-10-10 12:55:26 +00:00
|
|
|
Self::NotModified => colours.not_modified().paint("-"),
|
|
|
|
Self::New => colours.new().paint("N"),
|
|
|
|
Self::Modified => colours.modified().paint("M"),
|
|
|
|
Self::Deleted => colours.deleted().paint("D"),
|
|
|
|
Self::Renamed => colours.renamed().paint("R"),
|
|
|
|
Self::TypeChange => colours.type_change().paint("T"),
|
|
|
|
Self::Ignored => colours.ignored().paint("I"),
|
|
|
|
Self::Conflicted => colours.conflicted().paint("U"),
|
2017-05-21 16:01:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-21 15:59:02 +00:00
|
|
|
|
2017-08-20 19:29:23 +00:00
|
|
|
pub trait Colours {
|
|
|
|
fn not_modified(&self) -> 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
|
|
|
#[allow(clippy::new_ret_no_self)]
|
2017-08-20 19:29:23 +00:00
|
|
|
fn new(&self) -> Style;
|
|
|
|
fn modified(&self) -> Style;
|
|
|
|
fn deleted(&self) -> Style;
|
|
|
|
fn renamed(&self) -> Style;
|
|
|
|
fn type_change(&self) -> Style;
|
2018-11-20 17:12:38 +00:00
|
|
|
fn ignored(&self) -> Style;
|
2020-05-29 14:23:22 +00:00
|
|
|
fn conflicted(&self) -> Style;
|
2017-08-20 19:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-05-21 15:59:02 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
pub mod test {
|
2017-08-26 22:53:47 +00:00
|
|
|
use super::Colours;
|
2018-12-07 23:43:31 +00:00
|
|
|
use crate::output::cell::{TextCell, DisplayWidth};
|
|
|
|
use crate::fs::fields as f;
|
2017-05-21 15:59:02 +00:00
|
|
|
|
|
|
|
use ansi_term::Colour::*;
|
2017-08-20 19:29:23 +00:00
|
|
|
use ansi_term::Style;
|
2017-08-26 22:53:47 +00:00
|
|
|
|
|
|
|
|
2017-08-20 19:29:23 +00:00
|
|
|
struct TestColours;
|
|
|
|
|
|
|
|
impl Colours for TestColours {
|
|
|
|
fn not_modified(&self) -> Style { Fixed(90).normal() }
|
|
|
|
fn new(&self) -> Style { Fixed(91).normal() }
|
|
|
|
fn modified(&self) -> Style { Fixed(92).normal() }
|
|
|
|
fn deleted(&self) -> Style { Fixed(93).normal() }
|
|
|
|
fn renamed(&self) -> Style { Fixed(94).normal() }
|
|
|
|
fn type_change(&self) -> Style { Fixed(95).normal() }
|
2018-11-20 17:12:38 +00:00
|
|
|
fn ignored(&self) -> Style { Fixed(96).normal() }
|
2020-10-10 18:49:46 +00:00
|
|
|
fn conflicted(&self) -> Style { Fixed(97).normal() }
|
2017-08-26 22:53:47 +00:00
|
|
|
}
|
2017-05-21 15:59:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn git_blank() {
|
|
|
|
let stati = f::Git {
|
|
|
|
staged: f::GitStatus::NotModified,
|
|
|
|
unstaged: f::GitStatus::NotModified,
|
|
|
|
};
|
|
|
|
|
|
|
|
let expected = TextCell {
|
|
|
|
width: DisplayWidth::from(2),
|
|
|
|
contents: vec![
|
2017-08-20 19:29:23 +00:00
|
|
|
Fixed(90).paint("-"),
|
|
|
|
Fixed(90).paint("-"),
|
2017-05-21 15:59:02 +00:00
|
|
|
].into(),
|
|
|
|
};
|
|
|
|
|
2022-10-01 03:50:31 +00:00
|
|
|
assert_eq!(expected, stati.render(&TestColours))
|
2017-05-21 15:59:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn git_new_changed() {
|
|
|
|
let stati = f::Git {
|
|
|
|
staged: f::GitStatus::New,
|
|
|
|
unstaged: f::GitStatus::Modified,
|
|
|
|
};
|
|
|
|
|
|
|
|
let expected = TextCell {
|
|
|
|
width: DisplayWidth::from(2),
|
|
|
|
contents: vec![
|
2017-08-20 19:29:23 +00:00
|
|
|
Fixed(91).paint("N"),
|
|
|
|
Fixed(92).paint("M"),
|
2017-05-21 15:59:02 +00:00
|
|
|
].into(),
|
|
|
|
};
|
|
|
|
|
2022-10-01 03:50:31 +00:00
|
|
|
assert_eq!(expected, stati.render(&TestColours))
|
2017-05-21 15:59:02 +00:00
|
|
|
}
|
|
|
|
}
|