repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

neovim/lua/bugabinga/nugu/init.lua

Raw
local palette = require 'bugabinga.nugu.palette'

-- cterm indices into the wezterm palette
local debug = (palette.debug)
local error = (palette.error)
local info = (palette.info)
local warning = (palette.warning)

local content_normal = palette.content_normal
local content_backdrop = palette.content_backdrop
local content_accent = palette.content_accent
local content_minor = palette.content_minor
local content_focus = palette.content_focus
local content_unfocus = palette.content_unfocus
local content_important_global = palette.content_important_global
local content_important_local = palette.content_important_local

local ui_normal = palette.ui_normal
local ui_backdrop = palette.ui_backdrop
local ui_accent = palette.ui_accent
local ui_minor = palette.ui_minor
local ui_focus = palette.ui_focus
local ui_unfocus = palette.ui_unfocus
local ui_important_global = palette.ui_important_global
local ui_important_local = palette.ui_important_local

-- terminal colors for neovim's built-in :terminal
-- must match wezterm's ANSI palette RGB values
local terminal_colors = {
	dark = {
		'#121212', '#e46479', '#7ba1aa', '#9e9a69',
		'#b59ae4', '#d151d1', '#5d5d5d', '#ededed',
		'#8b8b8b', '#3ec5dd', '#6f6f6f', '#242424',
		'#dfd3f3', '#d86dd8', '#c9b6eb', '#f3effb',
	},
	light = {
		'#ededed', '#c0223c', '#184e5b', '#242317',
		'#715696', '#ae2eae', '#6f6f6f', '#121212',
		'#3b3b3b', '#13616e', '#5d5d5d', '#dbdbdb',
		'#4f3c69', '#922792', '#604980', '#3e2f53',
	},
}

local is_dark = vim.opt.background:get() == 'dark'
local term_pal = is_dark and terminal_colors.dark or terminal_colors.light
for i = 0, 15 do
	vim.g['terminal_color_' .. i] = term_pal[i + 1]
end

local set_group_properties = function ( self, properties )
	vim.validate( 'properties',               properties,               'table' )
	vim.validate( 'properties.fg',            properties.fg,            'number',  true )
	vim.validate( 'properties.bg',            properties.bg,            'number',  true )
	vim.validate( 'properties.blend',         properties.blend,         'number',  true )
	vim.validate( 'properties.bold',          properties.bold,          'boolean', true )
	vim.validate( 'properties.standout',      properties.standout,      'boolean', true )
	vim.validate( 'properties.underline',     properties.underline,     'boolean', true )
	vim.validate( 'properties.undercurl',     properties.undercurl,     'boolean', true )
	vim.validate( 'properties.underdotted',   properties.underdotted,   'boolean', true )
	vim.validate( 'properties.underdashed',   properties.underdashed,   'boolean', true )
	vim.validate( 'properties.strikethrough', properties.strikethrough, 'boolean', true )
	vim.validate( 'properties.italic',        properties.italic,        'boolean', true )
	vim.validate( 'properties.reverse',       properties.reverse,       'boolean', true )
	vim.validate( 'properties.nocombine',     properties.nocombine,     'boolean', true )
	vim.validate( 'properties.default',       properties.default,       'boolean', true )
	vim.validate( 'properties.force',         properties.force,         'boolean', true )

	for key, value in pairs( properties ) do
		self[key] = value
	end
end

local new_group = function ()
	return setmetatable( {}, {
		__call = set_group_properties,
	} )
end

local add_group = function ( self, key )
	if not self.groups[key] then
		self.groups[key] = new_group()
	end
	return self.groups[key]
end

local link_group = function ( self, key, value )
	local group = add_group( self, key )
	for name, group_link in pairs( self.groups ) do
		if group_link == value then
			group.link = name
			return group
		end
	end
end

local _ = setmetatable( { groups = {} }, {
	__index = add_group,
	__newindex = link_group,
} )

_.Debug { fg = ui_normal, bg = debug, bold = true }

_.Normal { fg = content_normal, bg = content_backdrop }
_.NormalUi { fg = ui_normal, bg = ui_backdrop }
_.NormalFloat { bg = _.NormalUi.bg }
_.FloatBorder { fg = ui_accent, bg = _.NormalFloat.bg }
_.FloatBorderCorner { fg = ui_accent, bg = _.Normal.bg }
_.FloatShadow { bg = content_unfocus, blend = 80 }
_.FloatShadowThrough { bg = content_unfocus, blend = 100 }
_.FloatTitle { fg = _.FloatBorder.fg, bg = _.FloatBorder.bg, bold = true }
_.CycleBufferFileName { fg = ui_accent, bold = true }
_.CycleBufferIcon { fg = ui_minor }
_.EndOfBuffer { bg = _.Normal.bg }
_.Comment { fg = content_important_global, bold = true, italic = true }
_.NotifyBackground = _.NormalUi
_.LineNr { fg = ui_focus, bg = content_backdrop }
_.LineNrAbove { fg = ui_minor, bg = content_backdrop }
_.LineNrBelow { fg = ui_minor, bg = content_backdrop }
_.FoldColumn = _.LineNrAbove
_.SignColumn = _.LineNrAbove
_.CursorLine { bg = ui_unfocus }
_.CursorLineNr { fg = ui_focus, bg = ui_backdrop }
_.CursorLineSign = _.CursorLineNr
_.Search { fg = content_backdrop, bg = content_focus }
_.IncSearch { fg = content_backdrop, bg = content_unfocus }
_.CurSearch { fg = content_backdrop, bg = content_important_local }
_.ColorColumn { fg = ui_important_global, bg = _.Normal.bg }
_.Conceal { fg = content_focus, bg = _.Normal.bg }
_.Cursor { fg = content_backdrop, bg = content_accent }
-- _.lCursor = _.Cursor
-- _.CursorIM = _.Cursor
_.Directory { fg = _.Normal.fg }
_.Added { fg = content_focus }
_.OkMsg = _.Added
_.Removed { fg = error }
_.Changed { fg = content_important_local }
_.DiffAdd = _.Added
_.DiffDelete { fg = content_focus, strikethrough = true }
_.DiffChange { fg = content_important_global }
_.DiffText { fg = content_normal, bg = content_unfocus }
_.CursorColumn { bg = ui_unfocus }
_.MatchParen { bg = ui_unfocus, bold = true }
_.NvimInternalError { fg = error, bg = content_backdrop }
-- _.TermCursor = _.Cursor
-- _.TermCursorNC = _.Cursor
_.ErrorMsg { fg = error }
_.RedrawDebugClear { fg = content_backdrop, bg = ui_backdrop }
_.RedrawDebugComposed { fg = content_backdrop, bg = ui_unfocus }
_.RedrawDebugRecompose { fg = content_backdrop, bg = error }
_.VertSplit { fg = ui_important_global }
_.Folded = _.Conceal
_.ModeMsg { bold = true }
_.MsgArea = _.NormalUi
_.MsgSeparator = _.NormalUi
_.MoreMsg = _.NormalUi
_.NonText { fg = content_unfocus }
_.Whitespace = _.NonText
_.Pmenu = _.NormalFloat
_.PmenuSel { fg = ui_important_local, bg = _.Pmenu.bg, bold = true, underline = true }
_.PmenuSbar { fg = ui_minor, bg = _.NormalFloat.bg }
_.PmenuThumb { fg = ui_important_local, bg = _.NormalFloat.bg }
_.PmenuMatch { fg = content_focus, bold = true }
_.PmenuMatchSel { fg = content_focus, bold = true }
_.ComplMatchIns { fg = content_accent }
_.PmenuKind { fg = ui_minor }
_.PmenuKindSel { fg = ui_important_local }
_.BugabingaCmdlineCursor { fg = ui_important_local, bg = ui_unfocus, bold = true }
_.CmdlineBorderSearch { fg = ui_important_global, bg = _.NormalFloat.bg }
_.CmdlineBorderShell { fg = content_focus, bg = _.NormalFloat.bg }
_.CmdlineBorderHelp { fg = info, bg = _.NormalFloat.bg }
_.CmdlineBorderLua { fg = content_focus, bg = _.NormalFloat.bg }
_.CmdlineBorderInput { fg = ui_important_local, bg = _.NormalFloat.bg }
_.CmdlineBorderCmdline { fg = ui_minor, bg = _.NormalFloat.bg }
_.CmdlineBorderCornerSearch { fg = _.CmdlineBorderSearch.fg, bg = _.FloatBorderCorner.bg }
_.CmdlineBorderCornerShell { fg = _.CmdlineBorderShell.fg, bg = _.FloatBorderCorner.bg }
_.CmdlineBorderCornerHelp { fg = _.CmdlineBorderHelp.fg, bg = _.FloatBorderCorner.bg }
_.CmdlineBorderCornerLua { fg = _.CmdlineBorderLua.fg, bg = _.FloatBorderCorner.bg }
_.CmdlineBorderCornerInput { fg = _.CmdlineBorderInput.fg, bg = _.FloatBorderCorner.bg }
_.CmdlineBorderCornerCmdline { fg = _.CmdlineBorderCmdline.fg, bg = _.FloatBorderCorner.bg }
_.CmdlineIconSearch { fg = _.CmdlineBorderSearch.fg }
_.CmdlineIconShell { fg = _.CmdlineBorderShell.fg }
_.CmdlineIconHelp { fg = _.CmdlineBorderHelp.fg }
_.CmdlineIconLua { fg = _.CmdlineBorderLua.fg }
_.CmdlineIconInput { fg = _.CmdlineBorderInput.fg }
_.CmdlineIconCmdline { fg = _.CmdlineBorderCmdline.fg }
_.Question { fg = ui_important_local, bold = true }
_.QuickFixLine = _.PmenuSel
_.SpecialKey { fg = error, bg = content_unfocus, bold = true }
_.SpellBad { fg = error, undercurl = true }
_.SpellCap = _.SpellBad
_.SpellLocal = _.SpellBad
_.SpellRare = _.SpellBad
_.StatusLine = _.NormalUi
_.StatusLineNC { fg = ui_minor, bg = _.StatusLine.bg }
_.WinBar { fg = ui_focus, bg = _.StatusLine.bg }
_.WinBarNC { fg = ui_minor, bg = _.StatusLine.bg }
_.TabLine = _.StatusLine
_.TabLineFill = _.StatusLine
_.TabLineSel { fg = ui_important_global, bg = _.TabLine.bg, bold = true, underline = true }
_.Title { fg = content_important_global, bold = true, underline = true }
_.Visual { bg = content_unfocus }
_.VisualNOS { bg = ui_unfocus }
_.SnippetTabstop { bg = content_unfocus, underline = true }
_.WarningMsg { fg = warning, bold = true }
_.WildMenu = _.PmenuSel
_.TextYankPost { fg = content_backdrop, bg = ui_important_local }

_.String { fg = content_focus, italic = true }
_.Constant = _.String
_.Character = _.String
_.Number = _.String
_.Boolean = _.String
_.Float = _.String
_.Identifier { fg = _.Normal.fg }
_.Function { fg = _.Normal.fg }
_.FunctionDeclaration { fg = _.Function.fg, underline = true }
_.Parameter { fg = content_important_local, bold = true }
_.MutableVariable = { fg = _.Parameter.fg, underline = true }
_.Type { fg = _.Identifier.fg }
_.Delimiter { fg = content_minor }

_.Statement { fg = content_minor }
_.Conditional = _.Statement
_.Repeat = _.Statement
_.Label = _.Statement
_.Operator = _.Statement
_.Keyword = _.Statement
_.Exception = _.Statement
_.StorageClass = _.Statement
_.Structure = _.Statement
_.Typedef = _.Statement

_.PreProc { fg = content_important_global, bold = true }
_.Include = _.PreProc
_.Define = _.PreProc
_.Macro = _.PreProc
_.PreCondit = _.PreProc

_.Special { fg = content_important_global, bold = true }
_.SpecialChar = _.Special
_.Tag = _.Special
_.SpecialComment = _.Special

_.Underlined { underline = true }
_.Bold { bold = true }
_.Italic { italic = true }

_.Ignore { fg = _.Normal.bg }

_.Error { fg = error }
_.Todo { fg = content_important_global, bold = true, underdouble = true }

_.DiagnosticUnnecessary { fg = ui_focus }
_.DiagnosticDeprecated { fg = ui_important_global, strikethrough = true }
_.DiagnosticError { fg = error }
_.DiagnosticWarn { fg = warning }
_.DiagnosticInfo { fg = info }
_.DiagnosticHint { fg = ui_important_local }
_.DiagnosticOk { fg = ui_minor }

_.DiagnosticVirtualTextError = _.DiagnosticError
_.DiagnosticVirtualTextWarn = _.DiagnosticWarn
_.DiagnosticVirtualTextInfo = _.DiagnosticInfo
_.DiagnosticVirtualTextHint = _.DiagnosticHint
_.DiagnosticVirtualTextOk = _.DiagnosticOk
_.DiagnosticUnderlineError { fg = _.DiagnosticError.fg, underdouble = true }
_.DiagnosticUnderlineWarn { fg = _.DiagnosticWarn.fg, underline = true }
_.DiagnosticUnderlineInfo { fg = _.DiagnosticInfo.fg, underdashed = true }
_.DiagnosticUnderlineHint { fg = _.DiagnosticHint.fg, underdotted = true }
_.DiagnosticUnderlineOk { fg = _.DiagnosticOk.fg }
_.DiagnosticSignError                = _.DiagnosticError
_.DiagnosticSignWarn                 = _.DiagnosticWarn
_.DiagnosticSignInfo                 = _.DiagnosticInfo
_.DiagnosticSignHint                 = _.DiagnosticHint
_.DiagnosticSignOk                   = _.DiagnosticOk

_.BugabingaCodeActionFixAll          = _.DiagnosticWarn
_.BugabingaCodeActionQuickFix        = _.DiagnosticHint
_.BugabingaCodeActionRefactor        = _.DiagnosticInfo
_.BugabingaCodeActionRefactorExtract = _.DiagnosticInfo
_.BugabingaCodeActionRefactorMove    = _.DiagnosticInfo
_.BugabingaCodeActionSource          = _.DiagnosticHint
_.BugabingaCodeActionSourceImports   = _.DiagnosticHint
_.BugabingaCodeActionDefault         = _.DiagnosticHint

_.DbgViewerKind                      = _.Title
_.DbgViewerTime                      = _.Comment
_.DbgViewerMessage                   = _.Normal
_.DbgViewerLocation                  = _.Comment
_.DbgViewerFilter                    = _.Search
_.DbgViewerKindIcon                  = _.DiagnosticInfo

_.LspReferenceText { underline = true }
_.LspReferenceRead = _.LspReferenceText
_.LspReferenceWrite = _.LspReferenceText
_.LspInlayHint { fg = content_minor, bg = _.Normal.bg }
_.LspSignatureActiveParameter = _.PmenuSel

_.MiniHipatternsFixme { fg = ui_backdrop, bg = _.DiagnosticError.fg, bold = true, underline = true }
_.MiniHipatternsHack { fg = ui_backdrop, bg = _.DiagnosticWarn.fg, bold = true, underline = true }
_.MiniHipatternsTodo { fg = ui_backdrop, bg = _.DiagnosticHint.fg, bold = true, underline = true }
_.MiniHipatternsNote { fg = ui_backdrop, bg = _.DiagnosticInfo.fg, bold = true, underline = true }

_['@attribute'] = _.Keyword
_['@boolean'] = _.Boolean
_['@character'] = _.Character
_['@character.special'] = _.SpecialChar
_['@comment'] = _.Comment
_['@conditional'] = _.Conditional
_['@constant'] = _.Constant
_['@constant.builtin'] = _.String
_['@constant.macro'] = _.Define
_['@constructor'] = _.Special
_['@debug'] = _.Debug
_['@define'] = _.Define
_['@exception'] = _.Exception
_['@field'] = _.Identifier
_['@float'] = _.Float
_['@function'] = _.Function
_['@function.builtin'] = _.Special
_['@function.macro'] = _.Macro
_['@include'] = _.Include
_['@keyword'] = _.Keyword
_['@keyword.return'] { fg = _.Keyword.fg, bg = _.Keyword.bg, underline = true, bold = true }
_['@label'] = _.Label
_['@macro'] = _.Macro
_['@method'] = _.Function
_['@namespace'] = _.Function
_['@number'] = _.Number
_['@operator'] = _.Operator
_['@parameter'] = _.Parameter
_['@preproc'] = _.PreProc
_['@property'] = _.Identifier
_['@punctuation'] = _.Delimiter
_['@repeat'] = _.Repeat
_['@storageclass'] = _.StorageClass
_['@string'] = _.String
_['@string.escape'] = _.SpecialChar
_['@string.special'] = _.SpecialChar
_['@structure'] = _.Structure
_['@tag'] = _.Tag
_['@text.literal'] = _.Comment
_['@text.reference'] = _.Identifier
_['@text.title'] = _.Title
_['@text.todo'] = _.Todo
_['@text.underline'] = _.Underlined
_['@type'] = _.Type
_['@type.builtin'] = _.Type
_['@type.definition'] = _.Typedef
_['@variable'] = _.Identifier
_['@variable.parameter'] = _.Parameter

_['@markup.raw.block'] { fg = content_normal }
_['@markup.raw.block.markdown'] { fg = ui_normal }
_['@markup.raw.block.vimdoc'] { fg = ui_normal }

_['@lsp.type.class'] = _['@type']
_['@lsp.type.decorator'] = _['@function']
_['@lsp.type.enum'] = _['@type']
_['@lsp.type.enumMember'] = _['@constant']
_['@lsp.type.function'] = _['@function']
_['@lsp.type.interface'] = _['@type']
_['@lsp.type.macro'] = _['@macro']
_['@lsp.type.method'] = _['@method']
_['@lsp.type.modifier'] = _['@keyword']
_['@lsp.type.namespace'] = _['@namespace']
_['@lsp.type.parameter'] = _['@parameter']
_['@lsp.type.property'] = _['@property']
_['@lsp.type.struct'] = _['@structure']
_['@lsp.type.type'] = _['@type']
_['@lsp.type.typeParameter'] = _['@type']
_['@lsp.type.variable'] = _['@variable']
_['@lsp.typemod.function.declaration'] = _.FunctionDeclaration
_['@lsp.typemod.method.declaration'] = _.FunctionDeclaration
_['@lsp.typemod.parameter.declaration'] = _.Parameter

-- cterm attributes that must be mirrored to the cterm table
local cterm_attrs = {
	bold = true, italic = true, reverse = true, standout = true,
	underline = true, undercurl = true, underdouble = true,
	underdotted = true, underdashed = true, strikethrough = true,
	nocombine = true,
}

return function ()
	local namespace = 0
	for name, group in pairs( _.groups ) do
		if group.link then
			vim.api.nvim_set_hl( namespace, name, { link = group.link, default = group.default } )
		else
			local opts = {}
			-- map fg/bg to ctermfg/ctermbg
			if group.fg    then opts.ctermfg = group.fg end
			if group.bg    then opts.ctermbg = group.bg end
			-- mirror boolean attrs to cterm table
			local ct = {}
			for attr in pairs( cterm_attrs ) do
				if group[attr] then ct[attr] = true end
			end
			if next( ct ) then opts.cterm = ct end
			-- carry over everything else
			if group.blend   then opts.blend   = group.blend end
			if group.default then opts.default = group.default end
			if group.force   then opts.force   = group.force end
			vim.api.nvim_set_hl( namespace, name, opts )
		end
	end
end