mirror of
https://github.com/sharkdp/bat.git
synced 2025-03-11 21:09:32 +01:00
Code cleanup
This commit is contained in:
parent
70ffd60b20
commit
fcfc7c465b
27
src/main.rs
27
src/main.rs
@ -33,6 +33,14 @@ enum LineChange {
|
|||||||
|
|
||||||
type LineChanges = HashMap<u32, LineChange>;
|
type LineChanges = HashMap<u32, LineChange>;
|
||||||
|
|
||||||
|
const GRID_COLOR : u8 = 238;
|
||||||
|
|
||||||
|
fn print_horizontal_line(grid_char: char, term_width: usize) {
|
||||||
|
let prefix = format!("{}{}", "─".repeat(7), grid_char);
|
||||||
|
let line = "─".repeat(term_width - prefix.len());
|
||||||
|
println!("{}{}", Fixed(GRID_COLOR).paint(prefix), Fixed(GRID_COLOR).paint(line));
|
||||||
|
}
|
||||||
|
|
||||||
fn print_file<P: AsRef<Path>>(
|
fn print_file<P: AsRef<Path>>(
|
||||||
theme: &Theme,
|
theme: &Theme,
|
||||||
filename: P,
|
filename: P,
|
||||||
@ -43,21 +51,18 @@ fn print_file<P: AsRef<Path>>(
|
|||||||
let mut highlighter = HighlightFile::new(filename.as_ref().clone(), &ss, &theme)?;
|
let mut highlighter = HighlightFile::new(filename.as_ref().clone(), &ss, &theme)?;
|
||||||
|
|
||||||
let term = Term::stdout();
|
let term = Term::stdout();
|
||||||
let (_height, width) = term.size();
|
let (_, term_width) = term.size();
|
||||||
|
let term_width = term_width as usize;
|
||||||
|
|
||||||
let prefix = "───────┬";
|
print_horizontal_line('┬', term_width);
|
||||||
let line = "─".repeat(width as usize - prefix.len());
|
|
||||||
println!("{}{}", Fixed(238).paint(prefix), Fixed(238).paint(line));
|
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
" {} {}",
|
" {} {}",
|
||||||
Fixed(238).paint("│"),
|
Fixed(GRID_COLOR).paint("│"),
|
||||||
White.bold().paint(filename.as_ref().to_string_lossy())
|
White.bold().paint(filename.as_ref().to_string_lossy())
|
||||||
);
|
);
|
||||||
|
|
||||||
let prefix = "───────┼";
|
print_horizontal_line('┼', term_width);
|
||||||
let line = "─".repeat(width as usize - prefix.len());
|
|
||||||
println!("{}{}", Fixed(238).paint(prefix), Fixed(238).paint(line));
|
|
||||||
|
|
||||||
for (idx, maybe_line) in highlighter.reader.lines().enumerate() {
|
for (idx, maybe_line) in highlighter.reader.lines().enumerate() {
|
||||||
let line_nr = idx + 1;
|
let line_nr = idx + 1;
|
||||||
@ -80,14 +85,12 @@ fn print_file<P: AsRef<Path>>(
|
|||||||
"{} {} {} {}",
|
"{} {} {} {}",
|
||||||
Fixed(244).paint(format!("{:4}", line_nr)),
|
Fixed(244).paint(format!("{:4}", line_nr)),
|
||||||
line_change,
|
line_change,
|
||||||
Fixed(238).paint("│"),
|
Fixed(GRID_COLOR).paint("│"),
|
||||||
as_24_bit_terminal_escaped(®ions, false)
|
as_24_bit_terminal_escaped(®ions, false)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let prefix = "───────┴";
|
print_horizontal_line('┴', term_width);
|
||||||
let line = "─".repeat(width as usize - prefix.len());
|
|
||||||
println!("{}{}", Fixed(238).paint(prefix), Fixed(238).paint(line));
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user