robin/artio.nvim
minimal ui2 fuzzy finder for Neovim
git clone https://git.robinwobin.dev/robin/artio.nvim
8fb9b8a
main
1---@module 'artio.config' 2 3---@class artio.config 4---@field opts artio.config.opts 5---@field win artio.config.win 6---@field mappings table<string, 'up'|'down'|'accept'|'cancel'|'togglepreview'|string> 7 8---@class artio.config.opts 9---@field preselect boolean 10---@field bottom boolean 11---@field shrink boolean 12---@field promptprefix string 13---@field prompt_title boolean 14---@field pointer string 15---@field marker string 16---@field infolist ('index'|'list')[] 17---@field use_icons boolean 18 19---@class artio.config.win 20---@field height? integer|number 21---@field hidestatusline? boolean 22---@field preview_opts? fun(view: artio.View): vim.api.keyset.win_config 23 24local M ={} 25 26---@type artio.config 27---@eval return MiniDoc.afterlines_to_code(MiniDoc.current.eval_section) 28---@text # Default ~ 29M . default ={ 30opts ={ 31preselect =true , 32bottom =true , 33shrink =true , 34promptprefix ="" , 35prompt_title =true , 36pointer ="" , 37marker ="│" , 38infolist ={ "list" } , -- index: [1] list: (4/5) 39use_icons =_G [ "MiniIcons" ] and true or false , 40} , 41win ={ 42height =0.4 , 43hidestatusline =false , -- works best with laststatus=3 44---@diagnostic disable-next-line: assign-type-mismatch 45preview_opts =vim . NIL , 46} , 47mappings ={ 48[ "<down>" ] ="down" , 49[ "<up>" ] ="up" , 50[ "<cr>" ] ="accept" , 51[ "<esc>" ] ="cancel" , 52[ "<tab>" ] ="mark" , 53[ "<c-g>" ] ="togglelive" , 54[ "<c-l>" ] ="togglepreview" , 55[ "<c-q>" ] ="setqflist" , 56[ "<c-s>" ] ="split" , 57[ "<c-v>" ] ="vsplit" , 58[ "<c-t>" ] ="tabnew" , 59} , 60} 61 62---@type artio.config 63---@diagnostic disable-next-line: missing-fields 64M . config ={} 65 66---@private 67---@generic T: table|any[] 68---@param tdefault T 69---@param toverride T 70---@return T 71local function tmerge ( tdefault , toverride ) 72if toverride == nil then 73return tdefault 74end 75 76if vim . islist ( tdefault ) then 77return toverride 78end 79if vim . tbl_isempty ( tdefault ) then 80return toverride 81end 82 83return vim . iter ( pairs ( tdefault )): fold ( {} , function ( tnew , k , v ) 84if v == vim . NIL and toverride [ k ] ~= nil then 85tnew [ k ] =toverride [ k ] 86return tnew 87end 88 89if toverride [ k ] == nil or type ( v ) ~= type ( toverride [ k ]) then 90tnew [ k ] =v 91return tnew 92end 93if type ( v ) == "table" then 94tnew [ k ] =tmerge ( v , toverride [ k ]) 95return tnew 96end 97 98tnew [ k ] =toverride [ k ] 99return tnew 100end ) 101end 102 103---@param tdefault artio.config 104---@param toverride artio.config 105---@return artio.config 106function M . merge ( tdefault , toverride ) 107local defaults =vim . deepcopy ( tdefault , true ) 108local mappings =tdefault . mappings 109defaults . mappings =vim . NIL 110local t =tmerge ( defaults , toverride ) 111t . mappings =toverride . mappings or mappings 112 113return t 114end 115 116---@return artio.config 117function M . get () 118return M . merge ( M . default , M . config ) 119end 120 121---@param cfg artio.config 122---@return artio.config 123function M . override ( cfg ) 124return M . merge ( M . default , cfg ) 125end 126 127---@param cfg artio.config 128function M . set ( cfg ) 129M . config =cfg 130end 131 132return M