From 013c415b57270577e49978dc6e9d985917a2c117 Mon Sep 17 00:00:00 2001 From: Bartek Jaszczak Date: Thu, 23 Jan 2025 16:55:40 +0100 Subject: [PATCH] feat: allow customisations (partially addresses github #2) allow colour overrides allow font style customisations update README --- README.md | 110 ++++++++++++++++++++++++++++++- lua/finale/highlights/syntax.lua | 77 ++++++++++++++-------- lua/finale/init.lua | 29 +++++++- lua/finale/theme.lua | 12 +++- 4 files changed, 195 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 8f87fde..9b8a717 100755 --- a/README.md +++ b/README.md @@ -5,15 +5,16 @@ ## Features - 10 carefully selected accent colours, along with 10 pastel variations -- Supports **treesitter** highlighting as well as **semantic tokens** +- Supports **tree-sitter** highlighting as well as **semantic tokens** - Supports some major plugins (feel free to open an issue if you'd like your plugin supported) - Includes themes for **lualine** and **barbecue** +- Supports colour overrides and some font style customisations (bold, italic) for syntax ## Usage ### Lazy -There are no settings to this theme, so there's no need to call `setup()`. Simply enable and activate the theme: +If you don't want any customisations, there's no need to call `setup()`. Simply enable and activate the theme: ```lua { @@ -27,6 +28,110 @@ There are no settings to this theme, so there's no need to call `setup()`. Simpl } ``` +Colours can be overridden and some formatting (bold, italics) adjusted. You'll need to call `setup()` function for that. + +
+Expand to see configuration options + +### Example configuration + +````lua +{ + "https://gitlab.com/bartekjaszczak/finale-nvim", + + priority = 1000, + + config = function() + require("finale").setup({ + styles = { + -- These are the default styles + comments = { + bold = false, + italic = true, + }, + statements = { + bold = true, + italic = false, + }, -- Statements that are NOT keywords + preproc statements (include, define) but NOT macros + keywords = { + bold = true, + italic = false, + }, + operators = { + bold = false, + italic = false, + }, + }, + colour_overrides = { + -- suggestions = "#FFFFFF", -- Copilot inline suggestions + -- + -- syntax = { + -- text = "#FFFFFF", -- Normal text + -- comment = "#FFFFFF", + -- comment_special = "#FFFFFF", -- Documentation comments + -- + -- string = "#FFFFFF", -- String literals + -- char = "#FFFFFF", -- Character literals + -- stringspecial = "#FFFFFF", -- Regex, escape characters and other special parts of the string + -- + -- constant = "#FFFFFF", -- Constant literals + -- enummember = "#FFFFFF", + -- + -- number = "#FFFFFF", -- Number literals + -- boolean = "#FFFFFF", -- Boolean literals + -- + -- variable = "#FFFFFF", -- Normal variables + -- param = "#FFFFFF", -- Function parameters + -- field = "#FFFFFF", -- Member variables, properties + -- global = "#FFFFFF", -- Global variables + -- static = "#FFFFFF", -- Static variables + -- builtin = "#FFFFFF", -- Built in variables + -- + -- func = "#FFFFFF", -- Functions + -- method = "#FFFFFF", -- Methods + -- + -- statement = "#FFFFFF", -- Statements (usually overridden by another highlight groups, such as keywords, operators, labels, etc.) + -- keyword = "#FFFFFF", + -- keyword_flow = "#FFFFFF", -- Keywords related to execution flow, such as conditionals (if, else), loops (for, while), break, continue, goto, etc. + -- operator = "#FFFFFF", + -- + -- preproc = "#FFFFFF", -- Preprocessor directives + -- + -- type = "#FFFFFF", -- Types + -- type_builtin = "#FFFFFF", -- Built in types, such as int, float, bool (depends on the language) + -- + -- special = "#FFFFFF", -- Special punctuation, parts of comments, special characters in a string, matching parenthesis + -- + -- debug = "#FFFFFF", -- Debugging statements + -- error = "#FFFFFF", -- Errors + -- + -- bracket = "#FFFFFF", -- Brackets: (), {}, [] + -- delimiter = "#FFFFFF", -- Operators such as: +, *, =, sizeof (C/C++), etc. + -- + -- label = "#FFFFFF", -- Labels (cases, default) + -- namespace = "#FFFFFF", + -- module = "#FFFFFF", + -- tag = "#FFFFFF", + -- attribute = "#FFFFFF", + -- + -- h1 = "#FFFFFF", -- Headers (HTML, markup, documentation) + -- h2 = "#FFFFFF", + -- h3 = "#FFFFFF", + -- h4 = "#FFFFFF", + -- h5 = "#FFFFFF", + -- h6 = "#FFFFFF", + -- link = "#FFFFFF", -- Links in HTML, markdown, text + -- }, + }, + }) + + vim.cmd.colorscheme("finale") + end, +} +```` + +
+ ### Lualine ```lua @@ -41,7 +146,6 @@ require("lualine").setup({ ### Barbecue - ```lua require("barbecue").setup({ -- ... diff --git a/lua/finale/highlights/syntax.lua b/lua/finale/highlights/syntax.lua index 7127026..35d0cd9 100755 --- a/lua/finale/highlights/syntax.lua +++ b/lua/finale/highlights/syntax.lua @@ -2,32 +2,56 @@ local M = {} function M.get_highlights(theme) return { - Comment = { fg = theme.syntax.comment, italic = true }, -- (preferred) any constant - Constant = { fg = theme.syntax.constant }, -- (preferred) any constant - String = { fg = theme.syntax.string }, -- a string constant: "this is a string" - Character = { fg = theme.syntax.char }, -- a character constant: 'c', '\n' - Number = { fg = theme.syntax.number }, -- a number constant: 234, 0xff - Boolean = { fg = theme.syntax.boolean }, -- a boolean constant: TRUE, false - Float = { fg = theme.syntax.number }, -- a floating point constant: 2.3e10 - - Identifier = { fg = theme.syntax.variable }, -- (preferred) any variable name - Function = { fg = theme.syntax.func }, -- function name (also: methods for classes) - - Statement = { fg = theme.syntax.statement }, -- (preferred) any statement - -- Conditional = { }, -- if, then, else, endif, switch, etc. - -- Repeat = { }, -- for, do, while, etc. - Label = { fg = theme.syntax.label }, -- case, default, etc. - Operator = { fg = theme.syntax.operator }, -- "sizeof", "+", "*", etc. - Keyword = { fg = theme.syntax.keyword, bold = true }, -- any other keyword + Comment = { + fg = theme.syntax.comment, + bold = theme.styles.comments.bold, + italic = theme.styles.comments.italic, + }, -- (preferred) any constant + Constant = { fg = theme.syntax.constant }, -- (preferred) any constant + String = { fg = theme.syntax.string }, -- a string constant: "this is a string" + Character = { fg = theme.syntax.char }, -- a character constant: 'c', '\n' + Number = { fg = theme.syntax.number }, -- a number constant: 234, 0xff + Boolean = { fg = theme.syntax.boolean }, -- a boolean constant: TRUE, false + Float = { fg = theme.syntax.number }, -- a floating point constant: 2.3e10 + + Identifier = { fg = theme.syntax.variable }, -- (preferred) any variable name + Function = { fg = theme.syntax.func }, -- function name (also: methods for classes) + + Statement = { + fg = theme.syntax.statement, + bold = theme.styles.statements.bold, + italic = theme.styles.statements.italic, + }, -- (preferred) any statement + Conditional = { + fg = theme.syntax.keyword_flow, + bold = theme.styles.keywords.bold, + italic = theme.styles.keywords.italic, + }, -- if, then, else, endif, switch, etc. + Repeat = { link = "Conditional" }, -- for, do, while, etc. + Label = { + fg = theme.syntax.label, + bold = theme.styles.statements.bold, + italic = theme.styles.statements.italic, + }, -- case, default, etc. + Operator = { + fg = theme.syntax.operator, + bold = theme.styles.operators.bold, + italic = theme.styles.operators.italic, + }, -- "sizeof", "+", "*", etc. + Keyword = { + fg = theme.syntax.keyword, + bold = theme.styles.keywords.bold, + italic = theme.styles.keywords.italic, + }, -- any other keyword -- Exception = { }, -- try, catch, throw - PreProc = { fg = theme.syntax.keyword }, -- (preferred) generic Preprocessor + PreProc = { link = "Statement" }, -- (preferred) generic Preprocessor -- Include = { }, -- preprocessor #include -- Define = {}, -- preprocessor #define Macro = { fg = theme.syntax.preproc }, -- same as Define -- PreCondit = { }, -- preprocessor #if, #else, #endif, etc. - Type = { fg = theme.syntax.type }, -- (preferred) int, long, char, etc. - StorageClass = { fg = theme.syntax.keyword }, -- static, register, volatile, etc. + Type = { fg = theme.syntax.type }, -- (preferred) int, long, char, etc. + StorageClass = { link = "Statement" }, -- static, register, volatile, etc. -- Structure = { }, -- struct, union, enum, etc. -- Typedef = { }, -- A typedef @@ -196,22 +220,23 @@ function M.get_highlights(theme) ["@function.method"] = { fg = theme.syntax.method }, -- ["@function.method.call"] = {}, - ["@constructor"] = { fg = theme.syntax.method }, -- For constructor calls and definitions: `= { }` in Lua, and Java constructors. - ["@operator"] = { fg = theme.syntax.operator }, -- For any operator: `+`, but also `->` and `*` in C. + ["@constructor"] = { fg = theme.syntax.method }, -- For constructor calls and definitions: `= { }` in Lua, and Java constructors. + ["@operator"] = { link = "Operator" }, -- For any operator: `+`, but also `->` and `*` in C. - ["@keyword"] = { fg = theme.syntax.keyword, bold = true }, -- For keywords that don't fall in previous categories. + ["@keyword"] = { link = "Keyword" }, -- For keywords that don't fall in previous categories. -- ["@keyword.coroutine"] = {}, -- ["@keyword.function"] = {}, -- ["@keyword.operator"] = {}, -- ["@keyword.import"] = {}, -- ["@keyword.type"] = {}, -- ["@keyword.modifier"] = {}, - ["@keyword.repeat"] = { fg = theme.syntax.keyword_flow, bold = true }, - ["@keyword.return"] = { fg = theme.syntax.keyword_flow, bold = true }, + ["@keyword.repeat"] = { link = "Conditional" }, + ["@keyword.return"] = { link = "Conditional" }, -- ["@keyword.debug"] = {}, -- ["@keyword.exception"] = {}, - ["@keyword.conditional"] = { fg = theme.syntax.keyword_flow, bold = true }, + ["@keyword.conditional"] = { link = "Conditional" }, + -- ["@keyword.conditional.ternary"] = {}, -- ["@keyword.directive"] = {}, diff --git a/lua/finale/init.lua b/lua/finale/init.lua index 7d3d0e5..2e22bc3 100755 --- a/lua/finale/init.lua +++ b/lua/finale/init.lua @@ -1,5 +1,32 @@ local M = {} +M.options = { + styles = { + comments = { + bold = false, + italic = true, + }, + statements = { + bold = true, + italic = false, + }, -- Statements that are NOT keywords + preproc statements (include, define) but NOT macros + keywords = { + bold = true, + italic = false, + }, + operators = { + bold = false, + italic = false, + }, + }, + colour_overrides = {}, +} + +function M.setup(opts) + opts = opts or {} + M.options = vim.tbl_deep_extend("force", M.options, opts) +end + local function set_highlights(theme) local highlights = require("finale.highlights").get_highlights(theme) for hl, opts in pairs(highlights) do @@ -23,7 +50,7 @@ function M.load() -- Enable highlights local colours = require("finale.colours") local theme = require("finale.theme") - theme = theme.get_theme(colours) + theme = theme.get_theme(colours, M.options) set_highlights(theme) end diff --git a/lua/finale/theme.lua b/lua/finale/theme.lua index 8c5bb48..4155bce 100755 --- a/lua/finale/theme.lua +++ b/lua/finale/theme.lua @@ -1,7 +1,7 @@ local M = {} -function M.get_theme(colours) - return { +function M.get_theme(colours, opts) + local theme = { none = "NONE", -- UI elements @@ -28,7 +28,6 @@ function M.get_theme(colours) -- Special colour special_accent_weak = colours.pastel.pink, special_accent_strong = colours.main.pink, - }, diag = { @@ -120,6 +119,13 @@ function M.get_theme(colours) link = colours.pastel.blue, }, } + + if opts then + theme = vim.tbl_deep_extend("force", theme, opts.colour_overrides) + theme.styles = opts.styles + end + + return theme end return M