fix(picker): rename picker function names
This commit is contained in:
parent
a7cd41712d
commit
5588eae526
5 changed files with 27 additions and 118 deletions
|
|
@ -1,8 +1,8 @@
|
|||
local picker_utils = require('cp.pickers')
|
||||
|
||||
local contest_picker, problem_picker
|
||||
local M
|
||||
|
||||
function contest_picker(platform)
|
||||
local function contest_picker(platform)
|
||||
local constants = require('cp.constants')
|
||||
local platform_display_name = constants.PLATFORM_DISPLAY_NAMES[platform] or platform
|
||||
local fzf = require('fzf-lua')
|
||||
|
|
@ -41,7 +41,8 @@ function contest_picker(platform)
|
|||
end
|
||||
|
||||
if contest then
|
||||
problem_picker(platform, contest.id)
|
||||
local cp = require('cp')
|
||||
cp.handle_command({ fargs = { platform, contest.id } })
|
||||
end
|
||||
end,
|
||||
['ctrl-r'] = function()
|
||||
|
|
@ -53,55 +54,7 @@ function contest_picker(platform)
|
|||
})
|
||||
end
|
||||
|
||||
function problem_picker(platform, contest_id)
|
||||
local constants = require('cp.constants')
|
||||
local platform_display_name = constants.PLATFORM_DISPLAY_NAMES[platform] or platform
|
||||
local fzf = require('fzf-lua')
|
||||
local problems = picker_utils.get_problems_for_contest(platform, contest_id)
|
||||
|
||||
if #problems == 0 then
|
||||
vim.notify(
|
||||
("Contest %s %s hasn't started yet or has no available problems"):format(
|
||||
platform_display_name,
|
||||
contest_id
|
||||
),
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
contest_picker(platform)
|
||||
return
|
||||
end
|
||||
|
||||
local entries = vim.tbl_map(function(problem)
|
||||
return problem.display_name
|
||||
end, problems)
|
||||
|
||||
return fzf.fzf_exec(entries, {
|
||||
prompt = ('Select Problem (%s %s)> '):format(platform_display_name, contest_id),
|
||||
actions = {
|
||||
['default'] = function(selected)
|
||||
if not selected or #selected == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
local selected_name = selected[1]
|
||||
local problem = nil
|
||||
for _, p in ipairs(problems) do
|
||||
if p.display_name == selected_name then
|
||||
problem = p
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if problem then
|
||||
local cp = require('cp')
|
||||
cp.handle_command({ fargs = { platform, contest_id, problem.id } })
|
||||
end
|
||||
end,
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
local function platform_picker()
|
||||
function M.picker()
|
||||
local fzf = require('fzf-lua')
|
||||
local platforms = picker_utils.get_platforms()
|
||||
local entries = vim.tbl_map(function(platform)
|
||||
|
|
@ -133,6 +86,4 @@ local function platform_picker()
|
|||
})
|
||||
end
|
||||
|
||||
return {
|
||||
platform_picker = platform_picker,
|
||||
}
|
||||
return M
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue