3use printer::{Colors, InteractivePrinter};
6pub struct DecorationText {
16 printer: &InteractivePrinter,
18 fn width(&self) -> usize;
21pub struct LineNumberDecoration {
23 cached_wrap: DecorationText,
24 cached_wrap_invalid_at: usize,
27impl LineNumberDecoration {
28 pub fn new(colors: &Colors) -> Self {
29 LineNumberDecoration {
30 color: colors.line_number,
31 cached_wrap_invalid_at: 10000,
32 cached_wrap: DecorationText {
33 text: colors.line_number.paint(" ".repeat(4)).to_string(),
40impl Decoration for LineNumberDecoration {
45 _printer: &InteractivePrinter,
48 if line_number > self.cached_wrap_invalid_at {
49 let new_width = self.cached_wrap.width + 1;
50 return DecorationText {
51 text: self.color.paint(" ".repeat(new_width)).to_string(),
56 self.cached_wrap.clone()
58 let plain: String = format!("{:4}", line_number);
61 text: self.color.paint(plain).to_string(),
66 fn width(&self) -> usize {
71pub struct LineChangesDecoration {
72 cached_none: DecorationText,
73 cached_added: DecorationText,
74 cached_removed_above: DecorationText,
75 cached_removed_below: DecorationText,
76 cached_modified: DecorationText,
79impl LineChangesDecoration {
81 fn generate_cached(style: Style, text: &str) -> DecorationText {
83 text: style.paint(text).to_string(),
84 width: text.chars().count(),
88 pub fn new(colors: &Colors) -> Self {
89 LineChangesDecoration {
90 cached_none: Self::generate_cached(Style::default(), " "),
91 cached_added: Self::generate_cached(colors.git_added, "+"),
92 cached_removed_above: Self::generate_cached(colors.git_removed, "‾"),
93 cached_removed_below: Self::generate_cached(colors.git_removed, "_"),
94 cached_modified: Self::generate_cached(colors.git_modified, "~"),
99impl Decoration for LineChangesDecoration {
104 printer: &InteractivePrinter,
105 ) -> DecorationText {
107 if let Some(ref changes) = printer.line_changes {
108 return match changes.get(&(line_number as u32)) {
109 Some(&LineChange::Added) => self.cached_added.clone(),
110 Some(&LineChange::RemovedAbove) => self.cached_removed_above.clone(),
111 Some(&LineChange::RemovedBelow) => self.cached_removed_below.clone(),
112 Some(&LineChange::Modified) => self.cached_modified.clone(),
113 _ => self.cached_none.clone(),
118 self.cached_none.clone()
121 fn width(&self) -> usize {
122 self.cached_none.width
126pub struct GridBorderDecoration {
127 cached: DecorationText,
130impl GridBorderDecoration {
131 pub fn new(colors: &Colors) -> Self {
132 GridBorderDecoration {
133 cached: DecorationText {
134 text: colors.grid.paint("│").to_string(),
141impl Decoration for GridBorderDecoration {
146 _printer: &InteractivePrinter,
147 ) -> DecorationText {
151 fn width(&self) -> usize {
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list