diff options
| author | ndavid <74260683+ndavidq0@users.noreply.github.com> | 2021-03-01 22:59:17 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-01 23:59:17 +0100 |
| commit | 678494e503d3c717df8295f55a6f3c7d3309b7fa (patch) | |
| tree | 8b0b8ea0199729da893d3b3230fd5e90fc36a06d /lua/telescope/utils.lua | |
| parent | b08f65c5fd25c752da0ed909349d613875f573ca (diff) | |
refactor: move transform_devicons and get_devicons to utils (#580)
So extension developers can access them
Diffstat (limited to 'lua/telescope/utils.lua')
| -rw-r--r-- | lua/telescope/utils.lua | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/lua/telescope/utils.lua b/lua/telescope/utils.lua index 4470c56..4d3de20 100644 --- a/lua/telescope/utils.lua +++ b/lua/telescope/utils.lua @@ -1,3 +1,5 @@ +local has_devicons, devicons = pcall(require, 'nvim-web-devicons') + local pathlib = require('telescope.path') local Job = require('plenary.job') @@ -295,4 +297,50 @@ utils.align_str = function(string, width, right_justify) or string..string.rep(" ", width - str_len) end +utils.transform_devicons = (function() + if has_devicons then + return function(filename, display, disable_devicons) + local conf = require('telescope.config').values + if disable_devicons or not filename then + return display + end + + local icon, icon_highlight = devicons.get_icon(filename, string.match(filename, '%a+$'), { default = true }) + local icon_display = (icon or ' ') .. ' ' .. display + + if conf.color_devicons then + return icon_display, icon_highlight + else + return icon_display + end + end + else + return function(_, display, _) + return display + end + end +end)() + +utils.get_devicons = (function() + if has_devicons then + return function(filename, disable_devicons) + local conf = require('telescope.config').values + if disable_devicons or not filename then + return '' + end + + local icon, icon_highlight = devicons.get_icon(filename, string.match(filename, '%a+$'), { default = true }) + if conf.color_devicons then + return icon, icon_highlight + else + return icon + end + end + else + return function(_, _) + return '' + end + end +end)() + return utils |
