From b41998828df5fb601c0e068b00e4794f1ec95294 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 28 Aug 2022 12:43:50 +0800 Subject: refactor a bit 1. change theme to colorscheme 2. update plugin load logic --- core/colorschemes.lua | 123 ++++++++++++++++++++++++++++++++++++++++++++++++++ core/plugins.vim | 2 +- core/themes.lua | 123 -------------------------------------------------- init.lua | 12 ++--- lua/lua-init.lua | 5 -- 5 files changed, 130 insertions(+), 135 deletions(-) create mode 100644 core/colorschemes.lua delete mode 100644 core/themes.lua delete mode 100644 lua/lua-init.lua diff --git a/core/colorschemes.lua b/core/colorschemes.lua new file mode 100644 index 0000000..1a42828 --- /dev/null +++ b/core/colorschemes.lua @@ -0,0 +1,123 @@ +local utils = require('utils') + +local M = {} + +-- Theme to directory name mapping, because theme repo name is not necessarily +-- the same as the theme name itself. +M.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', + kanagawa = 'kanagawa.nvim', + catppuccin = 'catppuccin' +} + +M.gruvbox8 = function() + -- Italic options should be put before colorscheme setting, + -- see https://github.com/morhetz/gruvbox/wiki/Terminal-specific#1-italics-is-disabled + vim.g.gruvbox_italics = 1 + vim.g.gruvbox_italicize_strings = 1 + vim.g.gruvbox_filetype_hi_groups = 1 + vim.g.gruvbox_plugin_hi_groups = 1 + + vim.cmd [[colorscheme gruvbox8_hard]] +end + +M.onedark = function() + vim.cmd [[colorscheme onedark]] +end + +M.edge = function() + vim.g.edge_enable_italic = 1 + vim.g.edge_better_performance = 1 + + vim.cmd [[colorscheme edge]] +end + +M.sonokai = function() + vim.g.sonokai_enable_italic = 1 + vim.g.sonokai_better_performance = 1 + + vim.cmd [[colorscheme sonokai]] +end + +M.gruvbox_material = function() + vim.g.gruvbox_material_enable_italic = 1 + vim.g.gruvbox_material_better_performance = 1 + + vim.cmd [[colorscheme gruvbox-material]] +end + +M.nord = function() + vim.cmd [[colorscheme nord]] +end + +M.doom_one = function() + + vim.cmd [[colorscheme doom-one]] +end + +M.everforest = function() + vim.g.everforest_enable_italic = 1 + vim.g.everforest_better_performance = 1 + + vim.cmd [[colorscheme everforest]] +end + +M.nightfox = function() + vim.cmd [[colorscheme nordfox]] +end + + +M.kanagawa = function() + vim.cmd [[colorscheme kanagawa]] +end + +M.catppuccin = function() + -- available option: latte, frappe, macchiato, mocha + vim.g.catppuccin_flavour = "frappe" + + require("catppuccin").setup() + + vim.cmd [[colorscheme catppuccin]] +end + + +--- Use a random theme from the pre-defined list of themes. +M.rand_theme = function () + local theme = utils.rand_element(vim.tbl_keys(M.theme2dir)) + + if not vim.tbl_contains(vim.tbl_keys(M), theme) then + local msg = "Invalid theme: " .. theme + vim.notify(msg, vim.log.levels.ERROR, { title = 'nvim-config' }) + + return + end + + -- Load the theme, because all the themes are declared as opt plugins, the theme isn't loaded yet. + local status = utils.add_pack(M.theme2dir[theme]) + + if not status then + local msg = string.format("Theme %s is not installed. Run PackerSync to install.", theme) + vim.notify(msg, vim.log.levels.ERROR, { title = 'nvim-config' }) + + return + end + + -- Set the theme. + M[theme]() + + if vim.g.logging_level == 'debug' then + local msg = "Colorscheme: " .. theme + + vim.notify(msg, vim.log.levels.DEBUG, { title = 'nvim-config' }) + end +end + +M.rand_theme() diff --git a/core/plugins.vim b/core/plugins.vim index fd4a6a8..1a1cd65 100644 --- a/core/plugins.vim +++ b/core/plugins.vim @@ -1,7 +1,7 @@ scriptencoding utf-8 " Plugin specification and lua stuff -lua require('lua-init') +lua require('plugins') " Use short names for common plugin manager commands to simplify typing. " To use these shortcuts: first activate command line with `:`, then input the diff --git a/core/themes.lua b/core/themes.lua deleted file mode 100644 index 1a42828..0000000 --- a/core/themes.lua +++ /dev/null @@ -1,123 +0,0 @@ -local utils = require('utils') - -local M = {} - --- Theme to directory name mapping, because theme repo name is not necessarily --- the same as the theme name itself. -M.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', - kanagawa = 'kanagawa.nvim', - catppuccin = 'catppuccin' -} - -M.gruvbox8 = function() - -- Italic options should be put before colorscheme setting, - -- see https://github.com/morhetz/gruvbox/wiki/Terminal-specific#1-italics-is-disabled - vim.g.gruvbox_italics = 1 - vim.g.gruvbox_italicize_strings = 1 - vim.g.gruvbox_filetype_hi_groups = 1 - vim.g.gruvbox_plugin_hi_groups = 1 - - vim.cmd [[colorscheme gruvbox8_hard]] -end - -M.onedark = function() - vim.cmd [[colorscheme onedark]] -end - -M.edge = function() - vim.g.edge_enable_italic = 1 - vim.g.edge_better_performance = 1 - - vim.cmd [[colorscheme edge]] -end - -M.sonokai = function() - vim.g.sonokai_enable_italic = 1 - vim.g.sonokai_better_performance = 1 - - vim.cmd [[colorscheme sonokai]] -end - -M.gruvbox_material = function() - vim.g.gruvbox_material_enable_italic = 1 - vim.g.gruvbox_material_better_performance = 1 - - vim.cmd [[colorscheme gruvbox-material]] -end - -M.nord = function() - vim.cmd [[colorscheme nord]] -end - -M.doom_one = function() - - vim.cmd [[colorscheme doom-one]] -end - -M.everforest = function() - vim.g.everforest_enable_italic = 1 - vim.g.everforest_better_performance = 1 - - vim.cmd [[colorscheme everforest]] -end - -M.nightfox = function() - vim.cmd [[colorscheme nordfox]] -end - - -M.kanagawa = function() - vim.cmd [[colorscheme kanagawa]] -end - -M.catppuccin = function() - -- available option: latte, frappe, macchiato, mocha - vim.g.catppuccin_flavour = "frappe" - - require("catppuccin").setup() - - vim.cmd [[colorscheme catppuccin]] -end - - ---- Use a random theme from the pre-defined list of themes. -M.rand_theme = function () - local theme = utils.rand_element(vim.tbl_keys(M.theme2dir)) - - if not vim.tbl_contains(vim.tbl_keys(M), theme) then - local msg = "Invalid theme: " .. theme - vim.notify(msg, vim.log.levels.ERROR, { title = 'nvim-config' }) - - return - end - - -- Load the theme, because all the themes are declared as opt plugins, the theme isn't loaded yet. - local status = utils.add_pack(M.theme2dir[theme]) - - if not status then - local msg = string.format("Theme %s is not installed. Run PackerSync to install.", theme) - vim.notify(msg, vim.log.levels.ERROR, { title = 'nvim-config' }) - - return - end - - -- Set the theme. - M[theme]() - - if vim.g.logging_level == 'debug' then - local msg = "Colorscheme: " .. theme - - vim.notify(msg, vim.log.levels.DEBUG, { title = 'nvim-config' }) - end -end - -M.rand_theme() diff --git a/init.lua b/init.lua index 3d95fd4..9299a2d 100644 --- a/init.lua +++ b/init.lua @@ -21,12 +21,12 @@ if nvim_ver ~= expected_ver then end local core_conf_files = { - "globals.vim", - "options.vim", - "autocommands.vim", - "mappings.vim", - "plugins.vim", - "themes.lua", + "globals.vim", -- some global settings + "options.vim", -- setting options in nvim + "autocommands.vim", -- various autocommands + "mappings.vim", -- all the user-defined mappings + "plugins.vim", -- all the plugins installed and their configurations + "colorschemes.lua", -- colorscheme settings } -- source all the core config files diff --git a/lua/lua-init.lua b/lua/lua-init.lua deleted file mode 100644 index c72cbb2..0000000 --- a/lua/lua-init.lua +++ /dev/null @@ -1,5 +0,0 @@ --- Some utility stuff -require 'utils' - --- plugin installation -require 'plugins' -- cgit v1.2.3