7pub struct DecorationText {
13 fn generate(&self, line_number: usize, continuation: bool, printer: &Printer)
15 fn width(&self) -> usize;
18// Line number decoration.
19pub struct LineNumberDecoration {
21 cached_wrap: DecorationText,
22 cached_wrap_invalid_at: usize,
25impl LineNumberDecoration {
26 pub fn new(colors: &Colors) -> Self {
27 LineNumberDecoration {
28 color: colors.line_number,
29 cached_wrap_invalid_at: 10000,
30 cached_wrap: DecorationText {
31 text: colors.line_number.paint(" ".repeat(4)).to_string(),
38impl Decoration for LineNumberDecoration {
46 if line_number > self.cached_wrap_invalid_at {
47 let new_width = self.cached_wrap.width + 1;
48 return DecorationText {
49 text: self.color.paint(" ".repeat(new_width)).to_string(),
54 self.cached_wrap.clone()
56 let plain: String = format!("{:4}", line_number);
59 text: self.color.paint(plain).to_string(),
64 fn width(&self) -> usize {
69// Line changes decoration.
70pub struct LineChangesDecoration {
71 cached_none: DecorationText,
72 cached_added: DecorationText,
73 cached_removed_above: DecorationText,
74 cached_removed_below: DecorationText,
75 cached_modified: DecorationText,
78impl LineChangesDecoration {
80 fn generate_cached(style: Style, text: &str) -> DecorationText {
82 text: style.paint(text).to_string(),
83 width: text.chars().count(),
87 pub fn new(colors: &Colors) -> Self {
88 LineChangesDecoration {
89 cached_none: Self::generate_cached(Style::default(), " "),
90 cached_added: Self::generate_cached(colors.git_added, "+"),
91 cached_removed_above: Self::generate_cached(colors.git_removed, "‾"),
92 cached_removed_below: Self::generate_cached(colors.git_removed, "_"),
93 cached_modified: Self::generate_cached(colors.git_modified, "~"),
98impl Decoration for LineChangesDecoration {
104 ) -> DecorationText {
106 if let Some(ref changes) = printer.line_changes {
107 return match changes.get(&(line_number as u32)) {
108 Some(&LineChange::Added) => self.cached_added.clone(),
109 Some(&LineChange::RemovedAbove) => self.cached_removed_above.clone(),
110 Some(&LineChange::RemovedBelow) => self.cached_removed_below.clone(),
111 Some(&LineChange::Modified) => self.cached_modified.clone(),
112 _ => self.cached_none.clone(),
117 self.cached_none.clone()
120 fn width(&self) -> usize {
121 self.cached_none.width
125// Grid border decoration.
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 {
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