Feature to add a custom theme (#19)

Closes #21 

Co-authored-by: Olivier Roques <olivier@oroques.dev>
This commit is contained in:
Aditya Sengupta
2021-07-11 21:55:34 +05:30
committed by GitHub
parent 8b6d209262
commit 17634e8250
2 changed files with 142 additions and 2 deletions

View File

@@ -8,6 +8,7 @@ local g, o, wo = vim.g, vim.o, vim.wo
local fmt = string.format local fmt = string.format
local common = require('hardline.common') local common = require('hardline.common')
local bufferline = require('hardline.bufferline') local bufferline = require('hardline.bufferline')
local custom_colors = require('hardline.themes.custom_colors')
local M = {} local M = {}
-------------------- OPTIONS ------------------------------- -------------------- OPTIONS -------------------------------
@@ -19,6 +20,19 @@ M.options = {
separator = '|', separator = '|',
}, },
theme = 'default', theme = 'default',
custom_theme = {
text = {gui = "NONE", cterm = "NONE", cterm16 = "NONE"},
normal = {gui = "NONE", cterm = "NONE", cterm16 = "NONE"},
insert = {gui = "NONE", cterm = "NONE", cterm16 = "NONE"},
replace = {gui = "NONE", cterm = "NONE", cterm16 = "NONE"},
inactive_comment = {gui = "NONE", cterm = "NONE", cterm16 = "NONE"},
inactive_cursor = {gui = "NONE", cterm = "NONE", cterm16 = "NONE"},
inactive_menu = {gui = "NONE", cterm = "NONE", cterm16 = "NONE"},
visual = {gui = "NONE", cterm = "NONE", cterm16 = "NONE"},
command = {gui = "NONE", cterm = "NONE", cterm16 = "NONE"},
alt_text = {gui = "NONE", cterm = "NONE", cterm16 = "NONE"},
warning = {gui = "NONE", cterm = "NONE", cterm16 = "NONE"},
},
sections = { sections = {
{class = 'mode', item = require('hardline.parts.mode').get_item}, {class = 'mode', item = require('hardline.parts.mode').get_item},
{class = 'high', item = require('hardline.parts.git').get_item, hide = 80}, {class = 'high', item = require('hardline.parts.git').get_item, hide = 80},
@@ -182,8 +196,12 @@ local function set_theme()
if type(M.options.theme) ~= 'string' then if type(M.options.theme) ~= 'string' then
return return
end end
local theme = fmt('hardline.themes.%s', M.options.theme) if M.options.theme == 'custom' then
M.options.theme = require(theme) M.options.theme = custom_colors.set(M.options.custom_theme)
else
local theme = fmt('hardline.themes.%s', M.options.theme)
M.options.theme = require(theme)
end
end end
local function set_hlgroups() local function set_hlgroups()

View File

@@ -0,0 +1,122 @@
-- Custom colorscheme
local M = {}
M.set = function(color_table)
local inactive = {
guifg = color_table.inactive_comment.gui,
guibg = color_table.inactive_cursor.gui,
ctermfg = color_table.inactive_comment.cterm,
ctermbg = color_table.inactive_cursor.cterm,
}
return {
mode = {
inactive = inactive,
normal = {
guifg = color_table.text.gui,
guibg = color_table.normal.gui,
ctermfg = color_table.text.cterm,
ctermbg = color_table.normal.cterm,
},
insert = {
guifg = color_table.text.gui,
guibg = color_table.insert.gui,
ctermfg = color_table.text.cterm,
ctermbg = color_table.insert.cterm,
},
replace = {
guifg = color_table.text.gui,
guibg = color_table.replace.gui,
ctermfg = color_table.text.cterm,
ctermbg = color_table.replace.cterm,
},
visual = {
guifg = color_table.text.gui,
guibg = color_table.visual.gui,
ctermfg = color_table.text.cterm,
ctermbg = color_table.visual.cterm,
},
command = {
guifg = color_table.text.gui,
guibg = color_table.command.gui,
ctermfg = color_table.text.cterm,
ctermbg = color_table.command.cterm,
},
},
low = {
active = {
guifg = color_table.alt_text.gui,
guibg = color_table.inactive_cursor.gui,
ctermfg = color_table.alt_text.cterm,
ctermbg = color_table.inactive_cursor.cterm,
},
inactive = inactive,
},
med = {
active = {
guifg = color_table.alt_text.gui,
guibg = color_table.inactive_cursor.gui,
ctermfg = color_table.alt_text.cterm,
ctermbg = color_table.inactive_cursor.cterm,
},
inactive = inactive,
},
high = {
active = {
guifg = color_table.alt_text.gui,
guibg = color_table.inactive_menu.gui,
ctermfg = color_table.alt_text.cterm,
ctermbg = color_table.inactive_menu.cterm,
},
inactive = inactive,
},
error = {
active = {
guifg = color_table.text.gui,
guibg = color_table.command.gui,
ctermfg = color_table.text.cterm,
ctermbg = color_table.command.cterm,
},
inactive = inactive,
},
warning = {
active = {
guifg = color_table.text.gui,
guibg = color_table.warning.gui,
ctermfg = color_table.text.cterm,
ctermbg = color_table.warning.cterm,
},
inactive = inactive,
},
bufferline = {
separator = inactive,
current = {
guifg = color_table.text.gui,
guibg = color_table.normal.gui,
ctermfg = color_table.text.cterm,
ctermbg = color_table.normal.cterm,
},
current_modified = {
guifg = color_table.text.gui,
guibg = color_table.insert.gui,
ctermfg = color_table.text.cterm,
ctermbg = color_table.insert.cterm,
},
background = {
guifg = color_table.normal.gui,
guibg = color_table.text.gui,
ctermfg = color_table.normal.cterm,
ctermbg = color_table.text.cterm,
},
background_modified = {
guifg = color_table.insert.gui,
guibg = color_table.text.gui,
ctermfg = color_table.insert.cterm,
ctermbg = color_table.text.cterm,
},
},
}
end
return M