exa/src/output/lines.rs
Benjamin Sago f1e3e7c7ff Move icon generation into file name module
This commit makes adding icons to file names something that the file name renderer does, rather than something that each individual view does. This is now possible thanks to the previous commit a1869f2, which moved the option to do this into the same module. The repeated code has been removed.

It happens to fix a bug where the width of each column was being incorrectly calculated for the grid-details view, making lines slightly too long for the terminal because the icon wasn't being taken into account.
2020-10-24 18:03:36 +01:00

35 lines
849 B
Rust

use std::io::{self, Write};
use ansi_term::ANSIStrings;
use crate::fs::File;
use crate::output::cell::TextCellContents;
use crate::output::file_name::{Options as FileStyle};
use crate::theme::Theme;
/// The lines view literally just displays each file, line-by-line.
pub struct Render<'a> {
pub files: Vec<File<'a>>,
pub theme: &'a Theme,
pub file_style: &'a FileStyle,
}
impl<'a> Render<'a> {
pub fn render<W: Write>(&self, w: &mut W) -> io::Result<()> {
for file in &self.files {
let name_cell = self.render_file(file);
writeln!(w, "{}", ANSIStrings(&name_cell))?;
}
Ok(())
}
fn render_file<'f>(&self, file: &'f File<'a>) -> TextCellContents {
self.file_style
.for_file(file, self.theme)
.with_link_paths()
.paint()
}
}