From fbf9b3d1ed3b1bde4ac711c3b9631be108a86576 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E9=9B=85=20=C2=B7=20Misaki=20Masa?= Date: Thu, 5 Dec 2024 22:07:40 +0800 Subject: [PATCH] fix!: remove the `vnd.` prefix from mimetype to solve differences introduced in the newest version of `file(1)` 5.46 (#1995) --- scripts/icons/generate.lua | 2 +- yazi-config/preset/theme-base.toml | 229 ----------------- .../{theme+dark.toml => theme-dark.toml} | 232 +++++++++++++++++- .../{theme+light.toml => theme-light.toml} | 232 +++++++++++++++++- yazi-config/preset/yazi.toml | 8 +- yazi-macro/src/asset.rs | 28 ++- yazi-plugin/preset/plugins/mime.lua | 2 +- 7 files changed, 479 insertions(+), 254 deletions(-) delete mode 100644 yazi-config/preset/theme-base.toml rename yazi-config/preset/{theme+dark.toml => theme-dark.toml} (88%) rename yazi-config/preset/{theme+light.toml => theme-light.toml} (88%) diff --git a/scripts/icons/generate.lua b/scripts/icons/generate.lua index da98fccb..8ac8623e 100644 --- a/scripts/icons/generate.lua +++ b/scripts/icons/generate.lua @@ -31,7 +31,7 @@ function dump(map) end function save(typ, files, exts) - local p = string.format("../../yazi-config/preset/theme+%s.toml", typ) + local p = string.format("../../yazi-config/preset/theme-%s.toml", typ) local s = io.open(p, "r"):read("*a") s = s:gsub("files = %[\n(.-)\n%]", string.format("files = [\n%s]", files)) s = s:gsub("exts = %[\n(.-)\n%]", string.format("exts = [\n%s]", exts)) diff --git a/yazi-config/preset/theme-base.toml b/yazi-config/preset/theme-base.toml deleted file mode 100644 index 3c7bf625..00000000 --- a/yazi-config/preset/theme-base.toml +++ /dev/null @@ -1,229 +0,0 @@ -# If the user's terminal is in dark mode, Yazi will use the content from `theme-base.toml` + `theme+dark.toml` as the default theme; -# if it's in light mode, use `theme-base.toml` + `theme+light.toml` instead. -# Users can always override and adjust the default theme in their own `theme.toml` configuration file. -"$schema" = "https://yazi-rs.github.io/schemas/theme.json" - -# vim:fileencoding=utf-8:foldmethod=marker - -# : Flavor {{{ - -[flavor] -dark = "" -light = "" - -# : }}} - -# : Manager {{{ - -[manager] -cwd = { fg = "cyan" } - -# Hovered -hovered = { reversed = true } -preview_hovered = { underline = true } - -# Find -find_keyword = { fg = "yellow", bold = true, italic = true, underline = true } -find_position = { fg = "magenta", bg = "reset", bold = true, italic = true } - -# Marker -marker_copied = { fg = "lightgreen", bg = "lightgreen" } -marker_cut = { fg = "lightred", bg = "lightred" } -marker_marked = { fg = "lightcyan", bg = "lightcyan" } -marker_selected = { fg = "lightyellow", bg = "lightyellow" } - -# Tab -tab_active = { reversed = true } -tab_inactive = {} -tab_width = 1 - -# Count -count_copied = { fg = "white", bg = "green" } -count_cut = { fg = "white", bg = "red" } -count_selected = { fg = "white", bg = "yellow" } - -# Border -border_symbol = "│" -border_style = { fg = "gray" } - -# Highlighting -syntect_theme = "" - -# : }}} - - -# : Mode {{{ - -[mode] - -normal_main = { bg = "blue", bold = true } -normal_alt = { fg = "blue", bg = "gray" } - -# Select mode -select_main = { bg = "red", bold = true } -select_alt = { fg = "red", bg = "gray" } - -# Unset mode -unset_main = { bg = "red", bold = true } -unset_alt = { fg = "red", bg = "gray" } - -# : }}} - - -# : Status bar {{{ - -[status] -separator_open = "" -separator_close = "" - -# Progress -progress_label = { bold = true } -progress_normal = { fg = "blue", bg = "black" } -progress_error = { fg = "red", bg = "black" } - -# Permissions -perm_sep = { fg = "darkgray" } -perm_type = { fg = "green" } -perm_read = { fg = "yellow" } -perm_write = { fg = "red" } -perm_exec = { fg = "cyan" } - -# : }}} - - -# : Pick {{{ - -[pick] -border = { fg = "blue" } -active = { fg = "magenta", bold = true } -inactive = {} - -# : }}} - - -# : Input {{{ - -[input] -border = { fg = "blue" } -title = {} -value = {} -selected = { reversed = true } - -# : }}} - - -# : Confirm {{{ - -[confirm] -border = { fg = "blue" } -title = { fg = "blue" } -content = {} -list = {} -btn_yes = { reversed = true } -btn_no = {} -btn_labels = [ " [Y]es ", " (N)o " ] - -# : }}} - - -# : Completion {{{ - -[completion] -border = { fg = "blue" } -active = { reversed = true } -inactive = {} - -# Icons -icon_file = "" -icon_folder = "" -icon_command = "" - -# : }}} - - -# : Tasks {{{ - -[tasks] -border = { fg = "blue" } -title = {} -hovered = { fg = "magenta", underline = true } - -# : }}} - - -# : Which {{{ - -[which] -cols = 3 -mask = { bg = "black" } -cand = { fg = "lightcyan" } -rest = { fg = "darkgray" } -desc = { fg = "lightmagenta" } -separator = "  " -separator_style = { fg = "darkgray" } - -# : }}} - - -# : Help {{{ - -[help] -on = { fg = "cyan" } -run = { fg = "magenta" } -desc = {} -hovered = { reversed = true, bold = true } -footer = { fg = "black", bg = "white" } - -# : }}} - - -# : Notify {{{ - -[notify] -title_info = { fg = "green" } -title_warn = { fg = "yellow" } -title_error = { fg = "red" } - -# Icons -icon_info = "" -icon_warn = "" -icon_error = "" - -# : }}} - - -# : File-specific styles {{{ - -[filetype] - -rules = [ - # Images - { mime = "image/*", fg = "yellow" }, - - # Media - { mime = "{audio,video}/*", fg = "magenta" }, - - # Archives - { mime = "application/{,g}zip", fg = "red" }, - { mime = "application/{tar,bzip*,7z-compressed,xz,rar}", fg = "red" }, - - # Documents - { mime = "application/{pdf,doc,rtf,vnd.*}", fg = "cyan" }, - - # Empty files - # { mime = "inode/empty", fg = "red" }, - - # Special files - { name = "*", is = "orphan", bg = "red" }, - { name = "*", is = "exec" , fg = "green" }, - - # Dummy files - { name = "*", is = "dummy", bg = "red" }, - { name = "*/", is = "dummy", bg = "red" }, - - # Fallback - # { name = "*", fg = "white" }, - { name = "*/", fg = "blue" } -] - -# : }}} diff --git a/yazi-config/preset/theme+dark.toml b/yazi-config/preset/theme-dark.toml similarity index 88% rename from yazi-config/preset/theme+dark.toml rename to yazi-config/preset/theme-dark.toml index e57fe1d8..1457cc2a 100644 --- a/yazi-config/preset/theme+dark.toml +++ b/yazi-config/preset/theme-dark.toml @@ -1,10 +1,236 @@ -# If the user's terminal is in dark mode, Yazi will use the content from `theme-base.toml` + `theme+dark.toml` as the default theme; -# if it's in light mode, use `theme-base.toml` + `theme+light.toml` instead. -# Users can always override and adjust the default theme in their own `theme.toml` configuration file. +# If the user's terminal is in dark mode, Yazi will load `theme-dark.toml` on startup; otherwise, `theme-light.toml`. +# You can override any parts of them that are not related to the dark/light mode in your own `theme.toml`. + +# If you want to dynamically override their content based on dark/light mode, you can specify two different flavors +# for dark and light modes under `[flavor]`, and do so in those flavors instead. "$schema" = "https://yazi-rs.github.io/schemas/theme.json" # vim:fileencoding=utf-8:foldmethod=marker +# : Flavor {{{ + +[flavor] +dark = "" +light = "" + +# : }}} + +# : Manager {{{ + +[manager] +cwd = { fg = "cyan" } + +# Hovered +hovered = { reversed = true } +preview_hovered = { underline = true } + +# Find +find_keyword = { fg = "yellow", bold = true, italic = true, underline = true } +find_position = { fg = "magenta", bg = "reset", bold = true, italic = true } + +# Marker +marker_copied = { fg = "lightgreen", bg = "lightgreen" } +marker_cut = { fg = "lightred", bg = "lightred" } +marker_marked = { fg = "lightcyan", bg = "lightcyan" } +marker_selected = { fg = "lightyellow", bg = "lightyellow" } + +# Tab +tab_active = { reversed = true } +tab_inactive = {} +tab_width = 1 + +# Count +count_copied = { fg = "white", bg = "green" } +count_cut = { fg = "white", bg = "red" } +count_selected = { fg = "white", bg = "yellow" } + +# Border +border_symbol = "│" +border_style = { fg = "gray" } + +# Highlighting +syntect_theme = "" + +# : }}} + + +# : Mode {{{ + +[mode] + +normal_main = { bg = "blue", bold = true } +normal_alt = { fg = "blue", bg = "gray" } + +# Select mode +select_main = { bg = "red", bold = true } +select_alt = { fg = "red", bg = "gray" } + +# Unset mode +unset_main = { bg = "red", bold = true } +unset_alt = { fg = "red", bg = "gray" } + +# : }}} + + +# : Status bar {{{ + +[status] +separator_open = "" +separator_close = "" + +# Progress +progress_label = { bold = true } +progress_normal = { fg = "blue", bg = "black" } +progress_error = { fg = "red", bg = "black" } + +# Permissions +perm_sep = { fg = "darkgray" } +perm_type = { fg = "green" } +perm_read = { fg = "yellow" } +perm_write = { fg = "red" } +perm_exec = { fg = "cyan" } + +# : }}} + + +# : Pick {{{ + +[pick] +border = { fg = "blue" } +active = { fg = "magenta", bold = true } +inactive = {} + +# : }}} + + +# : Input {{{ + +[input] +border = { fg = "blue" } +title = {} +value = {} +selected = { reversed = true } + +# : }}} + + +# : Confirm {{{ + +[confirm] +border = { fg = "blue" } +title = { fg = "blue" } +content = {} +list = {} +btn_yes = { reversed = true } +btn_no = {} +btn_labels = [ " [Y]es ", " (N)o " ] + +# : }}} + + +# : Completion {{{ + +[completion] +border = { fg = "blue" } +active = { reversed = true } +inactive = {} + +# Icons +icon_file = "" +icon_folder = "" +icon_command = "" + +# : }}} + + +# : Tasks {{{ + +[tasks] +border = { fg = "blue" } +title = {} +hovered = { fg = "magenta", underline = true } + +# : }}} + + +# : Which {{{ + +[which] +cols = 3 +mask = { bg = "black" } +cand = { fg = "lightcyan" } +rest = { fg = "darkgray" } +desc = { fg = "lightmagenta" } +separator = "  " +separator_style = { fg = "darkgray" } + +# : }}} + + +# : Help {{{ + +[help] +on = { fg = "cyan" } +run = { fg = "magenta" } +desc = {} +hovered = { reversed = true, bold = true } +footer = { fg = "black", bg = "white" } + +# : }}} + + +# : Notify {{{ + +[notify] +title_info = { fg = "green" } +title_warn = { fg = "yellow" } +title_error = { fg = "red" } + +# Icons +icon_info = "" +icon_warn = "" +icon_error = "" + +# : }}} + + +# : File-specific styles {{{ + +[filetype] + +rules = [ + # Images + { mime = "image/*", fg = "yellow" }, + + # Media + { mime = "{audio,video}/*", fg = "magenta" }, + + # Archives + { mime = "application/{,g}zip", fg = "red" }, + { mime = "application/{tar,bzip*,7z*,xz,rar}", fg = "red" }, + + # Documents + { mime = "application/{pdf,doc,rtf}", fg = "cyan" }, + + # Empty files + # { mime = "inode/empty", fg = "red" }, + + # Special files + { name = "*", is = "orphan", bg = "red" }, + { name = "*", is = "exec" , fg = "green" }, + + # Dummy files + { name = "*", is = "dummy", bg = "red" }, + { name = "*/", is = "dummy", bg = "red" }, + + # Fallback + # { name = "*", fg = "white" }, + { name = "*/", fg = "blue" } +] + +# : }}} + + # : Icons {{{ [icon] diff --git a/yazi-config/preset/theme+light.toml b/yazi-config/preset/theme-light.toml similarity index 88% rename from yazi-config/preset/theme+light.toml rename to yazi-config/preset/theme-light.toml index 9205532d..abe33d57 100644 --- a/yazi-config/preset/theme+light.toml +++ b/yazi-config/preset/theme-light.toml @@ -1,10 +1,236 @@ -# If the user's terminal is in dark mode, Yazi will use the content from `theme-base.toml` + `theme+dark.toml` as the default theme; -# if it's in light mode, use `theme-base.toml` + `theme+light.toml` instead. -# Users can always override and adjust the default theme in their own `theme.toml` configuration file. +# If the user's terminal is in dark mode, Yazi will load `theme-dark.toml` on startup; otherwise, `theme-light.toml`. +# You can override any parts of them that are not related to the dark/light mode in your own `theme.toml`. + +# If you want to dynamically override their content based on dark/light mode, you can specify two different flavors +# for dark and light modes under `[flavor]`, and do so in those flavors instead. "$schema" = "https://yazi-rs.github.io/schemas/theme.json" # vim:fileencoding=utf-8:foldmethod=marker +# : Flavor {{{ + +[flavor] +dark = "" +light = "" + +# : }}} + +# : Manager {{{ + +[manager] +cwd = { fg = "cyan" } + +# Hovered +hovered = { reversed = true } +preview_hovered = { underline = true } + +# Find +find_keyword = { fg = "yellow", bold = true, italic = true, underline = true } +find_position = { fg = "magenta", bg = "reset", bold = true, italic = true } + +# Marker +marker_copied = { fg = "lightgreen", bg = "lightgreen" } +marker_cut = { fg = "lightred", bg = "lightred" } +marker_marked = { fg = "lightcyan", bg = "lightcyan" } +marker_selected = { fg = "lightyellow", bg = "lightyellow" } + +# Tab +tab_active = { reversed = true } +tab_inactive = {} +tab_width = 1 + +# Count +count_copied = { fg = "white", bg = "green" } +count_cut = { fg = "white", bg = "red" } +count_selected = { fg = "white", bg = "yellow" } + +# Border +border_symbol = "│" +border_style = { fg = "gray" } + +# Highlighting +syntect_theme = "" + +# : }}} + + +# : Mode {{{ + +[mode] + +normal_main = { bg = "blue", bold = true } +normal_alt = { fg = "blue", bg = "gray" } + +# Select mode +select_main = { bg = "red", bold = true } +select_alt = { fg = "red", bg = "gray" } + +# Unset mode +unset_main = { bg = "red", bold = true } +unset_alt = { fg = "red", bg = "gray" } + +# : }}} + + +# : Status bar {{{ + +[status] +separator_open = "" +separator_close = "" + +# Progress +progress_label = { bold = true } +progress_normal = { fg = "blue", bg = "black" } +progress_error = { fg = "red", bg = "black" } + +# Permissions +perm_sep = { fg = "darkgray" } +perm_type = { fg = "green" } +perm_read = { fg = "yellow" } +perm_write = { fg = "red" } +perm_exec = { fg = "cyan" } + +# : }}} + + +# : Pick {{{ + +[pick] +border = { fg = "blue" } +active = { fg = "magenta", bold = true } +inactive = {} + +# : }}} + + +# : Input {{{ + +[input] +border = { fg = "blue" } +title = {} +value = {} +selected = { reversed = true } + +# : }}} + + +# : Confirm {{{ + +[confirm] +border = { fg = "blue" } +title = { fg = "blue" } +content = {} +list = {} +btn_yes = { reversed = true } +btn_no = {} +btn_labels = [ " [Y]es ", " (N)o " ] + +# : }}} + + +# : Completion {{{ + +[completion] +border = { fg = "blue" } +active = { reversed = true } +inactive = {} + +# Icons +icon_file = "" +icon_folder = "" +icon_command = "" + +# : }}} + + +# : Tasks {{{ + +[tasks] +border = { fg = "blue" } +title = {} +hovered = { fg = "magenta", underline = true } + +# : }}} + + +# : Which {{{ + +[which] +cols = 3 +mask = { bg = "black" } +cand = { fg = "lightcyan" } +rest = { fg = "darkgray" } +desc = { fg = "lightmagenta" } +separator = "  " +separator_style = { fg = "darkgray" } + +# : }}} + + +# : Help {{{ + +[help] +on = { fg = "cyan" } +run = { fg = "magenta" } +desc = {} +hovered = { reversed = true, bold = true } +footer = { fg = "black", bg = "white" } + +# : }}} + + +# : Notify {{{ + +[notify] +title_info = { fg = "green" } +title_warn = { fg = "yellow" } +title_error = { fg = "red" } + +# Icons +icon_info = "" +icon_warn = "" +icon_error = "" + +# : }}} + + +# : File-specific styles {{{ + +[filetype] + +rules = [ + # Images + { mime = "image/*", fg = "yellow" }, + + # Media + { mime = "{audio,video}/*", fg = "magenta" }, + + # Archives + { mime = "application/{,g}zip", fg = "red" }, + { mime = "application/{tar,bzip*,7z*,xz,rar}", fg = "red" }, + + # Documents + { mime = "application/{pdf,doc,rtf}", fg = "cyan" }, + + # Empty files + # { mime = "inode/empty", fg = "red" }, + + # Special files + { name = "*", is = "orphan", bg = "red" }, + { name = "*", is = "exec" , fg = "green" }, + + # Dummy files + { name = "*", is = "dummy", bg = "red" }, + { name = "*/", is = "dummy", bg = "red" }, + + # Fallback + # { name = "*", fg = "white" }, + { name = "*/", fg = "blue" } +] + +# : }}} + + # : Icons {{{ [icon] diff --git a/yazi-config/preset/yazi.toml b/yazi-config/preset/yazi.toml index 2c282748..52cd6e34 100644 --- a/yazi-config/preset/yazi.toml +++ b/yazi-config/preset/yazi.toml @@ -68,7 +68,7 @@ rules = [ { mime = "{audio,video}/*", use = [ "play", "reveal" ] }, # Archive { mime = "application/{,g}zip", use = [ "extract", "reveal" ] }, - { mime = "application/{tar,bzip*,7z-compressed,xz,rar}", use = [ "extract", "reveal" ] }, + { mime = "application/{tar,bzip*,7z*,xz,rar}", use = [ "extract", "reveal" ] }, # JSON { mime = "application/{json,ndjson}", use = [ "edit", "reveal" ] }, { mime = "*/javascript", use = [ "edit", "reveal" ] }, @@ -115,7 +115,7 @@ preloaders = [ { mime = "application/pdf", run = "pdf" }, # Font { mime = "font/*", run = "font" }, - { mime = "application/vnd.ms-opentype", run = "font" }, + { mime = "application/ms-opentype", run = "font" }, ] previewers = [ { name = "*/", run = "folder", sync = true }, @@ -133,10 +133,10 @@ previewers = [ { mime = "application/pdf", run = "pdf" }, # Archive { mime = "application/{,g}zip", run = "archive" }, - { mime = "application/{tar,bzip*,7z-compressed,xz,rar,iso9660-image}", run = "archive" }, + { mime = "application/{tar,bzip*,7z*,xz,rar,iso9660-image}", run = "archive" }, # Font { mime = "font/*", run = "font" }, - { mime = "application/vnd.ms-opentype", run = "font" }, + { mime = "application/ms-opentype", run = "font" }, # Empty file { mime = "inode/empty", run = "empty" }, # Fallback diff --git a/yazi-macro/src/asset.rs b/yazi-macro/src/asset.rs index b08a60e2..6d5e1f7d 100644 --- a/yazi-macro/src/asset.rs +++ b/yazi-macro/src/asset.rs @@ -43,22 +43,24 @@ macro_rules! theme_preset { ($name:literal) => {{ #[cfg(debug_assertions)] { - let append = std::fs::read_to_string(concat!( - env!("CARGO_MANIFEST_DIR"), - "/preset/theme+", - $name, - ".toml" - )) - .expect(concat!("Failed to read 'yazi-config/preset/theme+", $name, ".toml'")); - std::borrow::Cow::from(format!("{}\n{append}", &$crate::config_preset!("theme-base"))) + std::borrow::Cow::from( + std::fs::read_to_string(concat!( + env!("CARGO_MANIFEST_DIR"), + "/preset/theme-", + $name, + ".toml" + )) + .expect(concat!("Failed to read 'yazi-config/preset/theme-", $name, ".toml'")), + ) } #[cfg(not(debug_assertions))] { - std::borrow::Cow::from(concat!( - include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/preset/theme-base.toml")), - "\n", - include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/preset/theme+", $name, ".toml")) - )) + std::borrow::Cow::from(include_str!(concat!( + env!("CARGO_MANIFEST_DIR"), + "/preset/theme-", + $name, + ".toml" + ))) } }}; } diff --git a/yazi-plugin/preset/plugins/mime.lua b/yazi-plugin/preset/plugins/mime.lua index 3e1f6a6d..43ebc92e 100644 --- a/yazi-plugin/preset/plugins/mime.lua +++ b/yazi-plugin/preset/plugins/mime.lua @@ -5,7 +5,7 @@ local M = {} local function match_mimetype(s) local type, sub = s:match("^([-a-z]+/)([+-.a-zA-Z0-9]+)%s*$") if type and sub and SUPPORTED_TYPES:find(type, 1, true) then - return type:gsub("^x%-", "", 1) .. sub:gsub("^x%-", "", 1) + return type:gsub("^x%-", "", 1) .. sub:gsub("^x%-", "", 1):gsub("^vnd%.", "", 1) end end