feat: font preview (#1048)

This commit is contained in:
三咲雅 · Misaki Masa 2024-05-17 13:56:27 +08:00 committed by GitHub
parent f2329a3b35
commit 65afe6027a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 95 additions and 31 deletions

36
Cargo.lock generated
View File

@ -1211,9 +1211,9 @@ dependencies = [
[[package]]
name = "mlua"
version = "0.9.7"
version = "0.9.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d9bed6bce296397a9d6a86f995dd10a547a4e6949825d45225906bdcbfe7367"
checksum = "e340c022072f3208a4105458286f4985ba5355bfe243c3073afe45cbe9ecf491"
dependencies = [
"bstr",
"erased-serde",
@ -1229,9 +1229,9 @@ dependencies = [
[[package]]
name = "mlua-sys"
version = "0.5.2"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d16a9ba1dd2c6ac971b204262d434c24d65067038598f0638b64e5dca28d52b8"
checksum = "5552e7e4e22ada0463dfdeee6caf6dc057a189fdc83136408a8f950a5e5c5540"
dependencies = [
"cc",
"cfg-if",
@ -1242,9 +1242,9 @@ dependencies = [
[[package]]
name = "mlua_derive"
version = "0.9.2"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aaade5f94e5829db58791664ba98f35fea6a3ffebc783becb51dc97c7a21abee"
checksum = "09697a6cec88e7f58a02c7ab5c18c611c6907c8654613df9cc0192658a4fb859"
dependencies = [
"itertools",
"once_cell",
@ -1704,9 +1704,9 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
name = "serde"
version = "1.0.201"
version = "1.0.202"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "780f1cebed1629e4753a1a38a3c72d30b97ec044f0aef68cb26650a3c5cf363c"
checksum = "226b61a0d411b2ba5ff6d7f73a476ac4f8bb900373459cd00fab8512828ba395"
dependencies = [
"serde_derive",
]
@ -1723,9 +1723,9 @@ dependencies = [
[[package]]
name = "serde_derive"
version = "1.0.201"
version = "1.0.202"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c5e405930b9796f1c00bee880d03fc7e0bb4b9a11afc776885ffe84320da2865"
checksum = "6048858004bcff69094cd972ed40a32500f153bd3be9f716b2eed2e8217c4838"
dependencies = [
"proc-macro2",
"quote",
@ -1745,9 +1745,9 @@ dependencies = [
[[package]]
name = "serde_spanned"
version = "0.6.5"
version = "0.6.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1"
checksum = "79e674e01f999af37c49f70a6ede167a8a60b2503e56c5599532a65baa5969a0"
dependencies = [
"serde",
]
@ -2113,9 +2113,9 @@ dependencies = [
[[package]]
name = "toml"
version = "0.8.12"
version = "0.8.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e9dd1545e8208b4a5af1aa9bbd0b4cf7e9ea08fabc5d0a5c67fcaafa17433aa3"
checksum = "a4e43f8cc456c9704c851ae29c67e17ef65d2c30017c17a9765b89c382dc8bba"
dependencies = [
"indexmap",
"serde",
@ -2126,18 +2126,18 @@ dependencies = [
[[package]]
name = "toml_datetime"
version = "0.6.5"
version = "0.6.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1"
checksum = "4badfd56924ae69bcc9039335b2e017639ce3f9b001c393c1b2d1ef846ce2cbf"
dependencies = [
"serde",
]
[[package]]
name = "toml_edit"
version = "0.22.12"
version = "0.22.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3328d4f68a705b2a4498da1d580585d39a6510f98318a2cec3018a7ec61ddef"
checksum = "c127785850e8c20836d49732ae6abfa47616e60bf9d9f57c43c250361a9db96c"
dependencies = [
"indexmap",
"serde",

View File

@ -32,7 +32,7 @@ impl Emulator {
match self {
Self::Unknown(adapters) => adapters,
Self::Kitty => vec![Adaptor::Kitty],
Self::Konsole => vec![Adaptor::KittyOld, Adaptor::Iterm2, Adaptor::Sixel],
Self::Konsole => vec![Adaptor::Iterm2, Adaptor::KittyOld, Adaptor::Sixel],
Self::Iterm2 => vec![Adaptor::Iterm2, Adaptor::Sixel],
Self::WezTerm => vec![Adaptor::Iterm2, Adaptor::Sixel],
Self::Foot => vec![Adaptor::Sixel],

View File

@ -15,7 +15,7 @@ yazi-shared = { path = "../yazi-shared", version = "0.2.5" }
# External dependencies
clap = { version = "4.5.4", features = [ "derive" ] }
serde = { version = "1.0.201", features = [ "derive" ] }
serde = { version = "1.0.202", features = [ "derive" ] }
[build-dependencies]
clap = { version = "4.5.4", features = [ "derive" ] }

View File

@ -19,7 +19,7 @@ crossterm = "0.27.0"
md-5 = "0.10.6"
serde_json = "1.0.117"
tokio = { version = "1.37.0", features = [ "full" ] }
toml_edit = "0.22.12"
toml_edit = "0.22.13"
[build-dependencies]
anyhow = "1.0.83"

View File

@ -18,7 +18,7 @@ crossterm = "0.27.0"
globset = "0.4.14"
indexmap = "2.2.6"
ratatui = "=0.26.1"
serde = { version = "1.0.201", features = [ "derive" ] }
serde = { version = "1.0.202", features = [ "derive" ] }
shell-words = "1.1.0"
toml = { version = "0.8.12", features = [ "preserve_order" ] }
toml = { version = "0.8.13", features = [ "preserve_order" ] }
validator = { version = "0.18.1", features = [ "derive" ] }

View File

@ -303,6 +303,11 @@ rules = [
{ name = "*.xlsx", text = "", fg = "#207245" },
{ name = "*.xlt" , text = "", fg = "#207245" },
# Fonts
{ name = "*.eot", text = "", fg = "#ececec" },
{ name = "*.[ot]tf", text = "", fg = "#ececec" },
{ name = "*.{woff,woff2}", text = "", fg = "#ececec" },
# Lockfiles
{ name = "*.lock", text = "", fg = "#bbbbbb" },

View File

@ -87,6 +87,9 @@ preloaders = [
{ mime = "video/*", run = "video" },
# PDF
{ mime = "application/pdf", run = "pdf" },
# Font
{ mime = "font/*", run = "font" },
{ mime = "application/vnd.ms-opentype", run = "font" },
]
previewers = [
{ name = "*/", run = "folder", sync = true },
@ -105,6 +108,9 @@ previewers = [
# Archive
{ mime = "application/*zip", run = "archive" },
{ mime = "application/x-{tar,bzip*,7z-compressed,xz,rar}", run = "archive" },
# Font
{ mime = "font/*", run = "font" },
{ mime = "application/vnd.ms-opentype", run = "font" },
# Fallback
{ name = "*", run = "file" },
]

View File

@ -28,7 +28,7 @@ parking_lot = "0.12.2"
ratatui = "=0.26.1"
regex = "1.10.4"
scopeguard = "1.2.0"
serde = "1.0.201"
serde = "1.0.202"
tokio = { version = "1.37.0", features = [ "full" ] }
tokio-stream = "0.1.15"
tokio-util = "0.7.11"

View File

@ -18,9 +18,9 @@ yazi-shared = { path = "../yazi-shared", version = "0.2.5" }
# External dependencies
anyhow = "1.0.83"
mlua = { version = "0.9.7", features = [ "lua54" ] }
mlua = { version = "0.9.8", features = [ "lua54" ] }
parking_lot = "0.12.2"
serde = { version = "1.0.201", features = [ "derive" ] }
serde = { version = "1.0.202", features = [ "derive" ] }
serde_json = "1.0.117"
tokio = { version = "1.37.0", features = [ "full" ] }
tokio-stream = "0.1.15"

View File

@ -28,7 +28,7 @@ better-panic = "0.3.0"
crossterm = { version = "0.27.0", features = [ "event-stream" ] }
fdlimit = "0.3.0"
futures = "0.3.30"
mlua = { version = "0.9.7", features = [ "lua54" ] }
mlua = { version = "0.9.8", features = [ "lua54" ] }
ratatui = "=0.26.1"
scopeguard = "1.2.0"
syntect = { version = "5.2.0", default-features = false, features = [ "parsing", "plist-load", "regex-onig" ] }

View File

@ -27,10 +27,10 @@ base64 = "0.22.1"
crossterm = "0.27.0"
futures = "0.3.30"
md-5 = "0.10.6"
mlua = { version = "0.9.7", features = [ "lua54", "serialize", "macros", "async" ] }
mlua = { version = "0.9.8", features = [ "lua54", "serialize", "macros", "async" ] }
parking_lot = "0.12.2"
ratatui = "=0.26.1"
serde = "1.0.201"
serde = "1.0.202"
serde_json = "1.0.117"
shell-escape = "0.1.5"
shell-words = "1.1.0"

View File

@ -0,0 +1,52 @@
local TEXT = "ABCDEFGHIJKLM\nNOPQRSTUVWXYZ\nabcdefghijklm\nnopqrstuvwxyz\n1234567890\n!$&*()[]{}"
local M = {}
function M:peek()
local cache = ya.file_cache(self)
if not cache then
return
end
if self:preload() == 1 then
ya.image_show(cache, self.area)
ya.preview_widgets(self, {})
end
end
function M:seek() end
function M:preload()
local cache = ya.file_cache(self)
if not cache or fs.cha(cache) then
return 1
end
local child, code = Command("convert"):args({
"-size",
"800x560",
"-gravity",
"center",
"-font",
tostring(self.file.url),
"-pointsize",
"64",
"xc:white",
"-fill",
"black",
"-annotate",
"+0+0",
TEXT,
"JPG:" .. tostring(cache),
}):spawn()
if not child then
ya.err("spawn `convert` command returns " .. tostring(code))
return 0
end
local status = child:wait()
return status and status:success() and 1 or 2
end
return M

View File

@ -40,6 +40,7 @@ impl Loader {
"code" => include_bytes!("../../preset/plugins/code.lua"),
"file" => include_bytes!("../../preset/plugins/file.lua"),
"folder" => include_bytes!("../../preset/plugins/folder.lua"),
"font" => include_bytes!("../../preset/plugins/font.lua"),
"fzf" => include_bytes!("../../preset/plugins/fzf.lua"),
"image" => include_bytes!("../../preset/plugins/image.lua"),
"json" => include_bytes!("../../preset/plugins/json.lua"),

View File

@ -18,5 +18,5 @@ yazi-shared = { path = "../yazi-shared", version = "0.2.5" }
# External dependencies
anyhow = "1.0.83"
mlua = { version = "0.9.7", features = [ "lua54" ] }
mlua = { version = "0.9.8", features = [ "lua54" ] }
tokio = { version = "1.37.0", features = [ "full" ] }

View File

@ -19,7 +19,7 @@ parking_lot = "0.12.2"
percent-encoding = "2.3.1"
ratatui = "=0.26.1"
regex = "1.10.4"
serde = { version = "1.0.201", features = [ "derive" ] }
serde = { version = "1.0.202", features = [ "derive" ] }
tokio = { version = "1.37.0", features = [ "full" ] }
# Logging