fix: format_item doesn't have to return a string
This is perhaps ambiguous from the core docs, but format_item can return values that are not strings and they will then be stringified. So we should do the same
This commit is contained in:
parent
18a3548205
commit
7d0e85f00b
|
@ -28,7 +28,17 @@ return function(items, opts, on_choice)
|
|||
opts = opts or {}
|
||||
local config = global_config.get_mod_config("select", opts)
|
||||
opts.prompt = opts.prompt or "Select one of:"
|
||||
opts.format_item = opts.format_item or tostring
|
||||
if opts.format_item then
|
||||
-- Make format_item doesn't *technically* have to return a string for the
|
||||
-- core implementation. We should maintain compatibility by wrapping the
|
||||
-- return value with tostring
|
||||
local format_item = opts.format_item
|
||||
opts.format_item = function(item)
|
||||
return tostring(format_item(item))
|
||||
end
|
||||
else
|
||||
opts.format_item = tostring
|
||||
end
|
||||
|
||||
local backend, name = get_backend(config)
|
||||
backend.select(config[name], items, opts, on_choice)
|
||||
|
|
Loading…
Reference in New Issue