mirror of
https://github.com/jdhao/nvim-config.git
synced 2025-06-08 14:14:33 +02:00
refactor theme loading
This commit is contained in:
parent
f996edf016
commit
19cf6cca3c
@ -193,3 +193,14 @@ function! utils#MultiEdit(patterns) abort
|
||||
endfor
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
function! utils#add_pack(name) abort
|
||||
let l:success = v:true
|
||||
try
|
||||
execute printf("packadd! %s", a:name)
|
||||
catch /^Vim\%((\a\+)\)\=:E919/
|
||||
let l:success = v:false
|
||||
endtry
|
||||
|
||||
return l:success
|
||||
endfunction
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
let s:my_theme_dict = {}
|
||||
|
||||
function! s:my_theme_dict.gruvbox8() dict abort
|
||||
packadd! vim-gruvbox8
|
||||
let s:theme_func_dict = {}
|
||||
|
||||
function! s:theme_func_dict.gruvbox8() dict abort
|
||||
" Italic options should be put before colorscheme setting,
|
||||
" see https://github.com/morhetz/gruvbox/wiki/Terminal-specific#1-italics-is-disabled
|
||||
let g:gruvbox_italics=1
|
||||
@ -12,83 +10,77 @@ function! s:my_theme_dict.gruvbox8() dict abort
|
||||
colorscheme gruvbox8_hard
|
||||
endfunction
|
||||
|
||||
function! s:my_theme_dict.onedark() dict abort
|
||||
packadd! onedark.nvim
|
||||
|
||||
function! s:theme_func_dict.onedark() dict abort
|
||||
colorscheme onedark
|
||||
endfunction
|
||||
|
||||
function! s:my_theme_dict.edge() dict abort
|
||||
packadd! edge
|
||||
|
||||
function! s:theme_func_dict.edge() dict abort
|
||||
let g:edge_enable_italic = 1
|
||||
let g:edge_better_performance = 1
|
||||
colorscheme edge
|
||||
endfunction
|
||||
|
||||
function! s:my_theme_dict.sonokai() dict abort
|
||||
packadd! sonokai
|
||||
|
||||
function! s:theme_func_dict.sonokai() dict abort
|
||||
let g:sonokai_enable_italic = 1
|
||||
let g:sonokai_better_performance = 1
|
||||
colorscheme sonokai
|
||||
endfunction
|
||||
|
||||
function! s:my_theme_dict.gruvbox_material() dict abort
|
||||
packadd! gruvbox-material
|
||||
|
||||
function! s:theme_func_dict.gruvbox_material() dict abort
|
||||
let g:gruvbox_material_enable_italic = 1
|
||||
let g:gruvbox_material_better_performance = 1
|
||||
colorscheme gruvbox-material
|
||||
endfunction
|
||||
|
||||
function! s:my_theme_dict.nord() dict abort
|
||||
packadd! nord.nvim
|
||||
|
||||
function! s:theme_func_dict.nord() dict abort
|
||||
colorscheme nord
|
||||
endfunction
|
||||
|
||||
function! s:my_theme_dict.doom_one() dict abort
|
||||
packadd! doom-one.nvim
|
||||
function! s:theme_func_dict.doom_one() dict abort
|
||||
colorscheme doom-one
|
||||
endfunction
|
||||
|
||||
function! s:my_theme_dict.everforest() dict abort
|
||||
packadd! everforest
|
||||
|
||||
function! s:theme_func_dict.everforest() dict abort
|
||||
let g:everforest_enable_italic = 1
|
||||
let g:everforest_better_performance = 1
|
||||
colorscheme everforest
|
||||
endfunction
|
||||
|
||||
function! s:my_theme_dict.nightfox() dict abort
|
||||
packadd! nightfox.nvim
|
||||
|
||||
function! s:theme_func_dict.nightfox() dict abort
|
||||
colorscheme nordfox
|
||||
endfunction
|
||||
|
||||
let s:candidate_theme = [
|
||||
\ 'gruvbox8',
|
||||
\ 'onedark',
|
||||
\ 'edge',
|
||||
\ 'sonokai',
|
||||
\ 'gruvbox_material',
|
||||
\ 'nord',
|
||||
\ 'doom_one',
|
||||
\ 'everforest',
|
||||
\ 'nightfox'
|
||||
\ ]
|
||||
" Theme to directory name mapping, because theme repo name is not necessarily
|
||||
" the same as the theme name itself.
|
||||
let s:theme2dir = {
|
||||
\ 'gruvbox8' : 'vim-gruvbox8',
|
||||
\ 'onedark': 'onedark.nvim',
|
||||
\ 'edge' : 'edge',
|
||||
\ 'sonokai': 'sonokai',
|
||||
\ 'gruvbox_material': 'gruvbox-material',
|
||||
\ 'nord': 'nord.nvim',
|
||||
\ 'doom_one': 'doom-one.nvim',
|
||||
\ 'everforest' :'everforest',
|
||||
\ 'nightfox': 'nightfox.nvim'
|
||||
\ }
|
||||
|
||||
let s:theme = utils#RandElement(s:candidate_theme)
|
||||
let s:colorscheme_func = printf('s:my_theme_dict.%s()', s:theme)
|
||||
let s:theme = utils#RandElement(keys(s:theme2dir))
|
||||
let s:colorscheme_func = printf('s:theme_func_dict.%s()', s:theme)
|
||||
|
||||
if has_key(s:my_theme_dict, s:theme)
|
||||
execute 'call ' . s:colorscheme_func
|
||||
if g:logging_level == 'debug'
|
||||
let s:msg1 = "Currently loaded theme: " . s:theme
|
||||
call v:lua.vim.notify(s:msg1, 'info', {'title': 'nvim-config'})
|
||||
endif
|
||||
else
|
||||
if !has_key(s:theme_func_dict, s:theme)
|
||||
let s:msg = "Invalid colorscheme function: " . s:colorscheme_func
|
||||
call v:lua.vim.notify(s:msg, 'error', {'title': 'nvim-config'})
|
||||
finish
|
||||
endif
|
||||
|
||||
let s:res = utils#add_pack(s:theme2dir[s:theme])
|
||||
if !s:res
|
||||
echomsg printf("Theme %s not installed. Run PackerSync to install.", s:theme)
|
||||
finish
|
||||
endif
|
||||
|
||||
execute 'call ' . s:colorscheme_func
|
||||
if g:logging_level == 'debug'
|
||||
let s:msg1 = "Currently loaded theme: " . s:theme
|
||||
call v:lua.vim.notify(s:msg1, 'info', {'title': 'nvim-config'})
|
||||
endif
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user