From 07b36c365d63707fd4080899bb4dc7c3ab7aae7f Mon Sep 17 00:00:00 2001 From: sxyazi Date: Wed, 14 Aug 2024 21:25:34 +0800 Subject: [PATCH] feat: allow changing the colors of the tags --- mactag.yazi/README.md | 15 ++++++++++++++- mactag.yazi/init.lua | 11 +++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/mactag.yazi/README.md b/mactag.yazi/README.md index d278c8c..5b10766 100644 --- a/mactag.yazi/README.md +++ b/mactag.yazi/README.md @@ -4,6 +4,8 @@ Bring macOS's awesome tagging feature to Yazi! The plugin it's only available fo Authors: [@AnirudhG07](https://github.com/AnirudhG07), and [@sxyazi](https://github.com/sxyazi) +Note that this plugin is still under development. + ## Installation Install the plugin itself, and [jdberry/tag](https://github.com/jdberry/tag) used to tag files: @@ -18,7 +20,18 @@ brew update && brew install tag Add the following to your `~/.config/yazi/init.lua`: ```lua -require("mactag"):setup() +require("mactag"):setup { + -- You can change the colors of the tags here + colors = { + Red = "#ee7b70", + Orange = "#f5bd5c", + Yellow = "#fbe764", + Green = "#91fc87", + Blue = "#5fa3f8", + Purple = "#cb88f8", + Gray = "#b5b5b9", + }, +} ``` And register it as fetchers in your `~/.config/yazi/yazi.toml`: diff --git a/mactag.yazi/init.lua b/mactag.yazi/init.lua index 1994fc0..69f7bb9 100644 --- a/mactag.yazi/init.lua +++ b/mactag.yazi/init.lua @@ -1,5 +1,3 @@ -local COLORS = { red = "red", yellow = "yellow", orange = "magenta", green = "green", blue = "blue" } - local update = ya.sync(function(st, tags) for path, tag in pairs(tags) do st.tags[path] = #tag == 0 and nil or tag @@ -18,14 +16,19 @@ local selected_or_hovered = ya.sync(function() return urls end) -local function setup(st) +local function setup(st, opts) st.tags = {} + st.colors = opts.colors Linemode:children_add(function(self) local url = tostring(self._file.url) local spans = {} for _, tag in ipairs(st.tags[url] or {}) do - spans[#spans + 1] = ui.Span("⬤"):fg(COLORS[tag:lower()] or "reset") + if self._file:is_hovered() then + spans[#spans + 1] = ui.Span("⬤"):bg(st.colors[tag] or "reset") + else + spans[#spans + 1] = ui.Span("⬤"):fg(st.colors[tag] or "reset") + end end return ui.Line(spans) end, 500)