feat: fallback to built-in highlighting if jq is not installed (#151)

This commit is contained in:
Nguyễn Đức Toàn 2023-09-13 23:01:16 +07:00 committed by GitHub
parent 4c98a351c9
commit 9c6b3c9d1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,6 +3,7 @@ use std::{io::BufRead, path::Path, sync::atomic::{AtomicUsize, Ordering}};
use adaptor::ADAPTOR; use adaptor::ADAPTOR;
use anyhow::anyhow; use anyhow::anyhow;
use config::{MANAGER, PREVIEW}; use config::{MANAGER, PREVIEW};
use futures::TryFutureExt;
use shared::{MimeKind, PeekError}; use shared::{MimeKind, PeekError};
use syntect::{easy::HighlightFile, util::as_24_bit_terminal_escaped}; use syntect::{easy::HighlightFile, util::as_24_bit_terminal_escaped};
use tokio::fs; use tokio::fs;
@ -69,7 +70,9 @@ impl Provider {
} }
pub(super) async fn json(path: &Path, skip: usize) -> Result<String, PeekError> { pub(super) async fn json(path: &Path, skip: usize) -> Result<String, PeekError> {
external::jq(path, skip, MANAGER.layout.preview_height()).await external::jq(path, skip, MANAGER.layout.preview_height())
.or_else(|_| Provider::highlight(path, skip))
.await
} }
pub(super) async fn archive(path: &Path, skip: usize) -> Result<String, PeekError> { pub(super) async fn archive(path: &Path, skip: usize) -> Result<String, PeekError> {