Skip to content

Commit

Permalink
refactor: rename module name (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
linrongbin16 authored Feb 29, 2024
1 parent ce0cd6d commit 975a92f
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 49 deletions.
8 changes: 4 additions & 4 deletions lua/colorbox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ local strings = require("colorbox.commons.strings")

local configs = require("colorbox.configs")
local timing = require("colorbox.timing")
local util = require("colorbox.util")
local colors = require("colorbox.colors")
local track = require("colorbox.track")
local runtime = require("colorbox.runtime")
local controller = require("colorbox.controller")

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

colors.setup()
runtime.setup()

vim.api.nvim_create_user_command(confs.command.name, function(command_opts)
local logger = logging.get("colorbox") --[[@as commons.logging.Logger]]
Expand Down Expand Up @@ -108,7 +108,7 @@ local function setup(opts)
vim.api.nvim_create_autocmd("ColorScheme", {
callback = function()
vim.schedule(function()
util.save_track(vim.g.colors_name)
track.save_track(vim.g.colors_name)
end)
end,
})
Expand Down
4 changes: 2 additions & 2 deletions lua/colorbox/controller.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ local strings = require("colorbox.commons.strings")
local apis = require("colorbox.commons.apis")
local async = require("colorbox.commons.async")

local colors = require("colorbox.colors")
local runtime = require("colorbox.runtime")

local M = {}

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

local ColorNamesIndex = colors.colornames_index()
local ColorNamesIndex = runtime.colornames_index()
local HandleToColorSpecsMap = require("colorbox.db").get_handle_to_color_specs_map()
local color_specs_list = {}
for handle, spec in pairs(HandleToColorSpecsMap) do
Expand Down
26 changes: 13 additions & 13 deletions lua/colorbox/policy/builtin.lua
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
local logging = require("colorbox.commons.logging")
local numbers = require("colorbox.commons.numbers")

local colors = require("colorbox.colors")
local util = require("colorbox.util")
local runtime = require("colorbox.runtime")
local track = require("colorbox.track")

local M = {}

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

M.in_order = function()
local ColorNamesList = colors.colornames()
local ColorNamesList = runtime.colornames()
if #ColorNamesList > 0 then
local previous_track = util.previous_track() --[[@as colorbox.PreviousTrack]]
local previous_track = track.previous_track() --[[@as colorbox.PreviousTrack]]
local i = previous_track ~= nil and previous_track.color_number or 0
local color = util.get_next_color_name_by_idx(i)
local color = track.get_next_color_name_by_idx(i)
vim.cmd(string.format([[color %s]], color))
end
end

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

M.single = function()
local ColorNamesList = colors.colornames()
local ColorNamesList = runtime.colornames()
if #ColorNamesList > 0 then
local previous_track = util.previous_track() --[[@as colorbox.PreviousTrack]]
local previous_track = track.previous_track() --[[@as colorbox.PreviousTrack]]
local color = previous_track ~= nil and previous_track.color_name
or util.get_next_color_name_by_idx(0)
or track.get_next_color_name_by_idx(0)
if color ~= vim.g.colors_name then
vim.cmd(string.format([[color %s]], color))
end
Expand Down
8 changes: 4 additions & 4 deletions lua/colorbox/policy/filetype.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local strings = require("colorbox.commons.strings")

local configs = require("colorbox.configs")
local util = require("colorbox.util")
local track = require("colorbox.track")

local M = {}

Expand Down Expand Up @@ -29,17 +29,17 @@ M.run = function()
local ok, err =
pcall(vim.cmd --[[@as function]], string.format([[color %s]], confs.policy.mapping[ft]))
assert(ok, err)
util.sync_syntax()
track.sync_syntax()
elseif strings.empty(ft) and strings.not_empty(confs.policy.empty) then
local ok, err =
pcall(vim.cmd --[[@as function]], string.format([[color %s]], confs.policy.empty))
assert(ok, err)
util.sync_syntax()
track.sync_syntax()
elseif strings.not_empty(confs.policy.fallback) then
local ok, err =
pcall(vim.cmd --[[@as function]], string.format([[color %s]], confs.policy.fallback))
assert(ok, err)
util.sync_syntax()
track.sync_syntax()
end
end, 10)
end
Expand Down
4 changes: 2 additions & 2 deletions lua/colorbox/policy/fixed_interval.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ local tables = require("colorbox.commons.tables")

local configs = require("colorbox.configs")
local builtin_policy = require("colorbox.policy.builtin")
local util = require("colorbox.util")
local track = require("colorbox.track")

local M = {}

Expand Down Expand Up @@ -36,7 +36,7 @@ M.run = function()

local function impl()
fn()
util.sync_syntax()
track.sync_syntax()
vim.defer_fn(impl, later)
end
impl()
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions lua/colorbox/util.lua → lua/colorbox/track.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ local fileios = require("colorbox.commons.fileios")
local strings = require("colorbox.commons.strings")

local configs = require("colorbox.configs")
local colors = require("colorbox.colors")
local runtime = require("colorbox.runtime")

local M = {}

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

local ColorNamesIndex = colors.colornames_index()
local ColorNamesIndex = runtime.colornames_index()
local color_number = ColorNamesIndex[color_name] or 1

local content = jsons.encode({
Expand All @@ -51,7 +51,7 @@ end
M.get_next_color_name_by_idx = function(idx)
assert(type(idx) == "number")
idx = idx + 1
local ColorNamesList = colors.colornames()
local ColorNamesList = runtime.colornames()
local n = #ColorNamesList
if idx > n then
idx = 1
Expand All @@ -65,7 +65,7 @@ end
M.get_prev_color_name_by_idx = function(idx)
assert(type(idx) == "number")
idx = idx - 1
local ColorNamesList = colors.colornames()
local ColorNamesList = runtime.colornames()
local n = #ColorNamesList
if idx < 1 then
idx = n
Expand Down
1 change: 0 additions & 1 deletion spec/colorbox/controller_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ describe("colorbox.controller", function()

local strings = require("colorbox.commons.strings")
local tables = require("colorbox.commons.tables")
local colors = require("colorbox.colors")
local controller = require("colorbox.controller")
require("colorbox").setup({
debug = true,
Expand Down
13 changes: 6 additions & 7 deletions spec/colorbox/colors_spec.lua → spec/colorbox/runtime_spec.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local cwd = vim.fn.getcwd()

describe("colorbox.colors", function()
describe("colorbox.runtime", function()
local assert_eq = assert.is_equal
local assert_true = assert.is_true
local assert_false = assert.is_false
Expand All @@ -9,17 +9,16 @@ describe("colorbox.colors", function()
vim.api.nvim_command("cd " .. cwd)
end)

local strings = require("colorbox.commons.strings")
local tables = require("colorbox.commons.tables")
local colors = require("colorbox.colors")
local runtime = require("colorbox.runtime")
require("colorbox").setup({
debug = true,
file_log = true,
})

describe("[_build_colors]", function()
it("test", function()
local actual = colors._build_colors()
local actual = runtime._build_colors()
print(string.format("_build_colors:%s\n", vim.inspect(actual)))
assert_eq(type(tables.tbl_get(actual, "colors_list")), "table")
assert_eq(type(tables.tbl_get(actual, "colors_index")), "table")
Expand All @@ -28,14 +27,14 @@ describe("colorbox.colors", function()
end
end)
it("colornames/colornames_index", function()
local colornames = colors.colornames()
local colornames_index = colors.colornames_index()
local colornames = runtime.colornames()
local colornames_index = runtime.colornames_index()
for i, color in ipairs(colornames) do
assert_eq(colornames_index[color], i)
end
end)
it("setup", function()
colors.setup()
runtime.setup()
end)
end)
end)
23 changes: 11 additions & 12 deletions spec/colorbox/util_spec.lua → spec/colorbox/track_spec.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local cwd = vim.fn.getcwd()

describe("colorbox.util", function()
describe("colorbox.track", function()
local assert_eq = assert.is_equal
local assert_true = assert.is_true
local assert_false = assert.is_false
Expand All @@ -9,39 +9,38 @@ describe("colorbox.util", function()
vim.api.nvim_command("cd " .. cwd)
end)

local db = require("colorbox.db")
local util = require("colorbox.util")
local colors = require("colorbox.colors")
local track = require("colorbox.track")
local runtime = require("colorbox.runtime")
require("colorbox").setup({
debug = true,
file_log = true,
})

describe("[sync_syntax]", function()
it("test", function()
util.sync_syntax()
track.sync_syntax()
end)
end)
describe("[track]", function()
it("save_track", function()
local ColorNamesList = colors.colornames()
local ColorNamesList = runtime.colornames()
for i, color in ipairs(ColorNamesList) do
util.save_track(color)
track.save_track(color)
end
end)
it("previous_track", function()
local track = util.previous_track()
local track = track.previous_track()
if track then
assert_eq(type(track), "table")
assert_true(string.len(track.color_name) > 0)
assert_true(track.color_number > 0)
end
end)
it("next", function()
local ColorNamesList = colors.colornames()
local ColorNamesList = runtime.colornames()
local n = #ColorNamesList
for i = 1, 2 * n do
local actual, actual_idx = util.get_next_color_name_by_idx(i)
local actual, actual_idx = track.get_next_color_name_by_idx(i)
print(
string.format(
"get_next_color_name_by_idx(%s): %s, %s\n",
Expand All @@ -61,10 +60,10 @@ describe("colorbox.util", function()
end
end)
it("prev", function()
local ColorNamesList = colors.colornames()
local ColorNamesList = runtime.colornames()
local n = #ColorNamesList
for i = 0, 2 * n do
local actual, actual_idx = util.get_prev_color_name_by_idx(i)
local actual, actual_idx = track.get_prev_color_name_by_idx(i)
print(
string.format(
"get_next_color_name_by_idx(%s): %s, %s\n",
Expand Down

0 comments on commit 975a92f

Please sign in to comment.