Skip to content

Commit 3ad6453

Browse files
authored
feat: Add shuffle command to change color randomly (#239)
1 parent 62fd4b6 commit 3ad6453

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ You can also use command `Colorbox` to control the player with below subcommands
170170
- `update`: Update all git submodules.
171171
- `info`: Show detailed information and configured status.
172172
- **Note:** use `scale=0.7` to specify popup window's size in range `(0, 1]`, by default is `scale=0.7`.
173+
- `shuffle`: Change to a random color.
173174

174175
> [!NOTE]
175176
>

lua/colorbox/controller.lua

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ local logging = require("colorbox.commons.logging")
44
local LogLevels = require("colorbox.commons.logging").LogLevels
55
local uv = require("colorbox.commons.uv")
66
local async = require("colorbox.commons.async")
7+
local track = require("colorbox.track")
8+
local loader = require("colorbox.loader")
79

810
local runtime = require("colorbox.runtime")
911
local db = require("colorbox.db")
@@ -138,6 +140,26 @@ M._parse_args = function(args)
138140
return opts
139141
end
140142

143+
M.shuffle = function()
144+
local ColorNamesList = runtime.colornames()
145+
if #ColorNamesList > 0 then
146+
local logger = logging.get("colorbox")
147+
local random_index = num.random(1, #ColorNamesList)
148+
local color = ColorNamesList[random_index]
149+
150+
logger:debug(
151+
string.format(
152+
"|shuffle| color:%s, random_index:%d, ColorNamesList(%d):%s",
153+
vim.inspect(color),
154+
random_index,
155+
#ColorNamesList,
156+
vim.inspect(ColorNamesList)
157+
)
158+
)
159+
loader.load(color)
160+
end
161+
end
162+
141163
--- @param args string?
142164
M.info = function(args)
143165
local logger = logging.get("colorbox")

spec/colorbox/controller_spec.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,10 @@ describe("colorbox.controller", function()
5353
controller.info("")
5454
end
5555
end)
56+
it("shuffle", function()
57+
if not github_actions then
58+
controller.shuffle()
59+
end
60+
end)
5661
end)
5762
end)

0 commit comments

Comments
 (0)