Skip to content

Commit 975a92f

Browse files
authored
refactor: rename module name (#201)
1 parent ce0cd6d commit 975a92f

File tree

10 files changed

+46
-49
lines changed

10 files changed

+46
-49
lines changed

lua/colorbox.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ local strings = require("colorbox.commons.strings")
44

55
local configs = require("colorbox.configs")
66
local timing = require("colorbox.timing")
7-
local util = require("colorbox.util")
8-
local colors = require("colorbox.colors")
7+
local track = require("colorbox.track")
8+
local runtime = require("colorbox.runtime")
99
local controller = require("colorbox.controller")
1010

1111
--- @param opts colorbox.Options?
@@ -32,7 +32,7 @@ local function setup(opts)
3232
confs.previous_colors_cache = string.format("%s/previous_colors_cache", confs.cache_dir)
3333
confs = configs.set(confs)
3434

35-
colors.setup()
35+
runtime.setup()
3636

3737
vim.api.nvim_create_user_command(confs.command.name, function(command_opts)
3838
local logger = logging.get("colorbox") --[[@as commons.logging.Logger]]
@@ -108,7 +108,7 @@ local function setup(opts)
108108
vim.api.nvim_create_autocmd("ColorScheme", {
109109
callback = function()
110110
vim.schedule(function()
111-
util.save_track(vim.g.colors_name)
111+
track.save_track(vim.g.colors_name)
112112
end)
113113
end,
114114
})

lua/colorbox/controller.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ local strings = require("colorbox.commons.strings")
66
local apis = require("colorbox.commons.apis")
77
local async = require("colorbox.commons.async")
88

9-
local colors = require("colorbox.colors")
9+
local runtime = require("colorbox.runtime")
1010

1111
local M = {}
1212

@@ -219,7 +219,7 @@ M.info = function(args)
219219
vim.keymap.set({ "n" }, "q", ":\\<C-U>quit<CR>", { silent = true, buffer = bufnr })
220220
local winnr = vim.api.nvim_open_win(bufnr, true, win_config)
221221

222-
local ColorNamesIndex = colors.colornames_index()
222+
local ColorNamesIndex = runtime.colornames_index()
223223
local HandleToColorSpecsMap = require("colorbox.db").get_handle_to_color_specs_map()
224224
local color_specs_list = {}
225225
for handle, spec in pairs(HandleToColorSpecsMap) do

lua/colorbox/policy/builtin.lua

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
local logging = require("colorbox.commons.logging")
22
local numbers = require("colorbox.commons.numbers")
33

4-
local colors = require("colorbox.colors")
5-
local util = require("colorbox.util")
4+
local runtime = require("colorbox.runtime")
5+
local track = require("colorbox.track")
66

77
local M = {}
88

99
M.shuffle = function()
10-
local ColorNamesList = colors.colornames()
10+
local ColorNamesList = runtime.colornames()
1111
if #ColorNamesList > 0 then
1212
local i = numbers.random(#ColorNamesList) --[[@as integer]]
13-
local color = util.get_next_color_name_by_idx(i)
13+
local color = track.get_next_color_name_by_idx(i)
1414
logging.get("colorbox"):debug(
1515
"|_policy_shuffle| color:%s, ColorNamesList:%s (%d), i:%d",
1616
vim.inspect(color),
@@ -23,31 +23,31 @@ M.shuffle = function()
2323
end
2424

2525
M.in_order = function()
26-
local ColorNamesList = colors.colornames()
26+
local ColorNamesList = runtime.colornames()
2727
if #ColorNamesList > 0 then
28-
local previous_track = util.previous_track() --[[@as colorbox.PreviousTrack]]
28+
local previous_track = track.previous_track() --[[@as colorbox.PreviousTrack]]
2929
local i = previous_track ~= nil and previous_track.color_number or 0
30-
local color = util.get_next_color_name_by_idx(i)
30+
local color = track.get_next_color_name_by_idx(i)
3131
vim.cmd(string.format([[color %s]], color))
3232
end
3333
end
3434

3535
M.reverse_order = function()
36-
local ColorNamesList = colors.colornames()
36+
local ColorNamesList = runtime.colornames()
3737
if #ColorNamesList > 0 then
38-
local previous_track = util.previous_track() --[[@as colorbox.PreviousTrack]]
38+
local previous_track = track.previous_track() --[[@as colorbox.PreviousTrack]]
3939
local i = previous_track ~= nil and previous_track.color_number or (#ColorNamesList + 1)
40-
local color = util.get_prev_color_name_by_idx(i)
40+
local color = track.get_prev_color_name_by_idx(i)
4141
vim.cmd(string.format([[color %s]], color))
4242
end
4343
end
4444

4545
M.single = function()
46-
local ColorNamesList = colors.colornames()
46+
local ColorNamesList = runtime.colornames()
4747
if #ColorNamesList > 0 then
48-
local previous_track = util.previous_track() --[[@as colorbox.PreviousTrack]]
48+
local previous_track = track.previous_track() --[[@as colorbox.PreviousTrack]]
4949
local color = previous_track ~= nil and previous_track.color_name
50-
or util.get_next_color_name_by_idx(0)
50+
or track.get_next_color_name_by_idx(0)
5151
if color ~= vim.g.colors_name then
5252
vim.cmd(string.format([[color %s]], color))
5353
end

lua/colorbox/policy/filetype.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
local strings = require("colorbox.commons.strings")
22

33
local configs = require("colorbox.configs")
4-
local util = require("colorbox.util")
4+
local track = require("colorbox.track")
55

66
local M = {}
77

@@ -29,17 +29,17 @@ M.run = function()
2929
local ok, err =
3030
pcall(vim.cmd --[[@as function]], string.format([[color %s]], confs.policy.mapping[ft]))
3131
assert(ok, err)
32-
util.sync_syntax()
32+
track.sync_syntax()
3333
elseif strings.empty(ft) and strings.not_empty(confs.policy.empty) then
3434
local ok, err =
3535
pcall(vim.cmd --[[@as function]], string.format([[color %s]], confs.policy.empty))
3636
assert(ok, err)
37-
util.sync_syntax()
37+
track.sync_syntax()
3838
elseif strings.not_empty(confs.policy.fallback) then
3939
local ok, err =
4040
pcall(vim.cmd --[[@as function]], string.format([[color %s]], confs.policy.fallback))
4141
assert(ok, err)
42-
util.sync_syntax()
42+
track.sync_syntax()
4343
end
4444
end, 10)
4545
end

lua/colorbox/policy/fixed_interval.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ local tables = require("colorbox.commons.tables")
55

66
local configs = require("colorbox.configs")
77
local builtin_policy = require("colorbox.policy.builtin")
8-
local util = require("colorbox.util")
8+
local track = require("colorbox.track")
99

1010
local M = {}
1111

@@ -36,7 +36,7 @@ M.run = function()
3636

3737
local function impl()
3838
fn()
39-
util.sync_syntax()
39+
track.sync_syntax()
4040
vim.defer_fn(impl, later)
4141
end
4242
impl()
File renamed without changes.

lua/colorbox/util.lua renamed to lua/colorbox/track.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local fileios = require("colorbox.commons.fileios")
44
local strings = require("colorbox.commons.strings")
55

66
local configs = require("colorbox.configs")
7-
local colors = require("colorbox.colors")
7+
local runtime = require("colorbox.runtime")
88

99
local M = {}
1010

@@ -24,7 +24,7 @@ M.save_track = function(color_name)
2424
vim.schedule(function()
2525
local confs = configs.get()
2626

27-
local ColorNamesIndex = colors.colornames_index()
27+
local ColorNamesIndex = runtime.colornames_index()
2828
local color_number = ColorNamesIndex[color_name] or 1
2929

3030
local content = jsons.encode({
@@ -51,7 +51,7 @@ end
5151
M.get_next_color_name_by_idx = function(idx)
5252
assert(type(idx) == "number")
5353
idx = idx + 1
54-
local ColorNamesList = colors.colornames()
54+
local ColorNamesList = runtime.colornames()
5555
local n = #ColorNamesList
5656
if idx > n then
5757
idx = 1
@@ -65,7 +65,7 @@ end
6565
M.get_prev_color_name_by_idx = function(idx)
6666
assert(type(idx) == "number")
6767
idx = idx - 1
68-
local ColorNamesList = colors.colornames()
68+
local ColorNamesList = runtime.colornames()
6969
local n = #ColorNamesList
7070
if idx < 1 then
7171
idx = n

spec/colorbox/controller_spec.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ describe("colorbox.controller", function()
1111

1212
local strings = require("colorbox.commons.strings")
1313
local tables = require("colorbox.commons.tables")
14-
local colors = require("colorbox.colors")
1514
local controller = require("colorbox.controller")
1615
require("colorbox").setup({
1716
debug = true,
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
local cwd = vim.fn.getcwd()
22

3-
describe("colorbox.colors", function()
3+
describe("colorbox.runtime", function()
44
local assert_eq = assert.is_equal
55
local assert_true = assert.is_true
66
local assert_false = assert.is_false
@@ -9,17 +9,16 @@ describe("colorbox.colors", function()
99
vim.api.nvim_command("cd " .. cwd)
1010
end)
1111

12-
local strings = require("colorbox.commons.strings")
1312
local tables = require("colorbox.commons.tables")
14-
local colors = require("colorbox.colors")
13+
local runtime = require("colorbox.runtime")
1514
require("colorbox").setup({
1615
debug = true,
1716
file_log = true,
1817
})
1918

2019
describe("[_build_colors]", function()
2120
it("test", function()
22-
local actual = colors._build_colors()
21+
local actual = runtime._build_colors()
2322
print(string.format("_build_colors:%s\n", vim.inspect(actual)))
2423
assert_eq(type(tables.tbl_get(actual, "colors_list")), "table")
2524
assert_eq(type(tables.tbl_get(actual, "colors_index")), "table")
@@ -28,14 +27,14 @@ describe("colorbox.colors", function()
2827
end
2928
end)
3029
it("colornames/colornames_index", function()
31-
local colornames = colors.colornames()
32-
local colornames_index = colors.colornames_index()
30+
local colornames = runtime.colornames()
31+
local colornames_index = runtime.colornames_index()
3332
for i, color in ipairs(colornames) do
3433
assert_eq(colornames_index[color], i)
3534
end
3635
end)
3736
it("setup", function()
38-
colors.setup()
37+
runtime.setup()
3938
end)
4039
end)
4140
end)

spec/colorbox/util_spec.lua renamed to spec/colorbox/track_spec.lua

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
local cwd = vim.fn.getcwd()
22

3-
describe("colorbox.util", function()
3+
describe("colorbox.track", function()
44
local assert_eq = assert.is_equal
55
local assert_true = assert.is_true
66
local assert_false = assert.is_false
@@ -9,39 +9,38 @@ describe("colorbox.util", function()
99
vim.api.nvim_command("cd " .. cwd)
1010
end)
1111

12-
local db = require("colorbox.db")
13-
local util = require("colorbox.util")
14-
local colors = require("colorbox.colors")
12+
local track = require("colorbox.track")
13+
local runtime = require("colorbox.runtime")
1514
require("colorbox").setup({
1615
debug = true,
1716
file_log = true,
1817
})
1918

2019
describe("[sync_syntax]", function()
2120
it("test", function()
22-
util.sync_syntax()
21+
track.sync_syntax()
2322
end)
2423
end)
2524
describe("[track]", function()
2625
it("save_track", function()
27-
local ColorNamesList = colors.colornames()
26+
local ColorNamesList = runtime.colornames()
2827
for i, color in ipairs(ColorNamesList) do
29-
util.save_track(color)
28+
track.save_track(color)
3029
end
3130
end)
3231
it("previous_track", function()
33-
local track = util.previous_track()
32+
local track = track.previous_track()
3433
if track then
3534
assert_eq(type(track), "table")
3635
assert_true(string.len(track.color_name) > 0)
3736
assert_true(track.color_number > 0)
3837
end
3938
end)
4039
it("next", function()
41-
local ColorNamesList = colors.colornames()
40+
local ColorNamesList = runtime.colornames()
4241
local n = #ColorNamesList
4342
for i = 1, 2 * n do
44-
local actual, actual_idx = util.get_next_color_name_by_idx(i)
43+
local actual, actual_idx = track.get_next_color_name_by_idx(i)
4544
print(
4645
string.format(
4746
"get_next_color_name_by_idx(%s): %s, %s\n",
@@ -61,10 +60,10 @@ describe("colorbox.util", function()
6160
end
6261
end)
6362
it("prev", function()
64-
local ColorNamesList = colors.colornames()
63+
local ColorNamesList = runtime.colornames()
6564
local n = #ColorNamesList
6665
for i = 0, 2 * n do
67-
local actual, actual_idx = util.get_prev_color_name_by_idx(i)
66+
local actual, actual_idx = track.get_prev_color_name_by_idx(i)
6867
print(
6968
string.format(
7069
"get_next_color_name_by_idx(%s): %s, %s\n",

0 commit comments

Comments
 (0)