Skip to content

Commit

Permalink
frontend: added preview handling for json mime
Browse files Browse the repository at this point in the history
Signed-off-by: aserowy <serowy@hotmail.com>
  • Loading branch information
aserowy committed Sep 12, 2024
1 parent 6a4f249 commit fce622b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ because of the underlying architecture. Thus, it should be equally fast. E.g. re
a directory with 500k entries takes only a couple of seconds without blocking the
ui.

### image preview stays empty

Images are previewed using `chafa` to convert images to ansi. If the output stays
empty, make sure yeet can call `chafa` to enable image rendering.

### opening files in linux does nothing

yeet utilizes `xdg-open` to start files. Thus, not opening anything probably lies
Expand Down
21 changes: 13 additions & 8 deletions yeet-frontend/src/task/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,19 +321,24 @@ impl TaskManager {
let theme = &theme_set.themes["base16-eighties.dark"];

let content = if let Some(mime) = mime_guess::from_path(path.clone()).first() {
match mime.type_() {
mime::IMAGE => match image::load(&path, &rect).await {
match (mime.type_(), mime.subtype()) {
(mime::IMAGE, _) => match image::load(&path, &rect).await {
Some(content) => content,
None => "".to_string(),
},
mime::TEXT => match syntax::highlight(syntaxes, theme, &path).await {
Some(content) => content,
None => "".to_string(),
},
_ => "".to_string(),
(mime::TEXT, _) | (mime::APPLICATION, mime::JSON) => {
match syntax::highlight(syntaxes, theme, &path).await {
Some(content) => content,
None => "".to_string(),
}
}
_ => {
tracing::debug!("no preview specified for mime: {:?}", mime);
"".to_string()
}
}
} else {
tracing::warn!("unable to resolve kind for: {:?}", path);
tracing::debug!("unable to resolve kind for: {:?}", path);

match syntax::highlight(syntaxes, theme, &path).await {
Some(content) => content,
Expand Down
1 change: 1 addition & 0 deletions yeet-frontend/src/task/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub async fn highlight(syntaxes: &SyntaxSet, theme: &Theme, path: &Path) -> Opti

Some(result)
} else {
tracing::debug!("unable to resolve syntax for: {:?}", path);
Some(content)
}
}
Expand Down

0 comments on commit fce622b

Please sign in to comment.