3use diff::{LineChange, LineChanges};
6use syntect::highlighting;
7use terminal::as_terminal_escaped;
10const PANEL_WIDTH: usize = 7;
12pub struct Printer<'a> {
13 handle: &'a mut Write,
15 config: &'a Config<'a>,
16 pub line_changes: Option<LineChanges>,
20 pub fn new(handle: &'a mut Write, config: &'a Config) -> Self {
21 let colors = if config.colored_output {
35 pub fn print_header(&mut self, filename: Option<&str>) -> Result<()> {
36 if !self.config.output_components.header() {
40 if self.config.output_components.grid() {
41 self.print_horizontal_line('┬')?;
46 " ".repeat(PANEL_WIDTH),
47 self.colors.grid.paint("│"),
54 filename.map_or("", |_| "File: "),
55 self.colors.filename.paint(filename.unwrap_or("STDIN"))
58 if self.config.output_components.grid() {
59 self.print_horizontal_line('┼')?;
65 pub fn print_footer(&mut self) -> Result<()> {
66 if self.config.output_components.grid() {
67 self.print_horizontal_line('┴')
76 regions: &[(highlighting::Style, &str)],
78 let decorations = vec![
79 self.print_line_number(line_number),
80 self.print_git_marker(line_number),
81 self.print_line_border(),
82 Some(as_terminal_escaped(
84 self.config.true_color,
85 self.config.colored_output,
89 let grid_requested = self.config.output_components.grid();
95 .filter_map(|dec| if grid_requested {
96 Some(dec.unwrap_or_else(|| " ".to_owned()))
107 fn print_line_number(&self, line_number: usize) -> Option<String> {
108 if self.config.output_components.numbers() {
112 .paint(format!("{:4}", line_number))
115 } else if self.config.output_components.grid() {
122 fn print_git_marker(&self, line_number: usize) -> Option<String> {
123 if self.config.output_components.changes() {
125 if let Some(ref changes) = self.line_changes {
126 match changes.get(&(line_number as u32)) {
127 Some(&LineChange::Added) => self.colors.git_added.paint("+"),
128 Some(&LineChange::RemovedAbove) => self.colors.git_removed.paint("‾"),
129 Some(&LineChange::RemovedBelow) => self.colors.git_removed.paint("_"),
130 Some(&LineChange::Modified) => self.colors.git_modified.paint("~"),
131 _ => Style::default().paint(" "),
134 Style::default().paint(" ")
137 } else if self.config.output_components.grid() {
144 fn print_line_border(&self) -> Option<String> {
145 if self.config.output_components.grid() {
146 Some(self.colors.grid.paint("│").to_string())
152 fn print_horizontal_line(&mut self, grid_char: char) -> Result<()> {
153 let hline = "─".repeat(self.config.term_width - (PANEL_WIDTH + 1));
154 let hline = format!("{}{}{}", "─".repeat(PANEL_WIDTH), grid_char, hline);
156 writeln!(self.handle, "{}", self.colors.grid.paint(hline))?;
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