This commit is contained in:
sxyazi
2025-07-02 23:35:50 +08:00
parent 2ad42fa706
commit e5f00e2716
5 changed files with 105 additions and 64 deletions

View File

@@ -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

View File

@@ -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()

View File

@@ -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 = {

View File

@@ -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()

View File

@@ -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 |
-- | ------ | ------ |