summaryrefslogtreecommitdiffstats
path: root/src/layout.rs
diff options
context:
space:
mode:
authorkyoheiu <kyoheiu@outlook.com>2022-11-10 05:47:16 +0900
committerkyoheiu <kyoheiu@outlook.com>2022-11-10 05:47:16 +0900
commitcb8244e6fd5a27205a5547bc7013b326a4f76015 (patch)
treecdc17a035f071aba1aab19f55b55a5fb7484331b /src/layout.rs
parent8186bb14c5f3f6dea287073e04b094bde539164f (diff)
Remove unwrap as possible, return error
Diffstat (limited to 'src/layout.rs')
-rw-r--r--src/layout.rs14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/layout.rs b/src/layout.rs
index 8d271f2..cf4af93 100644
--- a/src/layout.rs
+++ b/src/layout.rs
@@ -106,7 +106,12 @@ impl Layout {
}
Some(PreviewType::Text) => {
if self.syntax_highlight {
- self.preview_text_with_sh(item);
+ match self.preview_text_with_sh(item) {
+ Ok(_) => {}
+ Err(e) => {
+ print!("{}", e);
+ }
+ }
} else {
self.preview_text(item);
}
@@ -147,7 +152,7 @@ impl Layout {
}
/// Preview text with syntax highlighting.
- fn preview_text_with_sh(&self, item: &ItemInfo) {
+ fn preview_text_with_sh(&self, item: &ItemInfo) -> Result<(), FxError> {
if let Ok(Some(syntax)) = self.syntax_set.find_syntax_for_file(item.file_path.clone()) {
let mut h = HighlightLines::new(syntax, &self.theme);
if let Some(content) = &item.content {
@@ -155,7 +160,7 @@ impl Layout {
let mut result = vec![];
for (index, line) in LinesWithEndings::from(content).enumerate() {
let count = line.len() / self.preview_space.0 as usize;
- let mut range = h.highlight_line(line, &self.syntax_set).unwrap();
+ let mut range = h.highlight_line(line, &self.syntax_set)?;
for _ in 0..=count + 1 {
let ranges = split_at(&range, (self.preview_space.0) as usize);
if !ranges.0.is_empty() {
@@ -178,6 +183,7 @@ impl Layout {
} else {
self.preview_text(item);
}
+ Ok(())
}
fn preview_directory(&self, item: &ItemInfo) {
@@ -273,7 +279,7 @@ impl Layout {
.args(["--animate=false", &wxh, file_path.unwrap()])
.output()?
.stdout;
- let output = String::from_utf8(output).unwrap();
+ let output = String::from_utf8(output)?;
match self.split {
Split::Vertical => {