From e5f00e2716fd177b0ca0d313f1a6e64f01c12760 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Wed, 2 Jul 2025 23:35:50 +0800 Subject: [PATCH] feat: adapt for https://github.com/sxyazi/yazi/pull/2939 --- git.yazi/main.lua | 14 ++++- mactag.yazi/main.lua | 7 ++- mount.yazi/main.lua | 21 ++++++- sudo-demo.yazi/main.lua | 2 +- types.yazi/main.lua | 125 ++++++++++++++++++++++------------------ 5 files changed, 105 insertions(+), 64 deletions(-) diff --git a/git.yazi/main.lua b/git.yazi/main.lua index 140ad5a..aa402e5 100644 --- a/git.yazi/main.lua +++ b/git.yazi/main.lua @@ -108,7 +108,12 @@ local add = ya.sync(function(st, cwd, repo, changed) st.repos[repo][path] = code end end - ya.render() + -- TODO: remove this + if ui.render then + ui.render() + else + ya.render() + end end) local remove = ya.sync(function(st, cwd) @@ -117,7 +122,12 @@ local remove = ya.sync(function(st, cwd) return end - ya.render() + -- TODO: remove this + if ui.render then + ui.render() + else + ya.render() + end st.dirs[cwd] = nil if not st.repos[repo] then return diff --git a/mactag.yazi/main.lua b/mactag.yazi/main.lua index 3d1a305..309a46a 100644 --- a/mactag.yazi/main.lua +++ b/mactag.yazi/main.lua @@ -4,7 +4,12 @@ local update = ya.sync(function(st, tags) for path, tag in pairs(tags) do st.tags[path] = #tag > 0 and tag or nil end - ya.render() + -- TODO: remove this + if ui.render then + ui.render() + else + ya.render() + end end) local selected_or_hovered = ya.sync(function() diff --git a/mount.yazi/main.lua b/mount.yazi/main.lua index 32dc15e..352a2d6 100644 --- a/mount.yazi/main.lua +++ b/mount.yazi/main.lua @@ -7,7 +7,12 @@ local toggle_ui = ya.sync(function(self) else self.children = Modal:children_add(self, 10) end - ya.render() + -- TODO: remove this + if ui.render then + ui.render() + else + ya.render() + end end) local subscribe = ya.sync(function(self) @@ -18,7 +23,12 @@ end) local update_partitions = ya.sync(function(self, partitions) self.partitions = partitions self.cursor = math.max(0, math.min(self.cursor or 0, #self.partitions - 1)) - ya.render() + -- TODO: remove this + if ui.render then + ui.render() + else + ya.render() + end end) local active_partition = ya.sync(function(self) return self.partitions[self.cursor + 1] end) @@ -29,7 +39,12 @@ local update_cursor = ya.sync(function(self, cursor) else self.cursor = ya.clamp(0, self.cursor + cursor, #self.partitions - 1) end - ya.render() + -- TODO: remove this + if ui.render then + ui.render() + else + ya.render() + end end) local M = { diff --git a/sudo-demo.yazi/main.lua b/sudo-demo.yazi/main.lua index bd92edc..599afe4 100644 --- a/sudo-demo.yazi/main.lua +++ b/sudo-demo.yazi/main.lua @@ -21,7 +21,7 @@ local function run_with_sudo(program, args) return cmd:output() end - local permit = ya.hide() + local permit = ui.hide and ui.hide() or ya.hide() -- TODO: remove this print(string.format("Sudo password required to run: `%s %s`", program, table.concat(args))) local output = cmd:output() permit:drop() diff --git a/types.yazi/main.lua b/types.yazi/main.lua index 3ef0667..e984642 100644 --- a/types.yazi/main.lua +++ b/types.yazi/main.lua @@ -1,11 +1,7 @@ -- luacheck: globals Command Url cx fs ps rt th ui ya ----@alias Color string|"reset"|"black"|"white"|"red"|"lightred"|"green"|"lightgreen"|"yellow"|"lightyellow"|"blue"|"lightblue"|"magenta"|"lightmagenta"|"cyan"|"lightcyan"|"gray"|"darkgray" ---@alias Stdio integer ----@alias Sendable nil|boolean|number|string|Url|{ [Sendable]: Sendable } ----@alias Renderable ui.Bar|ui.Border|ui.Clear|ui.Gauge|ui.Line|ui.List|ui.Text - ---@class (exact) Recv ---@field recv fun(self: self): string @@ -28,6 +24,21 @@ ui = ui ---@type ya ya = ya +-- A set of constants representing the origin of a position. +-- | | | +-- | ----- | ---------------------------------------------------------------------------------------------------------------------------------------- | +-- | Alias | `"top-left"` \| `"top-center"` \| `"top-right"` \| `"bottom-left"` \| `"bottom-center"` \| `"bottom-right"` \| `"center"` \| `"hovered"` | +---@alias Origin "top-left"|"top-center"|"top-right"|"bottom-left"|"bottom-center"|"bottom-right"|"center"|"hovered" +-- A value that can be sent across threads. See [Sendable value](/docs/plugins/overview#sendable) for more details. +-- | | | +-- | ----- | --------------------------------------------------------------------------------- | +-- | Alias | `nil` \| `boolean` \| `number` \| `string` \| `Url` \| `{ [Sendable]: Sendable }` | +---@alias Sendable nil|boolean|number|string|Url|{ [Sendable]: Sendable } +-- An element that can be rendered. +-- | | | +-- | ----- | --------------------------------------------------------------------- | +-- | Alias | `Bar` \| `Border` \| `Clear` \| `Gauge` \| `Line` \| `List` \| `Text` | +---@alias Renderable ui.Bar|ui.Border|ui.Clear|ui.Gauge|ui.Line|ui.List|ui.Text -- A value that can be covariantly treated as a [`Pos`](/docs/plugins/layout#pos). -- | | | -- | ----- | ------------------------------------------------------------------------------ | @@ -48,11 +59,11 @@ ya = ya -- | ----- | -------------------------------------------------------- | -- | Alias | `string` \| `Span` \| `Line` \| `(string\|Span\|Line)[]` | ---@alias AsText string|ui.Span|ui.Line|(string|ui.Span|ui.Line)[] --- Origin is a set of constants representing the origin of a position. --- | | | --- | ----- | ---------------------------------------------------------------------------------------------------------------------------------------- | --- | Alias | `"top-left"` \| `"top-center"` \| `"top-right"` \| `"bottom-left"` \| `"bottom-center"` \| `"bottom-right"` \| `"center"` \| `"hovered"` | ----@alias Origin "top-left"|"top-center"|"top-right"|"bottom-left"|"bottom-center"|"bottom-right"|"center"|"hovered" +-- A set of constants representing colors. +-- | | | +-- | ----- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +-- | Alias | `"black"` \| `"white"` \| `"red"` \| `"lightred"` \| `"green"` \| `"lightgreen"` \| `"yellow"` \| `"lightyellow"` \| `"blue"` \| `"lightblue"` \| `"magenta"` \| `"lightmagenta"` \| `"cyan"` \| `"lightcyan"` \| `"gray"` \| `"darkgray"` \| `"reset"` \| `string` | +---@alias AsColor "black"|"white"|"red"|"lightred"|"green"|"lightgreen"|"yellow"|"lightyellow"|"blue"|"lightblue"|"magenta"|"lightmagenta"|"cyan"|"lightcyan"|"gray"|"darkgray"|"reset"|string -- Create a Url: -- ```lua @@ -526,19 +537,19 @@ ya = ya -- ``` ---@class (exact) ui.Style -- Apply a foreground color. --- | In/Out | Type | --- | ------- | ------------------------------------------------ | --- | `self` | `Self` | --- | `color` | [`Color`](/docs/configuration/theme#types.color) | --- | Return | `self` | ----@field fg fun(self: self, color: Color): self +-- | In/Out | Type | +-- | ------- | ------------------------------------------- | +-- | `self` | `Self` | +-- | `color` | [`AsColor`](/docs/plugins/aliases#as-color) | +-- | Return | `self` | +---@field fg fun(self: self, color: AsColor): self -- Apply a background color. --- | In/Out | Type | --- | ------- | ------------------------------------------------ | --- | `self` | `Self` | --- | `color` | [`Color`](/docs/configuration/theme#types.color) | --- | Return | `self` | ----@field bg fun(self: self, color: Color): self +-- | In/Out | Type | +-- | ------- | ------------------------------------------- | +-- | `self` | `Self` | +-- | `color` | [`AsColor`](/docs/plugins/aliases#as-color) | +-- | Return | `self` | +---@field bg fun(self: self, color: AsColor): self -- Apply a bold style. -- | In/Out | Type | -- | ------ | ------ | @@ -650,19 +661,19 @@ ya = ya -- ``` ---@field style fun(self: self, style: ui.Style): self -- Apply a foreground color. --- | In/Out | Type | --- | ------- | ------------------------------------------------ | --- | `self` | `Self` | --- | `color` | [`Color`](/docs/configuration/theme#types.color) | --- | Return | `self` | ----@field fg fun(self: self, color: Color): self +-- | In/Out | Type | +-- | ------- | ------------------------------------------- | +-- | `self` | `Self` | +-- | `color` | [`AsColor`](/docs/plugins/aliases#as-color) | +-- | Return | `self` | +---@field fg fun(self: self, color: AsColor): self -- Apply a background color. --- | In/Out | Type | --- | ------- | ------------------------------------------------ | --- | `self` | `Self` | --- | `color` | [`Color`](/docs/configuration/theme#types.color) | --- | Return | `self` | ----@field bg fun(self: self, color: Color): self +-- | In/Out | Type | +-- | ------- | ------------------------------------------- | +-- | `self` | `Self` | +-- | `color` | [`AsColor`](/docs/plugins/aliases#as-color) | +-- | Return | `self` | +---@field bg fun(self: self, color: AsColor): self -- Apply a bold style. -- | In/Out | Type | -- | ------ | ------ | @@ -790,19 +801,19 @@ ya = ya -- ``` ---@field style fun(self: self, style: ui.Style): self -- Apply a foreground color. --- | In/Out | Type | --- | ------- | ------------------------------------------------ | --- | `self` | `Self` | --- | `color` | [`Color`](/docs/configuration/theme#types.color) | --- | Return | `self` | ----@field fg fun(self: self, color: Color): self +-- | In/Out | Type | +-- | ------- | ------------------------------------------- | +-- | `self` | `Self` | +-- | `color` | [`AsColor`](/docs/plugins/aliases#as-color) | +-- | Return | `self` | +---@field fg fun(self: self, color: AsColor): self -- Apply a background color. --- | In/Out | Type | --- | ------- | ------------------------------------------------ | --- | `self` | `Self` | --- | `color` | [`Color`](/docs/configuration/theme#types.color) | --- | Return | `self` | ----@field bg fun(self: self, color: Color): self +-- | In/Out | Type | +-- | ------- | ------------------------------------------- | +-- | `self` | `Self` | +-- | `color` | [`AsColor`](/docs/plugins/aliases#as-color) | +-- | Return | `self` | +---@field bg fun(self: self, color: AsColor): self -- Apply a bold style. -- | In/Out | Type | -- | ------ | ------ | @@ -932,19 +943,19 @@ ya = ya -- ``` ---@field style fun(self: self, style: ui.Style): self -- Apply a foreground color. --- | In/Out | Type | --- | ------- | ------------------------------------------------ | --- | `self` | `Self` | --- | `color` | [`Color`](/docs/configuration/theme#types.color) | --- | Return | `self` | ----@field fg fun(self: self, color: Color): self +-- | In/Out | Type | +-- | ------- | ------------------------------------------- | +-- | `self` | `Self` | +-- | `color` | [`AsColor`](/docs/plugins/aliases#as-color) | +-- | Return | `self` | +---@field fg fun(self: self, color: AsColor): self -- Apply a background color. --- | In/Out | Type | --- | ------- | ------------------------------------------------ | --- | `self` | `Self` | --- | `color` | [`Color`](/docs/configuration/theme#types.color) | --- | Return | `self` | ----@field bg fun(self: self, color: Color): self +-- | In/Out | Type | +-- | ------- | ------------------------------------------- | +-- | `self` | `Self` | +-- | `color` | [`AsColor`](/docs/plugins/aliases#as-color) | +-- | Return | `self` | +---@field bg fun(self: self, color: AsColor): self -- Apply a bold style. -- | In/Out | Type | -- | ------ | ------ |