mirror of
https://github.com/sharkdp/bat.git
synced 2024-12-22 14:30:42 +01:00
Print filename
This commit is contained in:
parent
ab10a20c1f
commit
6b507d1e35
14
src/main.rs
14
src/main.rs
@ -12,7 +12,7 @@ use std::io::{self, BufRead, Result};
|
|||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::process;
|
use std::process;
|
||||||
|
|
||||||
use ansi_term::Colour::{Fixed, Green, Red, Yellow};
|
use ansi_term::Colour::{Fixed, Green, Red, Yellow, White};
|
||||||
use atty::Stream;
|
use atty::Stream;
|
||||||
use clap::{App, AppSettings, Arg, ArgMatches};
|
use clap::{App, AppSettings, Arg, ArgMatches};
|
||||||
use console::Term;
|
use console::Term;
|
||||||
@ -38,7 +38,7 @@ fn print_file<P: AsRef<Path>>(filename: P, line_changes: Option<LineChanges>) ->
|
|||||||
let ts = ThemeSet::load_defaults();
|
let ts = ThemeSet::load_defaults();
|
||||||
let theme = &ts.themes["base16-eighties.dark"];
|
let theme = &ts.themes["base16-eighties.dark"];
|
||||||
|
|
||||||
let mut highlighter = HighlightFile::new(filename, &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 (_height, width) = term.size();
|
||||||
@ -47,6 +47,16 @@ fn print_file<P: AsRef<Path>>(filename: P, line_changes: Option<LineChanges>) ->
|
|||||||
let line = "─".repeat(width as usize - prefix.len());
|
let line = "─".repeat(width as usize - prefix.len());
|
||||||
println!("{}{}", Fixed(238).paint(prefix), Fixed(238).paint(line));
|
println!("{}{}", Fixed(238).paint(prefix), Fixed(238).paint(line));
|
||||||
|
|
||||||
|
println!(
|
||||||
|
" {} {}",
|
||||||
|
Fixed(238).paint("│"),
|
||||||
|
White.bold().paint(filename.as_ref().to_string_lossy())
|
||||||
|
);
|
||||||
|
|
||||||
|
let prefix = "───────┼";
|
||||||
|
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;
|
||||||
let line = maybe_line.unwrap_or("<INVALID UTF-8>".into());
|
let line = maybe_line.unwrap_or("<INVALID UTF-8>".into());
|
||||||
|
Loading…
Reference in New Issue
Block a user