Skip to content

Add colorscheme update and add filetype to buffer. #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 42 additions & 33 deletions lua/lib/colors.lua
Original file line number Diff line number Diff line change
@@ -1,40 +1,46 @@
local api = vim.api
local colors = require 'lib/config'.colors
local get_colors = require 'lib/config'.get_colors

local colors = get_colors()

local M = {}

local HIGHLIGHTS = {
Symlink = { gui = 'bold', fg = colors.cyan },
FolderName = { gui = 'bold', fg = colors.blue },
FolderIcon = { fg = '#90a4ae' },

ExecFile = { gui = 'bold', fg = colors.green },
SpecialFile = { gui = 'bold,underline', fg = colors.yellow },
ImageFile = { gui = 'bold', fg = colors.purple },
MarkdownFile = { 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' },
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 },

GitDirty = { fg = colors.dark_red },
GitStaged = { fg = colors.green },
GitMerge = { fg = colors.orange },
GitRenamed = { fg = colors.purple },
GitNew = { fg = colors.yellow }
}
local function create_hl()
return {
Symlink = { gui = 'bold', fg = colors.cyan },
FolderName = { gui = 'bold', fg = colors.blue },
FolderIcon = { fg = '#90a4ae' },

ExecFile = { gui = 'bold', fg = colors.green },
SpecialFile = { gui = 'bold,underline', fg = colors.yellow },
ImageFile = { gui = 'bold', fg = colors.purple },
MarkdownFile = { 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' },
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 },

GitDirty = { fg = colors.dark_red },
GitStaged = { fg = colors.green },
GitMerge = { fg = colors.orange },
GitRenamed = { fg = colors.purple },
GitNew = { fg = colors.yellow }
}
end

local HIGHLIGHTS = create_hl()

local LINKS = {
Normal = 'Normal',
Expand All @@ -45,6 +51,9 @@ local LINKS = {
}

function M.init_colors()
colors = get_colors()
print(vim.inspect(colors))
HIGHLIGHTS = create_hl()
for k, d in pairs(HIGHLIGHTS) do
local gui = d.gui or 'NONE'
api.nvim_command('hi def LuaTree'..k..' gui='..gui..' guifg='..d.fg)
Expand Down
32 changes: 22 additions & 10 deletions lua/lib/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ local function get(var, fallback)
end
end

local function get_color_from_hl(hl_name, fallback)
local id = api.nvim_get_hl_id_by_name(hl_name)
if not id then return fallback end

local hl = api.nvim_get_hl_by_id(id, true)
if not hl or not hl.foreground then return fallback end

return hl.foreground
end

local HAS_DEV_ICONS = api.nvim_call_function('exists', { "*WebDevIconsGetFileTypeSymbol" }) == 1

local show_icons = get('lua_tree_show_icons', { git = 1, folders = 1, files = 1 })
Expand All @@ -18,16 +28,18 @@ M.SHOW_FILE_ICON = HAS_DEV_ICONS and show_icons.files == 1
M.SHOW_FOLDER_ICON = show_icons.folders == 1
M.SHOW_GIT_ICON = show_icons.git == 1

M.colors = {
red = get('terminal_color_1', 'Red'),
green = get('terminal_color_2', 'Green'),
yellow = get('terminal_color_3', 'Yellow'),
blue = get('terminal_color_4', 'Blue'),
purple = get('terminal_color_5', 'Purple'),
cyan = get('terminal_color_6', 'Cyan'),
orange = get('terminal_color_11', 'Orange'),
dark_red = get('terminal_color_9', 'DarkRed'),
}
function M.get_colors()
return {
red = get('terminal_color_1', get_color_from_hl('Keyword', 'Red')),
green = get('terminal_color_2', get_color_from_hl('Character', 'Green')),
yellow = get('terminal_color_3', get_color_from_hl('PreProc', 'Yellow')),
blue = get('terminal_color_4', get_color_from_hl('Include', 'Blue')),
purple = get('terminal_color_5', get_color_from_hl('Define', 'Purple')),
cyan = get('terminal_color_6', get_color_from_hl('Conditional', 'Cyan')),
orange = get('terminal_color_11', get_color_from_hl('Number', 'Orange')),
dark_red = get('terminal_color_9', get_color_from_hl('Keyword', 'DarkRed')),
}
end

local keybindings = get('lua_tree_bindings', {});

Expand Down
1 change: 1 addition & 0 deletions lua/lib/winutils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ function M.open()

local buf = api.nvim_create_buf(false, true)
api.nvim_buf_set_name(buf, M.BUF_NAME)
api.nvim_buf_set_option(buf, 'filetype', M.BUF_NAME)

for opt, val in pairs(options) do
api.nvim_buf_set_option(buf, opt, val)
Expand Down
8 changes: 7 additions & 1 deletion lua/tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ local git = require 'lib/git'
local refresh_git = git.refresh_git
local force_refresh_git = git.force_refresh_git

require 'lib/colors'.init_colors()
local colors = require 'lib/colors'
colors.init_colors()

local M = {}

Expand Down Expand Up @@ -183,4 +184,9 @@ function M.find()

end

function M.reset_highlight()
colors.init_colors()
update_view()
end

return M
18 changes: 11 additions & 7 deletions plugin/tree.vim
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,23 @@ let g:loaded_netrwPlugin = 1

hi def link LuaTreePopup Normal

au BufWritePost * lua require'tree'.refresh()
augroup LuaTree
au BufWritePost * lua require'tree'.refresh()

if get(g:, 'lua_tree_auto_close') != 0
if get(g:, 'lua_tree_auto_close') != 0
au BufEnter * lua require'tree'.check_windows_and_close()
endif
endif

if get(g:, 'lua_tree_auto_open') != 0
if get(g:, 'lua_tree_auto_open') != 0
au VimEnter * lua require'tree'.check_buffer_and_open()
endif
endif

if get(g:, 'lua_tree_follow') != 0
if get(g:, 'lua_tree_follow') != 0
au BufEnter * :LuaTreeFindFile
endif
endif

au ColorScheme * lua require'tree'.reset_highlight()
augroup end

" TODO: WinEnter is not the right autocommand for this task,
" but we do not have LayoutChange or WinMove kind of option atm,
Expand Down