From 505d63a3e7253a78fcc3c94d9da415fde89e9887 Mon Sep 17 00:00:00 2001 From: kiyan42 Date: Tue, 4 Aug 2020 21:07:29 +0200 Subject: [PATCH] use nvim devicon colors and fix empty space before file --- lua/lib/colors.lua | 58 ++++---------------------------------------- lua/lib/renderer.lua | 8 +++--- 2 files changed, 9 insertions(+), 57 deletions(-) diff --git a/lua/lib/colors.lua b/lua/lib/colors.lua index b40428ea..c68f5903 100644 --- a/lua/lib/colors.lua +++ b/lua/lib/colors.lua @@ -1,4 +1,5 @@ local api = vim.api +local config = require'lib.config' local M = {} @@ -42,62 +43,10 @@ local function get_hl_groups() GitStaged = { fg = colors.green }, GitMerge = { fg = colors.orange }, GitRenamed = { fg = colors.purple }, - GitNew = { fg = colors.yellow }, - - -- TODO: remove those when we add this to nvim-web-devicons - MarkdownIcon = { fg = colors.purple }, - LicenseIcon = { fg = colors.yellow }, - YamlIcon = { fg = colors.yellow }, - TomlIcon = { fg = colors.yellow }, - GitignoreIcon = { fg = colors.yellow }, - JsonIcon = { fg = colors.yellow }, - LuaIcon = { fg = '#42a5f5' }, - GoIcon = { fg = '#7Fd5EA' }, - PythonIcon = { fg = colors.green }, - ShellIcon = { fg = colors.green }, - JavascriptIcon = { fg = colors.yellow }, - CIcon = { fg = colors.blue }, - ReactIcon = { fg = colors.cyan }, - HtmlIcon = { fg = colors.orange }, - RustIcon = { fg = colors.orange }, - VimIcon = { fg = colors.green }, - TypescriptIcon = { fg = colors.blue }, + GitNew = { fg = colors.yellow } } end --- TODO: remove those when we add this to nvim-web-devicons -M.hl_groups = { - ['LICENSE'] = 'LicenseIcon'; - ['license'] = 'LicenseIcon'; - ['vim'] = 'VimIcon'; - ['.vimrc'] = 'VimIcon'; - ['c'] = 'CIcon'; - ['cpp'] = 'CIcon'; - ['python'] = 'PythonIcon'; - ['lua'] = 'LuaIcon'; - ['rs'] = 'RustIcon'; - ['sh'] = 'ShellIcon'; - ['csh'] = 'ShellIcon'; - ['zsh'] = 'ShellIcon'; - ['bash'] = 'ShellIcon'; - ['md'] = 'MarkdownIcon'; - ['json'] = 'JsonIcon'; - ['toml'] = 'TomlIcon'; - ['go'] = 'GoIcon'; - ['yaml'] = 'YamlIcon'; - ['yml'] = 'YamlIcon'; - ['conf'] = 'GitignoreIcon'; - ['javascript'] = 'JavascriptIcon'; - ['typescript'] = 'TypescriptIcon'; - ['jsx'] = 'ReactIcon'; - ['tsx'] = 'ReactIcon'; - ['htm'] = 'HtmlIcon'; - ['html'] = 'HtmlIcon'; - ['slim'] = 'HtmlIcon'; - ['haml'] = 'HtmlIcon'; - ['ejs'] = 'HtmlIcon'; -} - local function get_links() return { FolderName = 'Directory', @@ -115,6 +64,9 @@ local function get_links() end function M.setup() + if config.get_icon_state().show_file_icon then + require'nvim-web-devicons'.setup() + end local higlight_groups = get_hl_groups() for k, d in pairs(higlight_groups) do local gui = d.gui or 'NONE' diff --git a/lua/lib/renderer.lua b/lua/lib/renderer.lua index 24e3045a..3dd82e93 100644 --- a/lua/lib/renderer.lua +++ b/lua/lib/renderer.lua @@ -35,14 +35,14 @@ if icon_state.show_file_icon then get_file_icon = function(fname, extension, line, depth) local icon, hl_group = web_devicons.get_icon(fname, extension) - local hl_override = colors.hl_groups[fname] or colors.hl_groups[extension] - hl_group = hl_override or hl_group if icon then - table.insert(hl, { 'LuaTree'..hl_group, line, depth, depth + #icon }) + if hl_group then + table.insert(hl, { hl_group, line, depth, depth + #icon }) + end return icon.." " else - return icon_state.icons.default and icon_state.icons.default.." " or "" + return #icon_state.icons.default > 0 and icon_state.icons.default.." " or "" end end