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
|
||||||
endfor
|
endfor
|
||||||
endfunction
|
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 = {}
|
let s:theme_func_dict = {}
|
||||||
|
|
||||||
function! s:my_theme_dict.gruvbox8() dict abort
|
|
||||||
packadd! vim-gruvbox8
|
|
||||||
|
|
||||||
|
function! s:theme_func_dict.gruvbox8() dict abort
|
||||||
" Italic options should be put before colorscheme setting,
|
" Italic options should be put before colorscheme setting,
|
||||||
" see https://github.com/morhetz/gruvbox/wiki/Terminal-specific#1-italics-is-disabled
|
" see https://github.com/morhetz/gruvbox/wiki/Terminal-specific#1-italics-is-disabled
|
||||||
let g:gruvbox_italics=1
|
let g:gruvbox_italics=1
|
||||||
@ -12,83 +10,77 @@ function! s:my_theme_dict.gruvbox8() dict abort
|
|||||||
colorscheme gruvbox8_hard
|
colorscheme gruvbox8_hard
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:my_theme_dict.onedark() dict abort
|
function! s:theme_func_dict.onedark() dict abort
|
||||||
packadd! onedark.nvim
|
|
||||||
|
|
||||||
colorscheme onedark
|
colorscheme onedark
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:my_theme_dict.edge() dict abort
|
function! s:theme_func_dict.edge() dict abort
|
||||||
packadd! edge
|
|
||||||
|
|
||||||
let g:edge_enable_italic = 1
|
let g:edge_enable_italic = 1
|
||||||
let g:edge_better_performance = 1
|
let g:edge_better_performance = 1
|
||||||
colorscheme edge
|
colorscheme edge
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:my_theme_dict.sonokai() dict abort
|
function! s:theme_func_dict.sonokai() dict abort
|
||||||
packadd! sonokai
|
|
||||||
|
|
||||||
let g:sonokai_enable_italic = 1
|
let g:sonokai_enable_italic = 1
|
||||||
let g:sonokai_better_performance = 1
|
let g:sonokai_better_performance = 1
|
||||||
colorscheme sonokai
|
colorscheme sonokai
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:my_theme_dict.gruvbox_material() dict abort
|
function! s:theme_func_dict.gruvbox_material() dict abort
|
||||||
packadd! gruvbox-material
|
|
||||||
|
|
||||||
let g:gruvbox_material_enable_italic = 1
|
let g:gruvbox_material_enable_italic = 1
|
||||||
let g:gruvbox_material_better_performance = 1
|
let g:gruvbox_material_better_performance = 1
|
||||||
colorscheme gruvbox-material
|
colorscheme gruvbox-material
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:my_theme_dict.nord() dict abort
|
function! s:theme_func_dict.nord() dict abort
|
||||||
packadd! nord.nvim
|
|
||||||
|
|
||||||
colorscheme nord
|
colorscheme nord
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:my_theme_dict.doom_one() dict abort
|
function! s:theme_func_dict.doom_one() dict abort
|
||||||
packadd! doom-one.nvim
|
|
||||||
colorscheme doom-one
|
colorscheme doom-one
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:my_theme_dict.everforest() dict abort
|
function! s:theme_func_dict.everforest() dict abort
|
||||||
packadd! everforest
|
|
||||||
|
|
||||||
let g:everforest_enable_italic = 1
|
let g:everforest_enable_italic = 1
|
||||||
let g:everforest_better_performance = 1
|
let g:everforest_better_performance = 1
|
||||||
colorscheme everforest
|
colorscheme everforest
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:my_theme_dict.nightfox() dict abort
|
function! s:theme_func_dict.nightfox() dict abort
|
||||||
packadd! nightfox.nvim
|
|
||||||
|
|
||||||
colorscheme nordfox
|
colorscheme nordfox
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
let s:candidate_theme = [
|
" Theme to directory name mapping, because theme repo name is not necessarily
|
||||||
\ 'gruvbox8',
|
" the same as the theme name itself.
|
||||||
\ 'onedark',
|
let s:theme2dir = {
|
||||||
\ 'edge',
|
\ 'gruvbox8' : 'vim-gruvbox8',
|
||||||
\ 'sonokai',
|
\ 'onedark': 'onedark.nvim',
|
||||||
\ 'gruvbox_material',
|
\ 'edge' : 'edge',
|
||||||
\ 'nord',
|
\ 'sonokai': 'sonokai',
|
||||||
\ 'doom_one',
|
\ 'gruvbox_material': 'gruvbox-material',
|
||||||
\ 'everforest',
|
\ 'nord': 'nord.nvim',
|
||||||
\ 'nightfox'
|
\ 'doom_one': 'doom-one.nvim',
|
||||||
\ ]
|
\ 'everforest' :'everforest',
|
||||||
|
\ 'nightfox': 'nightfox.nvim'
|
||||||
|
\ }
|
||||||
|
|
||||||
let s:theme = utils#RandElement(s:candidate_theme)
|
let s:theme = utils#RandElement(keys(s:theme2dir))
|
||||||
let s:colorscheme_func = printf('s:my_theme_dict.%s()', s:theme)
|
let s:colorscheme_func = printf('s:theme_func_dict.%s()', s:theme)
|
||||||
|
|
||||||
if has_key(s:my_theme_dict, s:theme)
|
if !has_key(s:theme_func_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
|
|
||||||
let s:msg = "Invalid colorscheme function: " . s:colorscheme_func
|
let s:msg = "Invalid colorscheme function: " . s:colorscheme_func
|
||||||
call v:lua.vim.notify(s:msg, 'error', {'title': 'nvim-config'})
|
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
|
endif
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user