Skip to content

Commit

Permalink
feat(controller): provide update option (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
linrongbin16 committed Nov 24, 2023
1 parent 8ac2ceb commit c6338ff
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ require('lazy').setup({
'linrongbin16/colorbox.nvim',
lazy = false, -- don't lazy this plugin if it provides the main colorscheme
priority = 1000, -- load this plugin before all other start plugins
build = function() require('colorbox').install() end,
build = function() require('colorbox').update() end,
config = function() require('colorbox').setup() end,
}
})
Expand All @@ -92,16 +92,16 @@ require('lazy').setup({
require('pckr').add({
{
'linrongbin16/colorbox.nvim',
run = function() require('colorbox').install() end,
run = function() require('colorbox').update() end,
config = function() require('colorbox').setup() end,
}
})
```

If you have issues on running multiple git clone/pull commands, try set `concurrency=1` in the `install` API:
If you have issues on running multiple git clone/pull commands, try set `concurrency=1` in the `update` API:

```lua
require('colorbox').install({
require('colorbox').update({
--- @type integer
concurrency = 4,
})
Expand All @@ -111,8 +111,8 @@ require('colorbox').install({

You can use command `Colorbox` to control the colorschemes player:

- `Colorbox reinstall`: clean & re-install git submodules.
- **Note:** use `Colorbox reinstall concurrency=1` to specify the `concurrency` parameters.
- `Colorbox update/reinstall`: update, or clean & re-install git submodules.
- **Note:** use `concurrency=1` to specify the `concurrency` parameters.
- `Colorbox next/prev/shuffle` (todo): next color, previous color, next random color (even you didn't configure the `shuffle` policy).
- `Colorbox pause/restart` (todo): stay on current color (disable timing config, e.g. fixed interval, by filetype timings), restart to continue change colors (enable timing config).

Expand Down
29 changes: 20 additions & 9 deletions lua/colorbox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ local function _timing()
end

--- @param opts {concurrency:integer}?
local function install(opts)
local function update(opts)
opts = opts or { concurrency = 4 }
opts.concurrency = type(opts.concurrency) == "number"
and math.max(opts.concurrency, 1)
Expand Down Expand Up @@ -410,8 +410,8 @@ local function install(opts)
end

--- @deprecated
local function update(opts)
return install(opts)
local function install(opts)
return update(opts)
end

local function _clean()
Expand All @@ -432,10 +432,9 @@ local function _clean()
logger.info("cleaned directory: %s", shorten_pack_dir)
end

--- @param args string
local function _reinstall(args)
_clean()

--- @param args string?
--- @return colorbox.Options?
local function _parse_update_args(args)
local opts = nil
if type(args) == "string" and string.len(vim.trim(args)) > 0 then
local args_splits =
Expand All @@ -444,10 +443,22 @@ local function _reinstall(args)
opts = { concurrency = tonumber(args_splits[2]) }
end
end
install(opts)
return opts
end

--- @param args string
local function _update(args)
update(_parse_update_args(args))
end

--- @param args string
local function _reinstall(args)
_clean()
update(_parse_update_args(args))
end

local CONTROLLERS_MAP = {
update = _update,
reinstall = _reinstall,
}

Expand Down Expand Up @@ -510,7 +521,7 @@ local function setup(opts)
bang = true,
desc = Configs.command.desc,
complete = function(ArgLead, CmdLine, CursorPos)
return { "reinstall" }
return { "update", "reinstall" }
end,
}
)
Expand Down

0 comments on commit c6338ff

Please sign in to comment.