aboutsummaryrefslogtreecommitdiff
path: root/core/themes.vim
diff options
context:
space:
mode:
authorjdhao <jdhao@hotmail.com>2021-11-23 22:39:43 +0800
committerjdhao <jdhao@hotmail.com>2021-11-23 22:43:12 +0800
commit19cf6cca3c710b7ba68bdf49327ac9c295225e21 (patch)
treeec9d104698b73baf25bb9abbf10344b8b3085b8d /core/themes.vim
parentf996edf016e289051a518e5c8b106a8aebd77400 (diff)
refactor theme loading
Diffstat (limited to 'core/themes.vim')
-rw-r--r--core/themes.vim90
1 files changed, 41 insertions, 49 deletions
diff --git a/core/themes.vim b/core/themes.vim
index 28e7bc6..2db4be9 100644
--- a/core/themes.vim
+++ b/core/themes.vim
@@ -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'
- \ ]
-
-let s:theme = utils#RandElement(s:candidate_theme)
-let s:colorscheme_func = printf('s:my_theme_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
+" 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(keys(s:theme2dir))
+let s:colorscheme_func = printf('s:theme_func_dict.%s()', s:theme)
+
+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