From d1c3eb0409fc74dc685e6d2a576d2004f0113ab8 Mon Sep 17 00:00:00 2001 From: Null Chilly <56817415+nullchilly@users.noreply.github.com> Date: Fri, 18 Nov 2022 04:47:26 +0700 Subject: [PATCH] feat: add vim support (#340) --- README.md | 8 +- autoload/clap/themes/catppuccin.vim | 21 +++- autoload/lightline/colorscheme/catppuccin.vim | 22 +++- colors/catppuccin-frappe.lua | 1 - colors/catppuccin-frappe.vim | 1 + colors/catppuccin-latte.lua | 1 - colors/catppuccin-latte.vim | 1 + colors/catppuccin-macchiato.lua | 1 - colors/catppuccin-macchiato.vim | 1 + colors/catppuccin-mocha.lua | 1 - colors/catppuccin-mocha.vim | 1 + colors/catppuccin.lua | 1 - colors/catppuccin.vim | 1 + doc/catppuccin.txt | 10 +- .../groups/integrations/treesitter.lua | 34 +++--- lua/catppuccin/groups/syntax.lua | 53 ++++----- lua/catppuccin/init.lua | 11 +- lua/catppuccin/lib/vim/compiler.lua | 58 ++++++++++ lua/catppuccin/lib/vim/init.lua | 109 ++++++++++++++++++ lua/catppuccin/utils/clap.lua | 19 --- lua/catppuccin/utils/lightline.lua | 37 ------ 21 files changed, 269 insertions(+), 123 deletions(-) delete mode 100644 colors/catppuccin-frappe.lua create mode 100644 colors/catppuccin-frappe.vim delete mode 100644 colors/catppuccin-latte.lua create mode 100644 colors/catppuccin-latte.vim delete mode 100644 colors/catppuccin-macchiato.lua create mode 100644 colors/catppuccin-macchiato.vim delete mode 100644 colors/catppuccin-mocha.lua create mode 100644 colors/catppuccin-mocha.vim delete mode 100644 colors/catppuccin.lua create mode 100644 colors/catppuccin.vim create mode 100644 lua/catppuccin/lib/vim/compiler.lua create mode 100644 lua/catppuccin/lib/vim/init.lua delete mode 100644 lua/catppuccin/utils/clap.lua delete mode 100644 lua/catppuccin/utils/lightline.lua diff --git a/README.md b/README.md index 8fef393..15e48b0 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,7 @@ vim.cmd.colorscheme "catppuccin" # Configuration -You may pass a lua table to the setup() function in order to edit any of Catppuccin's settings: +There is no need to call `setup` if you don't want to change the default options and settings. ```lua require("catppuccin").setup({ @@ -155,10 +155,14 @@ require("catppuccin").setup({ gitsigns = true, nvimtree = true, telescope = true, - treesitter = true, + notify = false, + mini = false, -- For more plugins integrations please scroll down (https://github.com/catppuccin/nvim#integrations) }, }) + +-- setup must be called before loading +vim.cmd.colorscheme "catppuccin" ``` Although settings already have self-explanatory names, here is where you can find info about each one of them and their classifications! diff --git a/autoload/clap/themes/catppuccin.vim b/autoload/clap/themes/catppuccin.vim index 3b1443c..16efd50 100644 --- a/autoload/clap/themes/catppuccin.vim +++ b/autoload/clap/themes/catppuccin.vim @@ -1 +1,20 @@ -let g:clap#themes#catppuccin#palette = luaeval('require("catppuccin.utils.clap")') \ No newline at end of file +let s:c = has("nvim") == 1 ? luaeval('require("catppuccin.palettes").get_palette()') : luaeval('vim.dict(require("catppuccin.palettes").get_palette())') + +let s:p = {} + +let s:p.display = { 'guibg': s:c.mantle } + +let s:p.input = s:p.display +let s:p.indicator = { 'guifg': s:c.subtext1, 'guibg': s:c.mantle } +let s:p.spinner = { 'guifg': s:c.yellow, 'guibg': s:c.mantle, 'gui': "bold" } +let s:p.search_text = { 'guifg': s:c.text, 'guibg': s:c.mantle, 'gui': "bold" } + +let s:p.preview = { 'guibg': s:c.base } + +let s:p.selected = { 'guifg': s:c.sapphire, 'gui': "bold,underline" } +let s:p.current_selection = { 'guibg': s:c.surface0, 'gui': "bold" } + +let s:p.selected_sign = { 'guifg': s:c.red } +let s:p.current_selection_sign = copy(s:p.selected_sign) + +let g:clap#themes#catppuccin#palette = s:p diff --git a/autoload/lightline/colorscheme/catppuccin.vim b/autoload/lightline/colorscheme/catppuccin.vim index 23bc4e6..a3cdc62 100644 --- a/autoload/lightline/colorscheme/catppuccin.vim +++ b/autoload/lightline/colorscheme/catppuccin.vim @@ -1,2 +1,20 @@ -let g:lightline#colorscheme#catppuccin#palette = lightline#colorscheme#fill( - \ luaeval('require("catppuccin.utils.lightline")')) \ No newline at end of file +let s:c = has("nvim") == 1 ? luaeval('require("catppuccin.palettes").get_palette()') : luaeval('vim.dict(require("catppuccin.palettes").get_palette())') + +let s:p = {'normal': {}, 'inactive': {}, 'insert': {}, 'replace': {}, 'visual': {}, 'tabline': {}} +let s:p.normal.left = [ [ s:c.mantle, s:c.blue ], [ s:c.blue, s:c.base ] ] +let s:p.normal.right = [ [ s:c.overlay0, s:c.base ], [ s:c.blue, s:c.surface0 ] ] +let s:p.inactive.right = [ [ s:c.surface1, s:c.base ], [ s:c.overlay0, s:c.base ] ] +let s:p.inactive.left = [ [ s:c.blue, s:c.base ], [ s:c.overlay0, s:c.base ] ] +let s:p.insert.left = [ [ s:c.mantle, s:c.teal ], [ s:c.blue, s:c.base ] ] +let s:p.replace.left = [ [ s:c.mantle, s:c.red ], [ s:c.blue, s:c.base ] ] +let s:p.visual.left = [ [ s:c.mantle, s:c.mauve ], [ s:c.blue, s:c.base ] ] +let s:p.normal.middle = [ [ s:c.blue, s:c.surface1 ] ] +let s:p.inactive.middle = [ [ s:c.surface1, s:c.base ] ] +let s:p.tabline.left = [ [ s:c.overlay0, s:c.base ], [ s:c.overlay0, s:c.base ] ] +let s:p.tabline.tabsel = [ [ s:c.blue, s:c.surface1 ], [ s:c.overlay0, s:c.base] ] +let s:p.tabline.middle = [ [ s:c.surface1, s:c.base ] ] +let s:p.tabline.right = copy(s:p.inactive.right) +let s:p.normal.error = [ [ s:c.mantle, s:c.red ] ] +let s:p.normal.warning = [ [ s:c.mantle, s:c.yellow ] ] + +let g:lightline#colorscheme#catppuccin#palette = lightline#colorscheme#fill(s:p) diff --git a/colors/catppuccin-frappe.lua b/colors/catppuccin-frappe.lua deleted file mode 100644 index 48b6096..0000000 --- a/colors/catppuccin-frappe.lua +++ /dev/null @@ -1 +0,0 @@ -require("catppuccin").load "frappe" diff --git a/colors/catppuccin-frappe.vim b/colors/catppuccin-frappe.vim new file mode 100644 index 0000000..c9fd8d5 --- /dev/null +++ b/colors/catppuccin-frappe.vim @@ -0,0 +1 @@ +lua require("catppuccin").load "frappe" diff --git a/colors/catppuccin-latte.lua b/colors/catppuccin-latte.lua deleted file mode 100644 index a2f88b8..0000000 --- a/colors/catppuccin-latte.lua +++ /dev/null @@ -1 +0,0 @@ -require("catppuccin").load "latte" diff --git a/colors/catppuccin-latte.vim b/colors/catppuccin-latte.vim new file mode 100644 index 0000000..6d87782 --- /dev/null +++ b/colors/catppuccin-latte.vim @@ -0,0 +1 @@ +lua require("catppuccin").load "latte" diff --git a/colors/catppuccin-macchiato.lua b/colors/catppuccin-macchiato.lua deleted file mode 100644 index eae599a..0000000 --- a/colors/catppuccin-macchiato.lua +++ /dev/null @@ -1 +0,0 @@ -require("catppuccin").load "macchiato" diff --git a/colors/catppuccin-macchiato.vim b/colors/catppuccin-macchiato.vim new file mode 100644 index 0000000..cc4f005 --- /dev/null +++ b/colors/catppuccin-macchiato.vim @@ -0,0 +1 @@ +lua require("catppuccin").load "macchiato" diff --git a/colors/catppuccin-mocha.lua b/colors/catppuccin-mocha.lua deleted file mode 100644 index a763bdb..0000000 --- a/colors/catppuccin-mocha.lua +++ /dev/null @@ -1 +0,0 @@ -require("catppuccin").load "mocha" diff --git a/colors/catppuccin-mocha.vim b/colors/catppuccin-mocha.vim new file mode 100644 index 0000000..4e6a300 --- /dev/null +++ b/colors/catppuccin-mocha.vim @@ -0,0 +1 @@ +lua require("catppuccin").load "mocha" diff --git a/colors/catppuccin.lua b/colors/catppuccin.lua deleted file mode 100644 index de89880..0000000 --- a/colors/catppuccin.lua +++ /dev/null @@ -1 +0,0 @@ -require("catppuccin").load() diff --git a/colors/catppuccin.vim b/colors/catppuccin.vim new file mode 100644 index 0000000..916847b --- /dev/null +++ b/colors/catppuccin.vim @@ -0,0 +1 @@ +lua require("catppuccin").load() diff --git a/doc/catppuccin.txt b/doc/catppuccin.txt index 0167693..0691f8c 100644 --- a/doc/catppuccin.txt +++ b/doc/catppuccin.txt @@ -65,8 +65,8 @@ Table of Contents *catppuccin-table-of-contents* ============================================================================== 4. Configuration *catppuccin-configuration* -You may pass a lua table to the setup() function in order to edit any of -Catppuccin’s settings: +There is no need to call `setup` if you don’t want to change the default +options and settings. > require("catppuccin").setup({ @@ -104,10 +104,14 @@ Catppuccin’s settings: gitsigns = true, nvimtree = true, telescope = true, - treesitter = true, + notify = false, + mini = false, -- For more plugins integrations please scroll down (https://github.com/catppuccin/nvim#integrations) }, }) + + -- setup must be called before loading + vim.cmd.colorscheme "catppuccin" < diff --git a/lua/catppuccin/groups/integrations/treesitter.lua b/lua/catppuccin/groups/integrations/treesitter.lua index 8799e10..a8436bb 100644 --- a/lua/catppuccin/groups/integrations/treesitter.lua +++ b/lua/catppuccin/groups/integrations/treesitter.lua @@ -1,12 +1,6 @@ local M = {} function M.get() - local operators = cp.sky - local cl = cp.mauve -- conditionals, loops - local keywords = cp.mauve - - local math_logic = cp.peach - if vim.treesitter.highlighter.hl_map then vim.notify( [[Catppuccin (info): @@ -25,7 +19,7 @@ If you want to stay on nvim 0.7, either disable the integration or pin catppucci ["@error"] = { link = "Error" }, ["@preproc"] = { link = "PreProc" }, -- various preprocessor directives & shebangs ["@define"] = { link = "Define" }, -- preprocessor definition directives - ["@operator"] = { fg = operators, style = cnf.styles.operators or {} }, -- For any operator: +, but also -> and * in cp. + ["@operator"] = { link = "Operator" }, -- For any operator: +, but also -> and * in cp. -- Punctuation ["@punctuation.delimiter"] = { fg = cp.overlay2 }, -- For delimiters ie: . @@ -33,7 +27,7 @@ If you want to stay on nvim 0.7, either disable the integration or pin catppucci ["@punctuation.special"] = { fg = cp.sky, style = cnf.styles.operators or {} }, -- For special punctutation that does not fall in the catagories before. -- Literals - ["@string"] = { fg = cp.green, style = cnf.styles.strings or {} }, -- For strings. + ["@string"] = { link = "String" }, -- For strings. ["@string.regex"] = { fg = cp.peach, style = cnf.styles.strings or {} }, -- For regexes. ["@string.escape"] = { fg = cp.pink, style = cnf.styles.strings }, -- For escape characters within a string. ["@string.special"] = { fg = cp.blue }, -- other special strings (e.g. dates) @@ -41,12 +35,12 @@ If you want to stay on nvim 0.7, either disable the integration or pin catppucci ["@character"] = { link = "Character" }, -- character literals ["@character.special"] = { link = "SpecialChar" }, -- special characters (e.g. wildcards) - ["@boolean"] = { fg = math_logic, style = cnf.styles.booleans or {} }, -- For booleans. - ["@number"] = { fg = math_logic, style = cnf.styles.numbers or {} }, -- For all numbers - ["@float"] = { fg = math_logic, style = cnf.styles.numbers or {} }, -- For floats. + ["@boolean"] = { link = "Boolean" }, -- For booleans. + ["@number"] = { link = "Number" }, -- For all numbers + ["@float"] = { link = "Number" }, -- For floats. -- Functions - ["@function"] = { fg = cp.blue, style = cnf.styles.functions or {} }, -- For function (calls and definitions). + ["@function"] = { link = "Function" }, -- For function (calls and definitions). ["@function.builtin"] = { fg = cp.peach, style = cnf.styles.functions or {} }, -- For builtin functions: table.insert in Lua. ["@function.call"] = { link = "@function" }, -- function calls ["@function.macro"] = { fg = cp.teal, style = cnf.styles.functions or {} }, -- For macro defined functions (calls and definitions): each macro_rules in Ruscp. @@ -58,21 +52,21 @@ If you want to stay on nvim 0.7, either disable the integration or pin catppucci ["@parameter"] = { fg = cp.maroon, style = { "italic" } }, -- For parameters of a function. -- Keywords - ["@keyword"] = { fg = keywords, style = cnf.styles.keywords or {} }, -- For keywords that don't fall in previous categories. + ["@keyword"] = { link = "Keyword" }, -- For keywords that don't fall in previous categories. ["@keyword.function"] = { fg = cp.mauve, style = cnf.styles.keywords or {} }, -- For keywords used to define a fuction. ["@keyword.operator"] = { fg = cp.mauve, style = cnf.styles.operators or {} }, -- For new keyword operator ["@keyword.return"] = { fg = cp.mauve, style = cnf.styles.keywords or {} }, - ["@conditional"] = { fg = cl, style = cnf.styles.conditionals or {} }, -- For keywords related to conditionnals. - ["@repeat"] = { fg = cl, style = cnf.styles.loops or {} }, -- For keywords related to loops. + ["@conditional"] = { link = "Conditional" }, -- For keywords related to conditionnals. + ["@repeat"] = { link = "Repeat" }, -- For keywords related to loops. -- @debug ; keywords related to debugging - ["@label"] = { fg = cp.sapphire }, -- For labels: label: in C and :label: in Lua. - ["@include"] = { fg = cp.mauve, style = cnf.styles.keywords or {} }, -- For includes: #include in C, use or extern crate in Rust, or require in Lua. + ["@label"] = { link = "Label" }, -- For labels: label: in C and :label: in Lua. + ["@include"] = { link = "Include" }, -- For includes: #include in C, use or extern crate in Rust, or require in Lua. ["@exception"] = { fg = cp.mauve, style = cnf.styles.keywords or {} }, -- For exception related keywords. -- Types - ["@type"] = { fg = cp.yellow, style = cnf.styles.types or {} }, -- For types. + ["@type"] = { link = "Type" }, -- For types. ["@type.builtin"] = { fg = cp.yellow, style = cnf.styles.properties or "italic" }, -- For builtin types. ["@type.definition"] = { link = "@type" }, -- type definitions (e.g. `typedef` in C) ["@type.qualifier"] = { link = "@type" }, -- type qualifiers (e.g. `const`) @@ -84,12 +78,12 @@ If you want to stay on nvim 0.7, either disable the integration or pin catppucci -- Identifiers - ["@variable"] = { fg = cp.text, style = cnf.styles.variables or {} }, -- Any variable name that does not have another highlighcp. + ["@variable"] = { link = "Identifiers" }, -- Any variable name that does not have another highlighcp. ["@variable.builtin"] = { fg = cp.red }, -- Variable names that are defined by the languages, like this or self. ["@constant"] = { fg = cp.peach }, -- For constants ["@constant.builtin"] = { fg = cp.peach, style = cnf.styles.keywords or {} }, -- For constant that are built in the language: nil in Lua. - ["@constant.macro"] = { fg = cp.mauve }, -- For constants that are defined by macros: NULL in cp. + ["@constant.macro"] = { link = "Macro" }, -- For constants that are defined by macros: NULL in cp. ["@namespace"] = { fg = cp.blue, style = { "italic" } }, -- For identifiers referring to modules and namespaces. ["@symbol"] = { fg = cp.flamingo }, diff --git a/lua/catppuccin/groups/syntax.lua b/lua/catppuccin/groups/syntax.lua index c6cbdfc..10a1f89 100644 --- a/lua/catppuccin/groups/syntax.lua +++ b/lua/catppuccin/groups/syntax.lua @@ -3,38 +3,39 @@ local M = {} function M.get() return { Comment = { fg = cp.surface2, style = cnf.styles.comments }, -- just comments + SpecialComment = { link = "Special" }, -- special things inside a comment Constant = { fg = cp.peach }, -- (preferred) any constant - String = { fg = cp.green, style = cnf.styles.strings }, -- a string constant: "this is a string" + String = { fg = cp.green, style = cnf.styles.strings or {} }, -- a string constant: "this is a string" Character = { fg = cp.teal }, -- a character constant: 'c', '\n' - Number = { fg = cp.peach }, -- a number constant: 234, 0xff - Float = { fg = cp.peach }, -- a floating point constant: 2.3e10 - Boolean = { fg = cp.peach }, -- a boolean constant: TRUE, false - Identifier = { fg = cp.flamingo, style = cnf.styles.variables }, -- (preferred) any variable name - Function = { fg = cp.blue, style = cnf.styles.functions }, -- function name (also: methods for classes) + Number = { fg = cp.peach, style = cnf.styles.numbers or {} }, -- a number constant: 234, 0xff + Float = { fg = cp.peach, style = cnf.styles.numbers or {} }, -- a floating point constant: 2.3e10 + Boolean = { fg = cp.peach, style = cnf.styles.booleans or {} }, -- a boolean constant: TRUE, false + Identifier = { fg = cp.text, style = cnf.styles.variables or {} }, -- (preferred) any variable name + Function = { fg = cp.blue, style = cnf.styles.functions or {} }, -- function name (also: methods for classes) Statement = { fg = cp.mauve }, -- (preferred) any statement - Conditional = { fg = cp.red }, -- if, then, else, endif, switch, etcp. - Repeat = { fg = cp.red }, -- for, do, while, etcp. - Label = { fg = cp.peach }, -- case, default, etcp. - Operator = { fg = cp.sky }, -- "sizeof", "+", "*", etcp. - Keyword = { fg = cp.pink, style = cnf.styles.keywords }, -- any other keyword + Conditional = { fg = cp.mauve, style = cnf.styles.conditionals or {} }, -- if, then, else, endif, switch, etcp. + Repeat = { fg = cp.mauve, style = cnf.styles.loops or {} }, -- for, do, while, etcp. + Label = { fg = cp.sapphire }, -- case, default, etcp. + Operator = { fg = cp.sky, style = cnf.styles.operators or {} }, -- "sizeof", "+", "*", etcp. + Keyword = { fg = cp.mauve, style = cnf.styles.keywords or {} }, -- any other keyword -- Exception = { }, -- try, catch, throw PreProc = { fg = cp.pink }, -- (preferred) generic Preprocessor - Include = { fg = cp.pink }, -- preprocessor #include - -- Define = { }, -- preprocessor #define - -- Macro = { }, -- same as Define - -- PreCondit = { }, -- preprocessor #if, #else, #endif, etcp. + Include = { fg = cp.mauve, style = cnf.styles.keywords or {} }, -- preprocessor #include + Define = { link = "PreProc" }, -- preprocessor #define + Macro = { fg = cp.mauve }, -- same as Define + PreCondit = { link = "PreProc" }, -- preprocessor #if, #else, #endif, etc. StorageClass = { fg = cp.yellow }, -- static, register, volatile, etcp. Structure = { fg = cp.yellow }, -- struct, union, enum, etcp. - Typedef = { fg = cp.yellow }, -- A typedef Special = { fg = cp.pink }, -- (preferred) any special symbol - Type = { fg = cp.blue }, -- (preferred) int, long, char, etcp. - -- SpecialChar = { }, -- special character in a constant - -- Tag = { }, -- you can use CTRL-] on this - -- Delimiter = { }, -- character that needs attention + Type = { fg = cp.yellow, style = cnf.styles.types or {} }, -- (preferred) int, long, char, etcp. + Typedef = { link = "Type" }, -- A typedef + SpecialChar = { link = "Special" }, -- special character in a constant + Tag = { link = "Special" }, -- you can use CTRL-] on this + Delimiter = { link = "Special" }, -- character that needs attention -- Specialoverlay0= { }, -- special things inside a overlay0 - -- Debug = { }, -- debugging statements + Debug = { link = "Special" }, -- debugging statements Underlined = { style = { "underline" } }, -- (preferred) text that stands out, HTML links Bold = { style = { "bold" } }, @@ -88,16 +89,6 @@ function M.get() GlyphPalette6 = { fg = cp.teal }, GlyphPalette7 = { fg = cp.text }, GlyphPalette9 = { fg = cp.red }, - - Define = { link = "PreProc" }, -- preprocessor #define - Macro = { link = "PreProc" }, -- same as Define - PreCondit = { link = "PreProc" }, -- preprocessor #if, #else, #endif, etc. - - SpecialChar = { link = "Special" }, -- special character in a constant - Tag = { link = "Special" }, -- you can use CTRL-] on this - Delimiter = { link = "Special" }, -- character that needs attention - SpecialComment = { link = "Special" }, -- special things inside a comment - Debug = { link = "Special" }, -- debugging statements } end diff --git a/lua/catppuccin/init.lua b/lua/catppuccin/init.lua index b4682dc..cb19e14 100644 --- a/lua/catppuccin/init.lua +++ b/lua/catppuccin/init.lua @@ -1,3 +1,6 @@ +local is_vim = vim.fn.has "nvim" ~= 1 +if is_vim then require "catppuccin.lib.vim" end + local M = { flavours = { "latte", "frappe", "macchiato", "mocha" }, options = { @@ -28,7 +31,7 @@ local M = { operators = {}, }, integrations = { - treesitter = true, + treesitter = not is_vim, cmp = true, gitsigns = true, telescope = true, @@ -58,12 +61,12 @@ local M = { color_overrides = {}, highlight_overrides = {}, }, - path_sep = ((jit and jit.os or nil) == "Windows") and "\\" or "/", + path_sep = jit and (jit.os == "Windows" and "\\" or "/") or package.config:sub(1, 1), } function M.compile() for _, flavour in pairs(M.flavours) do - require("catppuccin.lib.compiler").compile(flavour) + require("catppuccin.lib." .. (is_vim and "vim." or "") .. "compiler").compile(flavour) end end @@ -146,6 +149,8 @@ function M.setup(user_conf) end end +if is_vim then return M end + vim.api.nvim_create_user_command("Catppuccin", function(inp) if not vim.tbl_contains(M.flavours, inp.args) then vim.notify( diff --git a/lua/catppuccin/lib/vim/compiler.lua b/lua/catppuccin/lib/vim/compiler.lua new file mode 100644 index 0000000..cc2f216 --- /dev/null +++ b/lua/catppuccin/lib/vim/compiler.lua @@ -0,0 +1,58 @@ +local C = require "catppuccin" +local config = C.options +local M = {} + +-- Reference: https://github.com/EdenEast/nightfox.nvim +local fmt = string.format + +function M.compile(flavour) + local theme = require("catppuccin.lib.mapper").apply(flavour) + local lines = { + [[ +require("catppuccin").compiled = string.dump(function() +if vim.g.colors_name then vim.cmd("hi clear") end +vim.o.termguicolors = true +vim.g.colors_name = "catppuccin"]], + } + table.insert(lines, "vim.o.background = " .. (flavour == "latte" and [["light"]] or [["dark"]])) + + local tbl = vim.tbl_deep_extend("keep", theme.custom_highlights, theme.integrations, theme.syntax, theme.editor) + + if config.term_colors == true then + for k, v in pairs(theme.terminal) do + table.insert(lines, fmt('vim.g.%s = "%s"', k, v)) + end + end + + table.insert(lines, "vim.cmd[[") + + for group, color in pairs(tbl) do + if color.link then + table.insert(lines, fmt([[highlight! link %s %s]], group, color.link)) + else + if color.style then color.style = table.concat(color.style, ",") end + if color.style == "" then color.style = nil end + table.insert( + lines, + fmt( + [[highlight %s guifg=%s guibg=%s gui=%s guisp=%s]], + group, + color.fg or "NONE", + color.bg or "NONE", + color.style or "NONE", + color.sp or "NONE" + ) + ) + end + end + table.insert(lines, "]]end)") + if vim.fn.isdirectory(config.compile_path) == 0 then + os.execute(string.format("mkdir %s %s", C.is_windows and "" or "-p", config.compile_path)) + end + local file = io.open(config.compile_path .. C.path_sep .. flavour .. "_compiled.lua", "wb") + loadstring(table.concat(lines, "\n"), "=")() + file:write(require("catppuccin").compiled) + file:close() +end + +return M diff --git a/lua/catppuccin/lib/vim/init.lua b/lua/catppuccin/lib/vim/init.lua new file mode 100644 index 0000000..edb64e8 --- /dev/null +++ b/lua/catppuccin/lib/vim/init.lua @@ -0,0 +1,109 @@ +-- TODO: private _G.vim +vim.cmd = vim.command +vim.cmd [[command! CatppuccinCompile lua require('catppuccin').compile() print("Catppuccin (info): compiled cache!")]] +loadstring = load or loadstring +bit = bit32 or { + rshift = function(a, b) return a >> b end, + bxor = function(a, b) return a ~ b end, +} + +local function get_option(name, _) return vim.eval("&" .. name) end + +local function set_option(name, opt, _) + if type(opt) == "boolean" then + vim.cmd("set " .. name) + else + vim.cmd("set " .. name .. "=" .. opt) + end +end + +vim.o = setmetatable({}, { + __index = function(_, k) return get_option(k, {}) end, + __newindex = function(_, k, v) return set_option(k, v, {}) end, +}) + +vim.fn.stdpath = function(what) + if what ~= "cache" then return end + if package.config:sub(1, 1) == "\\" then + return vim.fn.expand "%localappdata%" .. [[Temp\vim]] + else + return (os.getenv "XDG_CACHE_HOME" or vim.fn.expand "$HOME/.cache") .. "/vim" + end +end + +vim.loop = { + fs_stat = function(file) + local mod = vim.fn.getftime(file) + if mod == -1 then return nil end + return { mtime = { sec = mod } } + end, +} + +-- Reference: https://github.com/neovim/neovim/blob/master/runtime/lua/vim/shared.lua +function vim.tbl_isempty(t) + assert(type(t) == "table", string.format("Expected table, got %s", type(t))) + return next(t) == nil +end + +function vim.tbl_islist(t) + if type(t) ~= "table" then return false end + + local count = 0 + + for k, _ in pairs(t) do + if type(k) == "number" then + count = count + 1 + else + return false + end + end + + if count > 0 then + return true + else + -- TODO(bfredl): in the future, we will always be inside nvim + -- then this check can be deleted. + if vim._empty_dict_mt == nil then return false end + return getmetatable(t) ~= vim._empty_dict_mt + end +end + +local function can_merge(v) return type(v) == "table" and (vim.tbl_isempty(v) or not vim.tbl_islist(v)) end + +function vim.tbl_contains(t, value) + for _, v in ipairs(t) do + if v == value then return true end + end + return false +end + +local function tbl_extend(behavior, deep_extend, ...) + if behavior ~= "error" and behavior ~= "keep" and behavior ~= "force" then + error('invalid "behavior": ' .. tostring(behavior)) + end + + if select("#", ...) < 2 then + error("wrong number of arguments (given " .. tostring(1 + select("#", ...)) .. ", expected at least 3)") + end + + local ret = {} + if vim._empty_dict_mt ~= nil and getmetatable(select(1, ...)) == vim._empty_dict_mt then ret = vim.empty_dict() end + + for i = 1, select("#", ...) do + local tbl = select(i, ...) + if tbl then + for k, v in pairs(tbl) do + if deep_extend and can_merge(v) and can_merge(ret[k]) then + ret[k] = tbl_extend(behavior, true, ret[k], v) + elseif behavior ~= "force" and ret[k] ~= nil then + if behavior == "error" then error("key found in more than one map: " .. k) end -- Else behavior is "keep". + else + ret[k] = v + end + end + end + end + return ret +end + +function vim.tbl_deep_extend(behavior, ...) return tbl_extend(behavior, true, ...) end diff --git a/lua/catppuccin/utils/clap.lua b/lua/catppuccin/utils/clap.lua deleted file mode 100644 index a21b671..0000000 --- a/lua/catppuccin/utils/clap.lua +++ /dev/null @@ -1,19 +0,0 @@ -local cp = require("catppuccin.palettes").get_palette() -local catppuccin = {} - -catppuccin.display = { guibg = cp.mantle } - -catppuccin.input = catppuccin.display -catppuccin.indicator = { guifg = cp.subtext1, guibg = cp.mantle } -catppuccin.spinner = { guifg = cp.yellow, guibg = cp.mantle, gui = "bold" } -catppuccin.search_text = { guifg = cp.text, guibg = cp.mantle, gui = "bold" } - -catppuccin.preview = { guibg = cp.base } - -catppuccin.selected = { guifg = cp.sapphire, gui = "bold,underline" } -catppuccin.current_selection = { guibg = cp.surface0, gui = "bold" } - -catppuccin.selected_sign = { guifg = cp.red } -catppuccin.current_selection_sign = catppuccin.selected_sign - -return catppuccin diff --git a/lua/catppuccin/utils/lightline.lua b/lua/catppuccin/utils/lightline.lua deleted file mode 100644 index 5b75889..0000000 --- a/lua/catppuccin/utils/lightline.lua +++ /dev/null @@ -1,37 +0,0 @@ -local cp = require("catppuccin.palettes").get_palette() -local catppuccin = {} - -catppuccin.normal = { - left = { { cp.mantle, cp.blue }, { cp.blue, cp.base } }, - middle = { { cp.blue, cp.surface1 } }, - right = { { cp.overlay0, cp.base }, { cp.blue, cp.surface0 } }, - error = { { cp.mantle, cp.red } }, - warning = { { cp.mantle, cp.yellow } }, -} - -catppuccin.insert = { - left = { { cp.mantle, cp.teal }, { cp.blue, cp.base } }, -} - -catppuccin.visual = { - left = { { cp.mantle, cp.mauve }, { cp.blue, cp.base } }, -} - -catppuccin.replace = { - left = { { cp.mantle, cp.red }, { cp.blue, cp.base } }, -} - -catppuccin.inactive = { - left = { { cp.blue, cp.base }, { cp.overlay0, cp.base } }, - middle = { { cp.surface1, cp.base } }, - right = { { cp.surface1, cp.base }, { cp.overlay0, cp.base } }, -} - -catppuccin.tabline = { - left = { { cp.overlay0, cp.base }, { cp.overlay0, cp.base } }, - middle = { { cp.surface1, cp.base } }, - right = { { cp.surface1, cp.base }, { cp.overlay0, cp.base } }, - tabsel = { { cp.blue, cp.surface1 }, { cp.overlay0, cp.base } }, -} - -return catppuccin