exa/src/output/render/git.rs
Christian Göttsche 61ec153bcd 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 15:37:31 +02:00

110 lines
3.0 KiB
Rust

use ansi_term::{ANSIString, Style};
use crate::output::cell::{TextCell, DisplayWidth};
use crate::fs::fields as f;
impl f::Git {
pub fn render(self, colours: &dyn Colours) -> TextCell {
TextCell {
width: DisplayWidth::from(2),
contents: vec![
self.staged.render(colours),
self.unstaged.render(colours),
].into(),
}
}
}
impl f::GitStatus {
fn render(self, colours: &dyn Colours) -> ANSIString<'static> {
match self {
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"),
}
}
}
pub trait Colours {
fn not_modified(&self) -> Style;
#[allow(clippy::new_ret_no_self)]
fn new(&self) -> Style;
fn modified(&self) -> Style;
fn deleted(&self) -> Style;
fn renamed(&self) -> Style;
fn type_change(&self) -> Style;
fn ignored(&self) -> Style;
fn conflicted(&self) -> Style;
}
#[cfg(test)]
pub mod test {
use super::Colours;
use crate::output::cell::{TextCell, DisplayWidth};
use crate::fs::fields as f;
use ansi_term::Colour::*;
use ansi_term::Style;
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() }
fn ignored(&self) -> Style { Fixed(96).normal() }
fn conflicted(&self) -> Style { Fixed(97).normal() }
}
#[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![
Fixed(90).paint("-"),
Fixed(90).paint("-"),
].into(),
};
assert_eq!(expected, stati.render(&TestColours).into())
}
#[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![
Fixed(91).paint("N"),
Fixed(92).paint("M"),
].into(),
};
assert_eq!(expected, stati.render(&TestColours).into())
}
}