2use crate::diff::LineChange;
3use crate::printer::{Colors, InteractivePrinter};
7pub(crate) struct DecorationText {
12pub(crate) trait Decoration {
17 printer: &InteractivePrinter,
19 fn width(&self) -> usize;
22pub(crate) struct LineNumberDecoration {
24 cached_wrap: DecorationText,
25 cached_wrap_invalid_at: usize,
28impl LineNumberDecoration {
29 pub(crate) fn new(colors: &Colors) -> Self {
30 LineNumberDecoration {
31 color: colors.line_number,
32 cached_wrap_invalid_at: 10000,
33 cached_wrap: DecorationText {
34 text: colors.line_number.paint(" ".repeat(4)).to_string(),
41impl Decoration for LineNumberDecoration {
46 _printer: &InteractivePrinter,
49 if line_number > self.cached_wrap_invalid_at {
50 let new_width = self.cached_wrap.width + 1;
51 return DecorationText {
52 text: self.color.paint(" ".repeat(new_width)).to_string(),
57 self.cached_wrap.clone()
59 let plain: String = format!("{:4}", line_number);
62 text: self.color.paint(plain).to_string(),
67 fn width(&self) -> usize {
72#[cfg(feature = "git")]
73pub(crate) struct LineChangesDecoration {
74 cached_none: DecorationText,
75 cached_added: DecorationText,
76 cached_removed_above: DecorationText,
77 cached_removed_below: DecorationText,
78 cached_modified: DecorationText,
81#[cfg(feature = "git")]
82impl LineChangesDecoration {
84 fn generate_cached(style: Style, text: &str) -> DecorationText {
86 text: style.paint(text).to_string(),
87 width: text.chars().count(),
91 pub(crate) fn new(colors: &Colors) -> Self {
92 LineChangesDecoration {
93 cached_none: Self::generate_cached(Style::default(), " "),
94 cached_added: Self::generate_cached(colors.git_added, "+"),
95 cached_removed_above: Self::generate_cached(colors.git_removed, "‾"),
96 cached_removed_below: Self::generate_cached(colors.git_removed, "_"),
97 cached_modified: Self::generate_cached(colors.git_modified, "~"),
102#[cfg(feature = "git")]
103impl Decoration for LineChangesDecoration {
108 printer: &InteractivePrinter,
109 ) -> DecorationText {
111 if let Some(ref changes) = printer.line_changes {
112 return match changes.get(&(line_number as u32)) {
113 Some(&LineChange::Added) => self.cached_added.clone(),
114 Some(&LineChange::RemovedAbove) => self.cached_removed_above.clone(),
115 Some(&LineChange::RemovedBelow) => self.cached_removed_below.clone(),
116 Some(&LineChange::Modified) => self.cached_modified.clone(),
117 _ => self.cached_none.clone(),
122 self.cached_none.clone()
125 fn width(&self) -> usize {
126 self.cached_none.width
130pub(crate) struct GridBorderDecoration {
131 cached: DecorationText,
134impl GridBorderDecoration {
135 pub(crate) fn new(colors: &Colors) -> Self {
136 GridBorderDecoration {
137 cached: DecorationText {
138 text: colors.grid.paint("│").to_string(),
145impl Decoration for GridBorderDecoration {
150 _printer: &InteractivePrinter,
151 ) -> DecorationText {
155 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