Struct broot::preview::ZeroLenFileView
source · pub struct ZeroLenFileView { /* private fields */ }
Expand description
a (light) display for a file declaring a size 0, as happens for many system “files”, for example in /proc
Implementations§
source§impl ZeroLenFileView
impl ZeroLenFileView
sourcepub fn new(path: PathBuf) -> Self
pub fn new(path: PathBuf) -> Self
Examples found in repository?
src/preview/preview.rs (line 96)
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
pub fn unfiltered_text(
path: &Path,
con: &AppContext,
) -> Self {
match SyntacticView::new(path, InputPattern::none(), &mut Dam::unlimited(), con, false) {
Ok(Some(sv)) => Self::Syntactic(sv),
Err(ProgramError::ZeroLenFile | ProgramError::UnmappableFile) => {
debug!("zero len or unmappable file - check if system file");
Self::ZeroLen(ZeroLenFileView::new(path.to_path_buf()))
}
Err(ProgramError::SyntectCrashed { details }) => {
warn!("syntect crashed with message : {details:?}");
Self::unstyled_text(path, con)
}
// not previewable as UTF8 text
// we'll try reading it as binary
Err(ProgramError::UnprintableFile) => Self::hex(path),
_ => Self::hex(path),
}
}
/// build a text preview with no syntax highlighting, if possible
pub fn unstyled_text(
path: &Path,
con: &AppContext,
) -> Self {
match SyntacticView::new(path, InputPattern::none(), &mut Dam::unlimited(), con, true) {
Ok(Some(sv)) => Self::Syntactic(sv),
Err(ProgramError::ZeroLenFile | ProgramError::UnmappableFile) => {
debug!("zero len or unmappable file - check if system file");
Self::ZeroLen(ZeroLenFileView::new(path.to_path_buf()))
}
// not previewable as UTF8 text - we'll try reading it as binary
Err(ProgramError::UnprintableFile) => Self::hex(path),
_ => Self::hex(path),
}
}
sourcepub fn display(
&mut self,
w: &mut W,
_screen: Screen,
panel_skin: &PanelSkin,
area: &Area
) -> Result<(), ProgramError>
pub fn display(
&mut self,
w: &mut W,
_screen: Screen,
panel_skin: &PanelSkin,
area: &Area
) -> Result<(), ProgramError>
Examples found in repository?
src/preview/preview.rs (line 257)
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
pub fn display(
&mut self,
w: &mut W,
disc: &DisplayContext,
area: &Area,
) -> Result<(), ProgramError> {
let panel_skin = &disc.panel_skin;
let screen = disc.screen;
let con = &disc.con;
match self {
Self::Image(iv) => iv.display(w, disc, area),
Self::Syntactic(sv) => sv.display(w, screen, panel_skin, area, con),
Self::ZeroLen(zlv) => zlv.display(w, screen, panel_skin, area),
Self::Hex(hv) => hv.display(w, screen, panel_skin, area),
Self::IoError(err) => {
let mut y = area.top;
w.queue(cursor::MoveTo(area.left, y))?;
let mut cw = CropWriter::new(w, area.width as usize);
cw.queue_str(&panel_skin.styles.default, "An error prevents the preview:")?;
cw.fill(&panel_skin.styles.default, &SPACE_FILLING)?;
y += 1;
w.queue(cursor::MoveTo(area.left, y))?;
let mut cw = CropWriter::new(w, area.width as usize);
cw.queue_g_string(&panel_skin.styles.status_error, err.to_string())?;
cw.fill(&panel_skin.styles.default, &SPACE_FILLING)?;
y += 1;
while y < area.top + area.height {
w.queue(cursor::MoveTo(area.left, y))?;
let mut cw = CropWriter::new(w, area.width as usize);
cw.fill(&panel_skin.styles.default, &SPACE_FILLING)?;
y += 1;
}
Ok(())
}
}
}