diff options
author | Jeff Zhao <jeff.no.zhao@gmail.com> | 2021-06-23 10:22:00 -0400 |
---|---|---|
committer | Jeff Zhao <jeff.no.zhao@gmail.com> | 2021-06-23 10:22:00 -0400 |
commit | f26fc0cb6826cd126c71e7bd7f1565843d86f65c (patch) | |
tree | b6463e4fdb6de2e985358808f9d995a4fca39352 | |
parent | a11ed197df4fc3830387931c684346975333baf3 (diff) |
fix text preview formatting
- don't store preview if exit code is 1
-rw-r--r-- | src/ui/widgets/tui_file_preview.rs | 5 | ||||
-rw-r--r-- | src/util/input.rs | 11 |
2 files changed, 12 insertions, 4 deletions
diff --git a/src/ui/widgets/tui_file_preview.rs b/src/ui/widgets/tui_file_preview.rs index f731a0e..7fe3822 100644 --- a/src/ui/widgets/tui_file_preview.rs +++ b/src/ui/widgets/tui_file_preview.rs @@ -30,6 +30,9 @@ impl<'a> TuiFilePreview<'a> { impl<'a> Widget for TuiFilePreview<'a> { fn render(self, area: Rect, buf: &mut Buffer) { let style = Style::default(); - buf.set_string(area.x, area.y, self.preview.output.as_str(), style); + let area_width = area.width as usize; + for (y, s) in (area.y..area.y + area.height).zip(self.preview.output.as_str().split('\n')) { + buf.set_stringn(area.x, y, s, area_width, style); + } } } diff --git a/src/util/input.rs b/src/util/input.rs index 0896292..200a92a 100644 --- a/src/util/input.rs +++ b/src/util/input.rs @@ -82,9 +82,14 @@ pub fn process_dir_preview(context: &mut AppContext, dirlist: JoshutoDirList) { } pub fn process_file_preview(context: &mut AppContext, file_preview: FilePreview) { - context - .preview_context_mut() - .insert_preview(file_preview._path.clone(), file_preview); + match file_preview.status.code() { + Some(1) | None => {} + _ => { + context + .preview_context_mut() + .insert_preview(file_preview._path.clone(), file_preview); + } + } } pub fn process_mouse(event: MouseEvent, context: &mut AppContext, backend: &mut ui::TuiBackend) { |