From 2951af7bbd839ebef25e33f8bd01bd5c501f76c8 Mon Sep 17 00:00:00 2001 From: aktersnurra Date: Sat, 29 Oct 2022 18:19:38 +0200 Subject: Update how options and colorscheme is set (#12) * Update loading of colorscheme * Fix typo * Fix setting of style * Fix highlighting * Unpack style * Add empty table if props are nil * Fix concat of tables * Fix typo * Update settings * Add call set in settings * Add deep extend * Remove style field * Update README BREAKING CHANGE: updates how the colorscheme is set and the structure of the options table --- README.md | 35 +++++++---- colors/no-clown-fiesta.lua | 8 +-- lua/no-clown-fiesta/highlight-group/hop.lua | 4 +- lua/no-clown-fiesta/highlight-group/lsp.lua | 8 +-- lua/no-clown-fiesta/highlight-group/markdown.lua | 6 +- lua/no-clown-fiesta/highlight-group/nvim-tree.lua | 4 +- lua/no-clown-fiesta/highlight-group/telescope.lua | 2 +- lua/no-clown-fiesta/highlight-group/treesitter.lua | 42 ++++++++++---- lua/no-clown-fiesta/highlights.lua | 67 ++++++++++++++-------- lua/no-clown-fiesta/init.lua | 15 +++-- lua/no-clown-fiesta/palette.lua | 1 + lua/no-clown-fiesta/settings.lua | 25 ++++---- lua/no-clown-fiesta/util.lua | 18 +----- 13 files changed, 138 insertions(+), 97 deletions(-) diff --git a/README.md b/README.md index a8b03c5..dec0af9 100644 --- a/README.md +++ b/README.md @@ -4,23 +4,34 @@ An attempt at a color scheme that does not look like a clown puked up the source ![image](https://gustafrydholm.xyz/images/no-clown-fiesta.png?) -## Setup -The default configuration is: +## Usage + +To enable this colorscheme: + +```vim +colorscheme no-clown-fiesta +``` + ```lua -{ - transparent_background = palette.bg, - comments = "NONE", - keywords = "NONE", - functions = "NONE", - variables = "NONE", - type = "NONE", -} +vim.cmd[[colorscheme no-clown-fiesta]] ``` -These can be overridden when activating the plugin, e.g.: +To override the default settings you need to call setup before enabling the +colorscheme. No-clown-fiesta will use these settings, unless you call setup +and override these. ```lua -require("no-clown-fiesta").setup({ type = "bold,italic" }) +require("no-clown-fiesta").setup({ + transparent = false, -- Enable this to disable the bg color + styles = { + -- You can set any of the style values specified for `:h nvim_set_hl` + comments = {}, + keywords = {}, + functions = {}, + variables = {}, + type = { bold = true }, + }, +}) ``` ## Supported Plugins diff --git a/colors/no-clown-fiesta.lua b/colors/no-clown-fiesta.lua index 1678131..3a7818d 100644 --- a/colors/no-clown-fiesta.lua +++ b/colors/no-clown-fiesta.lua @@ -1,7 +1 @@ -for k in pairs(package.loaded) do - if k:match ".*no-clown-fiesta.*" then - package.loaded[k] = nil - end -end - -require "no-clown-fiesta" +require("no-clown-fiesta").load() diff --git a/lua/no-clown-fiesta/highlight-group/hop.lua b/lua/no-clown-fiesta/highlight-group/hop.lua index 341c6ff..caa16b2 100644 --- a/lua/no-clown-fiesta/highlight-group/hop.lua +++ b/lua/no-clown-fiesta/highlight-group/hop.lua @@ -2,8 +2,8 @@ local M = {} function M.highlight(palette) return { - HopNextKey = { fg = palette.cyan, style = "bold" }, - HopNextKey1 = { fg = palette.red, style = "bold" }, + HopNextKey = { fg = palette.cyan, bold = true }, + HopNextKey1 = { fg = palette.red, bold = true }, HopNextKey2 = { fg = palette.gray_blue }, HopUnmatched = { fg = palette.gray }, } diff --git a/lua/no-clown-fiesta/highlight-group/lsp.lua b/lua/no-clown-fiesta/highlight-group/lsp.lua index daf87f9..5ebfc34 100644 --- a/lua/no-clown-fiesta/highlight-group/lsp.lua +++ b/lua/no-clown-fiesta/highlight-group/lsp.lua @@ -35,11 +35,11 @@ function M.highlight(palette) LspDiagnosticsHint = { fg = palette.hint_blue }, DiagnosticUnderlineError = { sp = palette.error_red, - style = "undercurl", + undercurl = true, }, - DiagnosticUnderlineWarn = { sp = palette.warning_orange, style = "NONE" }, - DiagnosticUnderlineInfo = { sp = palette.hint_blue, style = "NONE" }, - DiagnosticUnderlineHint = { sp = palette.hint_blue, style = "NONE" }, + DiagnosticUnderlineWarn = { sp = palette.warning_orange }, + DiagnosticUnderlineInfo = { sp = palette.hint_blue }, + DiagnosticUnderlineHint = { sp = palette.hint_blue }, LspReferenceRead = { bg = "#36383F" }, LspReferenceText = { bg = "#36383F" }, LspReferenceWrite = { bg = "#36383f" }, diff --git a/lua/no-clown-fiesta/highlight-group/markdown.lua b/lua/no-clown-fiesta/highlight-group/markdown.lua index 28ece3b..6147a25 100644 --- a/lua/no-clown-fiesta/highlight-group/markdown.lua +++ b/lua/no-clown-fiesta/highlight-group/markdown.lua @@ -3,7 +3,7 @@ local M = {} function M.highlight(palette) return { markdownBlockquote = { fg = palette.accent }, - markdownBold = { fg = palette.yellow, style = "bold" }, + markdownBold = { fg = palette.yellow, bold = true }, markdownCode = { fg = palette.green }, markdownCodeBlock = { fg = palette.green }, markdownCodeDelimiter = { fg = palette.green }, @@ -19,12 +19,12 @@ function M.highlight(palette) markdownIdDeclaration = { fg = palette.blue }, markdownIdDelimiter = { fg = palette.light_gray }, markdownLinkDelimiter = { fg = palette.light_gray }, - markdownItalic = { style = "italic" }, + markdownItalic = { italic = true }, markdownLinkText = { fg = palette.blue }, markdownListMarker = { fg = palette.red }, markdownOrderedListMarker = { fg = palette.red }, markdownRule = { fg = palette.accent }, - markdownUrl = { fg = palette.cyan, style = "underline" }, + markdownUrl = { fg = palette.cyan, underline = true }, } end diff --git a/lua/no-clown-fiesta/highlight-group/nvim-tree.lua b/lua/no-clown-fiesta/highlight-group/nvim-tree.lua index ffe7897..21cdc25 100644 --- a/lua/no-clown-fiesta/highlight-group/nvim-tree.lua +++ b/lua/no-clown-fiesta/highlight-group/nvim-tree.lua @@ -7,7 +7,7 @@ function M.highlight(palette) NvimTreeNormal = { fg = palette.light_gray, bg = palette.alt_bg }, NvimTreeVertSplit = { fg = palette.alt_bg, bg = palette.alt_bg }, NvimTreeFolderName = { fg = palette.white }, - NvimTreeOpenedFolderName = { fg = palette.white, style = "bold" }, + NvimTreeOpenedFolderName = { fg = palette.white, bold = true }, NvimTreeEmptyFolderName = { fg = palette.medium_gray }, NvimTreeGitIgnored = { fg = palette.medium_gray }, NvimTreeImageFile = { fg = palette.light_gray }, @@ -22,7 +22,7 @@ function M.highlight(palette) NvimTreeGitMerge = { fg = palette.info_yellow }, NvimTreeGitDirty = { fg = palette.info_yellow }, NvimTreeSymlink = { fg = palette.cyan }, - NvimTreeRootFolder = { fg = palette.fg, style = "bold" }, + NvimTreeRootFolder = { fg = palette.fg, bold = true }, NvimTreeExecFile = { fg = palette.green }, NvimTreeStatusLine = { fg = palette.alt_bg, bg = palette.alt_bg }, NvimTreeStatusLineNC = { fg = palette.alt_bg, bg = palette.alt_bg }, diff --git a/lua/no-clown-fiesta/highlight-group/telescope.lua b/lua/no-clown-fiesta/highlight-group/telescope.lua index 211e21e..1a0971c 100644 --- a/lua/no-clown-fiesta/highlight-group/telescope.lua +++ b/lua/no-clown-fiesta/highlight-group/telescope.lua @@ -4,7 +4,7 @@ function M.highlight(palette) return { TelescopeNormal = { fg = palette.fg, bg = palette.bg }, TelescopeSelection = { fg = palette.fg, bg = palette.accent }, - TelescopeMatching = { fg = palette.info_yellow, style = "bold" }, + TelescopeMatching = { fg = palette.info_yellow, bold = true }, TelescopeBorder = { fg = palette.fg, bg = palette.bg }, } end diff --git a/lua/no-clown-fiesta/highlight-group/treesitter.lua b/lua/no-clown-fiesta/highlight-group/treesitter.lua index 6d5f8c6..fb3d1c1 100644 --- a/lua/no-clown-fiesta/highlight-group/treesitter.lua +++ b/lua/no-clown-fiesta/highlight-group/treesitter.lua @@ -1,18 +1,32 @@ local M = {} -function M.highlight(palette, opts) +local unpack = unpack + +function M.highlight(palette, options) return { - ["@comment"] = { fg = palette.medium_gray, style = opts.comments }, + ["@comment"] = vim.tbl_extend( + "force", + { fg = palette.medium_gray }, + options.styles.comments + ), ["@annotation"] = { fg = palette.white }, ["@attribute"] = { fg = palette.white }, ["@constructor"] = { fg = palette.cyan }, - ["@type"] = { fg = palette.white, style = opts.type }, + ["@type"] = vim.tbl_extend("force", { fg = palette.white }, options.styles.type), ["@type.builtin"] = { fg = palette.white }, ["@conditional"] = { fg = palette.gray_blue }, ["@exception"] = { fg = palette.red }, ["@include"] = { fg = palette.red }, - ["@keyword"] = { fg = palette.gray_blue, style = opts.keywords }, - ["@keyword.function"] = { fg = palette.gray_blue, style = opts.keywords }, + ["@keyword"] = vim.tbl_extend( + "force", + { fg = palette.gray_blue }, + options.styles.keywords + ), + ["@keyword.function"] = vim.tbl_extend( + "force", + { fg = palette.gray_blue }, + options.styles.keywords + ), ["@label"] = { fg = palette.white }, ["@namespace"] = { fg = palette.white }, ["@repeat"] = { fg = palette.gray_blue }, @@ -23,12 +37,20 @@ function M.highlight(palette, opts) ["@boolean"] = { fg = palette.red }, ["@character"] = { fg = palette.light_green }, ["@error"] = { fg = palette.error_red }, - ["@function"] = { fg = palette.cyan, style = opts.functions }, + ["@function"] = vim.tbl_extend( + "force", + { fg = palette.cyan }, + options.styles.functions + ), ["@function.builtin"] = { fg = palette.cyan }, ["@method"] = { fg = palette.cyan }, ["@const.macro"] = { fg = palette.cyan }, ["@function.macro"] = { fg = palette.cyan }, - ["@variable"] = { fg = palette.white, style = opts.variables }, + ["@variable"] = vim.tbl_extend( + "force", + { fg = palette.white }, + options.styles.variables + ), ["@variable.builtin"] = { fg = palette.white }, ["@property"] = { fg = palette.white }, ["@operator"] = { fg = palette.white }, @@ -45,11 +67,11 @@ function M.highlight(palette, opts) ["@string.regex"] = { fg = palette.medium_gray_blue }, ["@string.escape"] = { fg = palette.medium_gray_blue }, ["@tag"] = { fg = palette.pale_purple }, - ["@emphasis"] = { style = "italic" }, - ["@underline"] = { style = "underline" }, + ["@emphasis"] = { italic = true }, + ["@underline"] = { underline = true }, ["@title"] = { fg = palette.medium_gray }, ["@literal"] = { fg = palette.medium_gray }, - ["@uri"] = { fg = palette.cyan, style = "underline" }, + ["@uri"] = { fg = palette.cyan, underline = true }, ["@keyword.operator"] = { fg = palette.gray_blue }, ["@structure"] = { fg = palette.purple_test }, ["@strong"] = { fg = palette.medium_gray }, diff --git a/lua/no-clown-fiesta/highlights.lua b/lua/no-clown-fiesta/highlights.lua index 5ebbc45..86446fc 100644 --- a/lua/no-clown-fiesta/highlights.lua +++ b/lua/no-clown-fiesta/highlights.lua @@ -1,22 +1,29 @@ local M = {} -function M.highlight(palette, opts) +function M.highlight(palette, options) return { - Normal = { fg = palette.fg, bg = opts.transparent_background }, + Normal = { + fg = palette.fg, + bg = options.transparent and palette.none or palette.bg, + }, SignColumn = { bg = palette.bg }, MsgArea = { fg = palette.fg, bg = palette.bg }, ModeMsg = { fg = palette.fg, bg = palette.bg }, MsgSeparator = { fg = palette.fg, bg = palette.bg }, - SpellBad = { sp = palette.error_red, style = "undercurl" }, - SpellCap = { sp = palette.yellow, style = "undercurl" }, - SpellLocal = { sp = palette.green, style = "undercurl" }, - SpellRare = { sp = palette.purple, style = "undercurl" }, + SpellBad = { sp = palette.error_red, undercurl = true }, + SpellCap = { sp = palette.yellow, undercurl = true }, + SpellLocal = { sp = palette.green, undercurl = true }, + SpellRare = { sp = palette.purple, undercurl = true }, NormalNC = { fg = palette.fg, bg = palette.bg }, Pmenu = { fg = palette.light_gray, bg = palette.accent }, PmenuSel = { fg = palette.blue, bg = palette.alt_bg }, WildMenu = { fg = palette.blue, bg = palette.alt_bg }, - CursorLineNr = { fg = palette.light_gray, style = "bold" }, - Comment = { fg = palette.medium_gray, style = opts.comments }, + CursorLineNr = { fg = palette.light_gray, bold = true }, + Comment = vim.tbl_extend( + "force", + { fg = palette.medium_gray }, + options.styles.comments + ), Folded = { fg = palette.light_gray, bg = palette.alt_bg }, FoldColumn = { fg = palette.light_gray, bg = palette.alt_bg }, LineNr = { fg = palette.gray }, @@ -39,10 +46,10 @@ function M.highlight(palette, opts) QuickFixLine = { bg = palette.accent }, PmenuSbar = { bg = palette.alt_bg }, PmenuThumb = { bg = palette.light_gray }, - MatchWord = { style = "underline" }, - MatchParen = { fg = palette.pale_purple, bg = palette.bg, style = "underline" }, - MatchWordCur = { style = "underline" }, - MatchParenCur = { style = "underline" }, + MatchWord = { underline = true }, + MatchParen = { fg = palette.pale_purple, bg = palette.bg, underline = true }, + MatchWordCur = { underline = true }, + MatchParenCur = { underline = true }, Cursor = { fg = palette.cursor_fg, bg = palette.cursor_bg }, lCursor = { fg = palette.cursor_fg, bg = palette.cursor_bg }, CursorIM = { fg = palette.cursor_fg, bg = palette.cursor_bg }, @@ -52,7 +59,7 @@ function M.highlight(palette, opts) Directory = { fg = palette.blue }, SpecialKey = { fg = palette.blue }, Title = { fg = palette.blue }, - ErrorMsg = { fg = palette.error_red, bg = palette.bg, style = "bold" }, + ErrorMsg = { fg = palette.error_red, bg = palette.bg, bold = true }, Search = { fg = palette.orange, bg = palette.alt_bg }, IncSearch = { fg = palette.cursor_fg, bg = palette.alt_bg }, Substitute = { fg = palette.alt_bg, bg = palette.gray_blue }, @@ -60,7 +67,11 @@ function M.highlight(palette, opts) Question = { fg = palette.cyan }, EndOfBuffer = { fg = palette.bg }, NonText = { fg = palette.bg }, - Variable = { fg = palette.white, style = opts.variables }, + Variable = vim.tbl_extend( + "force", + { fg = palette.white }, + options.styles.variables + ), String = { fg = palette.medium_gray_blue }, Character = { fg = palette.light_green }, Constant = { fg = palette.white }, @@ -68,13 +79,17 @@ function M.highlight(palette, opts) Boolean = { fg = palette.red }, Float = { fg = palette.red }, Identifier = { fg = palette.white }, - Function = { fg = palette.cyan, style = opts.functions }, + Function = vim.tbl_extend("force", { fg = palette.cyan }, options.styles.functions), Operator = { fg = palette.white }, - Type = { fg = palette.white, style = opts.type }, + Type = vim.tbl_extend("force", { fg = palette.white }, options.styles.type), StorageClass = { fg = palette.gray_blue }, Structure = { fg = palette.gray_blue }, Typedef = { fg = palette.white }, - Keyword = { fg = palette.gray_blue, style = opts.keywords }, + Keyword = vim.tbl_extend( + "force", + { fg = palette.gray_blue }, + options.styles.keywords + ), Statement = { fg = palette.gray_blue }, Conditional = { fg = palette.gray_blue }, Repeat = { fg = palette.gray_blue }, @@ -90,13 +105,17 @@ function M.highlight(palette, opts) Tag = { fg = palette.pale_purple }, Debug = { fg = palette.red }, Delimiter = { fg = palette.white }, - SpecialComment = { fg = palette.medium_gray, style = opts.comments }, - Underlined = { style = "underline" }, - Bold = { style = "bold" }, - Italic = { style = "italic" }, - Ignore = { fg = palette.cyan, bg = palette.bg, style = "bold" }, - Todo = { fg = palette.red, bg = palette.bg, style = "bold" }, - Error = { fg = palette.error_red, bg = palette.bg, style = "bold" }, + SpecialComment = vim.tbl_extend( + "force", + { fg = palette.medium_gray }, + options.styles.comments + ), + Underlined = { underline = true }, + Bold = { bold = true }, + Italic = { italic = true }, + Ignore = { fg = palette.cyan, bg = palette.bg, bold = true }, + Todo = { fg = palette.red, bg = palette.bg, bold = true }, + Error = { fg = palette.error_red, bg = palette.bg, bold = true }, TabLine = { fg = palette.gray, bg = palette.alt_bg }, TabLineSel = { fg = palette.white, bg = palette.alt_bg }, TabLineFill = { fg = palette.white, bg = palette.alt_bg }, diff --git a/lua/no-clown-fiesta/init.lua b/lua/no-clown-fiesta/init.lua index 170a4d2..1cfc291 100644 --- a/lua/no-clown-fiesta/init.lua +++ b/lua/no-clown-fiesta/init.lua @@ -1,10 +1,15 @@ local M = {} -function M.setup(opts) +function M.setup(options) local settings = require "no-clown-fiesta.settings" - if opts then - opts = settings.set(opts) + if options then + settings.set(options) end +end + +function M.load() + local settings = require "no-clown-fiesta.settings" + local options = settings.options vim.api.nvim_command "hi clear" if vim.fn.exists "syntax_on" then @@ -17,7 +22,7 @@ function M.setup(opts) local util = require "no-clown-fiesta.util" local palette = require "no-clown-fiesta.palette" - local highlights = require("no-clown-fiesta.highlights").highlight(palette, opts) + local highlights = require("no-clown-fiesta.highlights").highlight(palette, options) local alpha = require("no-clown-fiesta.highlight-group.alpha").highlight(palette) local git = require("no-clown-fiesta.highlight-group.git").highlight(palette) @@ -40,7 +45,7 @@ function M.setup(opts) ) local treesitter = require("no-clown-fiesta.highlight-group.treesitter").highlight( palette, - opts + options ) local whichkey = require("no-clown-fiesta.highlight-group.whichkey").highlight( palette diff --git a/lua/no-clown-fiesta/palette.lua b/lua/no-clown-fiesta/palette.lua index 911c7e5..246785e 100644 --- a/lua/no-clown-fiesta/palette.lua +++ b/lua/no-clown-fiesta/palette.lua @@ -1,4 +1,5 @@ local colors = { + none = "NONE", fg = "#E1E1E1", bg = "#151515", alt_bg = "#171717", diff --git a/lua/no-clown-fiesta/settings.lua b/lua/no-clown-fiesta/settings.lua index e41380c..78f78ad 100644 --- a/lua/no-clown-fiesta/settings.lua +++ b/lua/no-clown-fiesta/settings.lua @@ -1,17 +1,22 @@ local M = {} -local palette = require "no-clown-fiesta.palette" -local default = { - transparent_background = palette.bg, - comments = "NONE", - keywords = "NONE", - functions = "NONE", - variables = "NONE", - type = "NONE", +local DEFAULT = { + transparent = false, + styles = { + comments = {}, + keywords = {}, + functions = {}, + variables = {}, + type = { bold = true }, + }, } -function M.set(opts) - return vim.tbl_extend("force", default, opts) +M.options = {} + +function M.set(options) + M.options = vim.tbl_deep_extend("force", DEFAULT, options or {}) end +M.set() + return M diff --git a/lua/no-clown-fiesta/util.lua b/lua/no-clown-fiesta/util.lua index 1591a63..46e66d3 100644 --- a/lua/no-clown-fiesta/util.lua +++ b/lua/no-clown-fiesta/util.lua @@ -1,23 +1,7 @@ local M = {} local function highlight(group, properties) - local bg = properties.bg == nil and "" or "guibg=" .. properties.bg - local fg = properties.fg == nil and "" or "guifg=" .. properties.fg - local sp = properties.sp == nil and "" or "guisp=" .. properties.sp - local style = properties.style == nil and "" or "gui=" .. properties.style - local link = properties.link == nil and "" or "link=" .. properties.link - - local cmd = table.concat({ - "highlight", - group, - bg, - fg, - sp, - style, - link, - }, " ") - - vim.api.nvim_command(cmd) + vim.api.nvim_set_hl(0, group, properties) end function M.initialise(skeleton) -- cgit v1.2.3-70-g09d2