@@ -50,10 +50,10 @@ fn print_horizontal_line(
5050 grid_char: char,
5151 term_width: usize,
5252) -> io::Result<()> {
53− let bar = "─".repeat(term_width - (PANEL_WIDTH + 1));
54− let line = format!("{}{}{}", "─".repeat(PANEL_WIDTH), grid_char, bar);
53+ let hline = "─".repeat(term_width - (PANEL_WIDTH + 1));
54+ let hline = format!("{}{}{}", "─".repeat(PANEL_WIDTH), grid_char, hline);
5555
56− write!(handle, "{}\n", Fixed(GRID_COLOR).paint(line))?;
56+ writeln!(handle, "{}", Fixed(GRID_COLOR).paint(hline))?;
5757
5858 Ok(())
5959}
@@ -63,9 +63,9 @@ fn print_file<P: AsRef<Path>>(
6363 theme: &Theme,
6464 syntax_set: &SyntaxSet,
6565 filename: P,
66− line_changes: Option<LineChanges>,
66+ line_changes: &Option<LineChanges>,
6767) -> io::Result<()> {
68− let mut highlighter = HighlightFile::new(filename.as_ref().clone(), syntax_set, theme)?;
68+ let mut highlighter = HighlightFile::new(filename.as_ref(), syntax_set, theme)?;
6969
7070 let stdout = io::stdout();
7171 let mut handle = stdout.lock();
@@ -76,9 +76,9 @@ fn print_file<P: AsRef<Path>>(
7676
7777 print_horizontal_line(&mut handle, '┬', term_width)?;
7878
79− write!(
79+ writeln!(
8080 handle,
81− "{}{} File {}\n",
81+ "{}{} File {}",
8282 " ".repeat(PANEL_WIDTH),
8383 Fixed(GRID_COLOR).paint("│"),
8484 White.bold().paint(filename.as_ref().to_string_lossy())
@@ -88,10 +88,10 @@ fn print_file<P: AsRef<Path>>(
8888
8989 for (idx, maybe_line) in highlighter.reader.lines().enumerate() {
9090 let line_nr = idx + 1;
91− let line = maybe_line.unwrap_or("<INVALID UTF-8>".into());
91+ let line = maybe_line.unwrap_or_else(|_| "<INVALID UTF-8>".into());
9292 let regions = highlighter.highlight_lines.highlight(&line);
9393
94− let line_change = if let Some(ref changes) = line_changes {
94+ let line_change = if let Some(ref changes) = *line_changes {
9595 match changes.get(&(line_nr as u32)) {
9696 Some(&LineChange::Added) => Green.paint("+"),
9797 Some(&LineChange::RemovedAbove) => Red.paint("‾"),
@@ -103,9 +103,9 @@ fn print_file<P: AsRef<Path>>(
103103 Style::default().paint(" ")
104104 };
105105
106− write!(
106+ writeln!(
107107 handle,
108− "{} {} {} {}\n",
108+ "{} {} {} {}",
109109 Fixed(244).paint(format!("{:4}", line_nr)),
110110 line_change,
111111 Fixed(GRID_COLOR).paint("│"),
@@ -118,7 +118,7 @@ fn print_file<P: AsRef<Path>>(
118118 Ok(())
119119}
120120
121−fn get_git_diff(filename: String) -> Option<LineChanges> {
121+fn get_git_diff(filename: &str) -> Option<LineChanges> {
122122 let repo = Repository::open_from_env().ok()?;
123123 let workdir = repo.workdir()?;
124124 let current_dir = env::current_dir().ok()?;
@@ -145,7 +145,7 @@ fn get_git_diff(filename: String) -> Option<LineChanges> {
145145 &mut |_, _| true,
146146 None,
147147 Some(&mut |delta, hunk| {
148− let path = delta.new_file().path().unwrap_or(Path::new(""));
148+ let path = delta.new_file().path().unwrap_or_else(|| Path::new(""));
149149
150150 if filepath != workdir.join(path) {
151151 return false;
@@ -159,7 +159,7 @@ fn get_git_diff(filename: String) -> Option<LineChanges> {
159159 if old_lines == 0 && new_lines > 0 {
160160 mark_section(&mut line_changes, new_start, new_end, LineChange::Added);
161161 } else if new_lines == 0 && old_lines > 0 {
162− if new_start <= 0 {
162+ if new_start == 0 {
163163 mark_section(&mut line_changes, 1, 1, LineChange::RemovedAbove);
164164 } else {
165165 mark_section(
@@ -182,12 +182,10 @@ fn get_git_diff(filename: String) -> Option<LineChanges> {
182182}
183183
184184fn run(matches: &ArgMatches) -> Result<()> {
185− let home_dir = env::home_dir().ok_or(io::Error::new(
186− ErrorKind::Other,
187− "Could not get home directory",
188− ))?;
185+ let home_dir = env::home_dir()
186+ .ok_or_else(|| io::Error::new(ErrorKind::Other, "Could not get home directory"))?;
189187
190− let colorterm = env::var("COLORTERM").unwrap_or("".into());
188+ let colorterm = env::var("COLORTERM").unwrap_or_else(|_| "".into());
191189
192190 let options = Options {
193191 true_color: colorterm == "truecolor" || colorterm == "24bit",
@@ -196,10 +194,12 @@ fn run(matches: &ArgMatches) -> Result<()> {
196194 let theme_dir = home_dir.join(".config").join("bat").join("themes");
197195 let theme_set = ThemeSet::load_from_folder(theme_dir)
198196 .map_err(|_| io::Error::new(ErrorKind::Other, "Could not load themes"))?;
199− let theme = &theme_set.themes.get("Default").ok_or(io::Error::new(
200− ErrorKind::Other,
201− "Could not load default theme (~/.config/bat/themes/Default.tmTheme)",
202− ))?;
197+ let theme = &theme_set.themes.get("Default").ok_or_else(|| {
198+ io::Error::new(
199+ ErrorKind::Other,
200+ "Could not load default theme (~/.config/bat/themes/Default.tmTheme)",
201+ )
202+ })?;
203203
204204 // TODO: let mut syntax_set = SyntaxSet::load_defaults_nonewlines();
205205 let mut syntax_set = SyntaxSet::new();
@@ -210,8 +210,8 @@ fn run(matches: &ArgMatches) -> Result<()> {
210210
211211 if let Some(files) = matches.values_of("FILE") {
212212 for file in files {
213− let line_changes = get_git_diff(file.to_string());
214− print_file(&options, theme, &syntax_set, file, line_changes)?;
213+ let line_changes = get_git_diff(&file.to_string());
214+ print_file(&options, theme, &syntax_set, file, &line_changes)?;
215215 }
216216 }
217217