diff --git a/lua/astrobox/config.lua b/lua/astrobox/config.lua new file mode 100644 index 0000000..ce28766 --- /dev/null +++ b/lua/astrobox/config.lua @@ -0,0 +1,26 @@ +---@enum Contrast +local CONTRASTS = { + soft = "soft", + medium = "medium", + hard = "hard", +} + +---@class Config +---@field contrast Contrast +---@field float_no_borders boolean + +local M = { + ---@type Config + default = { + contrast = CONTRASTS.medium, + float_no_borders = true, + }, +} + +---@param user_cfg Config +---@return Config +function M.make_config(user_cfg) + return user_cfg and vim.tbl_extend("force", M.default, user_cfg) or M.default +end + +return M diff --git a/lua/astrobox/highlights/init.lua b/lua/astrobox/highlights/init.lua index 4d2b5cc..4767a96 100644 --- a/lua/astrobox/highlights/init.lua +++ b/lua/astrobox/highlights/init.lua @@ -1,9 +1,14 @@ local utils = require("astrobox.utils") -return function(palette, config) +local M = {} + +--- @param theme Theme +--- @param palette Palette +--- @param config Config +function M.make_highlights(theme, palette, config) local HL = {} local function load_mod(mod, mod_name) - local ok, res = pcall(mod, palette, config) + local ok, res = pcall(mod, theme, palette, config) if ok and res then HL = vim.tbl_extend("error", HL, res) else @@ -12,7 +17,7 @@ return function(palette, config) end utils.visit_astrobox_modules("highlights.modules", load_mod) - HL = vim.tbl_extend("force", HL, config.overrides) - return HL end + +return M diff --git a/lua/astrobox/highlights/modules/core.lua b/lua/astrobox/highlights/modules/core.lua index 35052a4..b9782fe 100644 --- a/lua/astrobox/highlights/modules/core.lua +++ b/lua/astrobox/highlights/modules/core.lua @@ -1,120 +1,96 @@ -return function(palette) +---@param theme Theme +---@param palette Palette +return function(theme, palette) return { - -- Bold = { bold = true }, - -- Italic = { italic = true }, - Conceal = { fg = palette.other.conceal, bg = palette.other.harder_bg }, - Directory = { fg = palette.blue, bg = palette.none }, - EndOfBuffer = { fg = palette.bg, bg = palette.bg }, + Conceal = theme.conceal, + Directory = theme.files.directory, + EndOfBuffer = { link = "Normal" }, MatchParen = { fg = palette.none, bg = palette.none, bold = true, underline = true }, - NonText = { fg = palette.ui.fg_inactive, bg = palette.none }, - Normal = { fg = palette.fg, bg = palette.bg }, + NonText = { fg = theme.conceal.fg }, + Normal = theme.normal, NormalNC = { link = "Normal" }, - QuickFixLine = palette.ui.selection, + QuickFixLine = theme.selection, SpecialKey = { fg = palette.none, bg = palette.colored_backgrounds.yellow }, Underlined = { fg = palette.aqua, bg = palette.none, underline = true }, -- Popup - - FloatTitle = { - fg = palette.ui.float.title, - bg = palette.ui.bg, - bold = true, - }, - FloatBorder = { - fg = palette.ui.float.border, - bg = palette.ui.bg, - }, - NormalFloat = { - fg = palette.ui.float.text, - bg = palette.ui.bg, - }, - Title = { - fg = palette.ui.float.title2, - bg = palette.bg, - bold = true, - }, + FloatTitle = theme.popup.title, + FloatBorder = theme.popup.border, + NormalFloat = theme.popup.normal, + Title = theme.popup.title2, -- Bars - - TabLine = { fg = palette.ui.fg_inactive, bg = palette.ui.bg_inactive }, - TabLineFill = { fg = palette.none, bg = palette.ui.bg_inactive }, - TabLineSel = { fg = palette.ui.fg, bg = palette.ui.bg, bold = true, italic = true }, - WinBar = { fg = palette.ui.winbar.fg, bg = palette.ui.winbar.bg }, - WinBarNC = { - fg = palette.ui.winbar.fg_inactive, - bg = palette.ui.winbar.bg_inactive, - }, - - StatusCommand = { fg = palette.ui.statusbar.bg, bg = palette.yellow }, - StatusInsert = { fg = palette.ui.statusbar.bg, bg = palette.green }, - StatusLine = { fg = palette.ui.statusbar.fg, bg = palette.ui.statusbar.bg }, - StatusLineNC = { fg = palette.ui.statusbar.fg_inactive, bg = palette.ui.statusbar.bg }, - StatusNormal = { fg = palette.ui.statusbar.bg, bg = palette.blue }, - StatusReplace = { fg = palette.ui.statusbar.bg, bg = palette.red }, + StatusCommand = { fg = theme.statusbar.normal.bg, bg = palette.yellow }, + StatusInsert = { fg = theme.statusbar.normal.bg, bg = palette.green }, + StatusLine = theme.statusbar.normal, + StatusLineNC = theme.statusbar.inactive, + StatusNormal = { fg = theme.statusbar.normal.bg, bg = palette.blue }, + StatusReplace = { fg = theme.statusbar.normal.bg, bg = palette.red }, StatusTerminal = { link = "StatusInsert" }, - StatusVisual = { fg = palette.ui.statusbar.bg, bg = palette.purple }, + StatusVisual = { fg = theme.statusbar.normal.bg, bg = palette.purple }, + TabLine = theme.statusbar.normal, + TabLineFill = { link = "TabLine" }, + TabLineSel = vim.tbl_extend("error", theme.statusbar.inactive, { bold = true, italic = true }), + WinBar = theme.winbar.normal, + WinBarNC = theme.winbar.inactive, -- Cursor - Cursor = { fg = palette.fg, bg = palette.bg }, + Cursor = { link = "Normal" }, CursorColumn = { link = "CursorLine" }, CursorIM = { link = "Cursor" }, - CursorLine = { fg = palette.none, bg = palette.other.bg_active }, - CursorLineNr = { fg = palette.ui.fg, bg = palette.none }, - LineNr = { fg = palette.ui.fg_inactive, bg = palette.none }, + CursorLine = theme.active, + CursorLineNr = { fg = theme.normal.fg }, + LineNr = theme.inactive, lCursor = { link = "Cursor" }, -- Columns - ColorColumn = { fg = palette.none, bg = palette.other.bg_active }, - FoldColumn = { fg = palette.ui.fg_inactive, bg = palette.none }, - Folded = { fg = palette.ui.fg_inactive, bg = palette.none }, - SignColumn = { fg = palette.none, bg = palette.none }, -- TODO Test + ColorColumn = theme.active, + FoldColumn = theme.active, + Folded = theme.conceal, + SignColumn = theme.none, -- Splits - WinSeparator = { - fg = palette.ui.win.separator, - bg = palette.bg, - -- bold = false, - }, + WinSeparator = theme.windows.separator, -- Diff - DiffAdd = { fg = palette.none, bg = palette.colored_backgrounds.green }, - DiffChange = { fg = palette.none, bg = palette.colored_backgrounds.blue }, - DiffDelete = { fg = palette.none, bg = palette.colored_backgrounds.red }, - DiffText = { fg = palette.none, bg = palette.colored_backgrounds.yellow }, + DiffAdd = theme.diff.bg.add, + DiffChange = theme.diff.bg.change, + DiffDelete = theme.diff.bg.del, + DiffText = theme.diff.bg.text, DiffAdded = { link = "DiffAdd" }, DiffRemoved = { link = "DiffDelete" }, DiffChanged = { link = "DiffText" }, -- TODO Switch to DiffChange? - DiffOldFile = { fg = palette.red, bg = palette.bg }, - DiffNewFile = { fg = palette.green, bg = palette.bg }, - DiffFile = palette.other.error_hl, -- TODO What's this? - DiffLine = palette.other.error_hl, -- TODO What's this? - DiffIndexLine = palette.other.error_hl, -- TODO What's this? + DiffOldFile = theme.diff.normal.del, + DiffNewFile = theme.diff.normal.add, + DiffFile = theme.error, -- TODO What's this? + DiffLine = theme.error, -- TODO What's this? + DiffIndexLine = theme.error, -- Cmd - ErrorMsg = { fg = palette.red, bg = palette.none }, - WarningMsg = { fg = palette.yellow, bg = palette.none }, - Question = { fg = palette.blue, bg = palette.none }, - WildMenu = { fg = palette.ui.selection.fg, bg = palette.ui.selection.bg }, + ErrorMsg = theme.msg.error, + WarningMsg = theme.msg.warning, + Question = theme.msg.info, + WildMenu = theme.selection, -- PMenu - Pmenu = { fg = palette.ui.fg, bg = palette.ui.bg_hard }, - PmenuSel = { fg = palette.ui.selection.fg, bg = palette.ui.selection.bg }, - PmenuSbar = { fg = palette.none, bg = palette.ui.float.scroll }, + Pmenu = theme.menu.normal, + PmenuSel = theme.menu.selection, + PmenuSbar = theme.scrollbar, PmenuThumb = { link = "PmenuSbar" }, -- Search - Search = { fg = palette.fg, bg = palette.other.bg_active }, - IncSearch = { fg = palette.none, bg = palette.colored_backgrounds.blue }, - Substitute = { fg = palette.none, bg = palette.colored_backgrounds.yellow }, - CurSearch = { link = "IncSearch" }, - Visual = { fg = palette.none, bg = palette.other.bg_active }, - VisualNOS = { fg = palette.other.bg_active, bg = palette.fg }, -- Meh + Search = theme.backgrounds.blue, + IncSearch = theme.backgrounds.green, + Substitute = theme.backgrounds.yellow, + CurSearch = theme.backgrounds.purple, + Visual = theme.backgrounds.aqua, + VisualNOS = theme.backgrounds.red, -- Spelling diff --git a/lua/astrobox/highlights/modules/gitsigns.lua b/lua/astrobox/highlights/modules/gitsigns.lua index 21d4dc1..2df4c12 100644 --- a/lua/astrobox/highlights/modules/gitsigns.lua +++ b/lua/astrobox/highlights/modules/gitsigns.lua @@ -1,7 +1,8 @@ -return function(palette) +---@param theme Theme +return function(theme) return { - GitSignsAdd = { fg = palette.green }, - GitSignsChange = { fg = palette.yellow }, - GitSignsDelete = { fg = palette.red }, + GitSignsAdd = theme.diff.normal.add, + GitSignsChange = theme.diff.normal.text, + GitSignsDelete = theme.diff.normal.del, } end diff --git a/lua/astrobox/highlights/modules/markup.lua b/lua/astrobox/highlights/modules/markup.lua index a4198eb..765fc2e 100644 --- a/lua/astrobox/highlights/modules/markup.lua +++ b/lua/astrobox/highlights/modules/markup.lua @@ -1,4 +1,6 @@ -return function(palette) +---@param theme Theme +---@param palette Palette +return function(theme, palette) return { ["@markup"] = { fg = palette.fg }, ["@markup.checked"] = { fg = palette.green }, @@ -8,9 +10,9 @@ return function(palette) ["@markup.emphasis"] = { fg = palette.fg, italic = true }, ["@markup.environment"] = { fg = palette.yellow }, ["@markup.environment.name"] = { fg = palette.orange }, - ["@markup.heading"] = { fg = palette.green, bold = true }, - ["@markup.heading.1.markdown"] = { fg = palette.blue, bold = true }, - ["@markup.heading.2.markdown"] = { fg = palette.aqua, bold = true }, + ["@markup.heading"] = { fg = theme.colors.accent, bold = true }, + ["@markup.heading.1.markdown"] = { fg = theme.colors.accent2, bold = true }, + ["@markup.heading.2.markdown"] = { fg = theme.colors.accent3, bold = true }, ["@markup.heading.3.markdown"] = { fg = palette.purple, bold = true }, ["@markup.heading.4.markdown"] = { fg = palette.yellow, bold = true }, ["@markup.link"] = { fg = palette.aqua, bold = true }, @@ -31,7 +33,7 @@ return function(palette) ["@markup.todo.warning"] = { link = "@markup.warning" }, ["@markup.unchecked"] = { fg = palette.blue }, ["@markup.underline"] = { link = "Underline" }, - ["@markup.warning"] = { fg = palette.yellow }, + ["@markup.warning"] = { fg = theme.colors.warning }, -- Deprecated ["@text"] = { fg = palette.fg }, diff --git a/lua/astrobox/highlights/modules/neo-tree.lua b/lua/astrobox/highlights/modules/neo-tree.lua index 5aadf4a..39d362b 100644 --- a/lua/astrobox/highlights/modules/neo-tree.lua +++ b/lua/astrobox/highlights/modules/neo-tree.lua @@ -1,26 +1,30 @@ -return function(palette) +---@param theme Theme +---@param palette Palette +return function(theme, palette) return { - NeoTreeDirectoryIcon = { fg = palette.blue }, - NeoTreeRootName = { fg = palette.ui.fg, bold = true }, - NeoTreeFileName = { fg = palette.ui.fg }, - NeoTreeFileIcon = { fg = palette.ui.fg }, - NeoTreeFloatTitle = { link = "FloatTitle" }, - NeoTreeIndentMarker = { fg = palette.other.conceal }, + NeoTreeDirectoryIcon = { link = "Directory" }, + NeoTreeRootName = theme.files.root, + NeoTreeFileName = theme.files.file, + NeoTreeFileIcon = { link = "NeoTreeFileName" }, + NeoTreeIndentMarker = theme.inactive, - NeoTreeGitAdded = { fg = palette.green }, - NeoTreeGitConflict = { fg = palette.red }, - NeoTreeGitDeleted = { fg = palette.fg_inactive }, - NeoTreeGitIgnored = { fg = palette.fg }, - NeoTreeGitModified = { fg = palette.orange }, - NeoTreeGitRenamed = { fg = palette.orange }, - NeoTreeGitStaged = { fg = palette.aqua }, - NeoTreeGitUntracked = { fg = palette.yellow }, - NeoTreeGitUnstaged = { fg = palette.yellow }, + NeoTreeGitAdded = theme.diff.normal.add, + NeoTreeGitConflict = theme.diff.normal.merge, + NeoTreeGitDeleted = theme.diff.normal.del, + NeoTreeGitIgnored = theme.inactive, + NeoTreeGitModified = theme.diff.normal.orange, + NeoTreeGitRenamed = { link = "NeoTreeGitModified" }, + NeoTreeGitStaged = theme.diff.normal.staged, + NeoTreeGitUntracked = theme.diff.normal.text, + NeoTreeGitUnstaged = { link = "NeoTreeFileName" }, + + NeoTreeCursorLine = theme.selection, + NeoTreeFloatBorder = theme.popup.border, + NeoTreeFloatTitle = theme.popup.title, - NeoTreeTitleBar = { fg = palette.ui.float.title2, bg = palette.ui.fg, bold = true }, NeoTreeSymbolicLinkTarget = { fg = palette.aqua }, - NeoTreeTabActive = { fg = palette.ui.fg, bg = palette.ui.bg, bold = true }, - NeoTreeTabInactive = { fg = palette.ui.winbar.fg_inactive, bg = palette.ui.winbar.bg }, - NeoTreeCursorLine = { fg = palette.none, bg = palette.ui.selection.bg }, + NeoTreeTabActive = vim.tbl_extend("error", theme.statusbar.active, { bold = true }), + NeoTreeTabInactive = theme.winbar.inactive, + NeoTreeTitleBar = theme.popup.title2, } end diff --git a/lua/astrobox/highlights/modules/nvim-notify.lua b/lua/astrobox/highlights/modules/nvim-notify.lua new file mode 100644 index 0000000..b97d18c --- /dev/null +++ b/lua/astrobox/highlights/modules/nvim-notify.lua @@ -0,0 +1,26 @@ +---@param theme Theme +---@param palette Palette +return function(theme, palette) + return { + NotifyERRORBorder = theme.msg.error, + NotifyWARNBorder = theme.msg.warning, + NotifyINFOBorder = theme.msg.info, + NotifyDEBUGBorder = theme.msg.hint, + NotifyTRACEBorder = theme.msg.error, + NotifyERRORIcon = { link = "NotifyERRORBorder" }, + NotifyWARNIcon = { link = "NotifyWARNBorder" }, + NotifyINFOIcon = { link = "NotifyINFOBorder" }, + NotifyDEBUGIcon = { link = "NotifyDEBUGBorder" }, + NotifyTRACEIcon = { link = "NotifyTRACEBorder" }, + NotifyERRORTitle = { link = "NotifyERRORBorder" }, + NotifyWARNTitle = { link = "NotifyWARNBorder" }, + NotifyINFOTitle = { link = "NotifyINFOBorder" }, + NotifyDEBUGTitle = { link = "NotifyDEBUGBorder" }, + NotifyTRACETitle = { link = "NotifyTRACEBorder" }, + NotifyERRORBody = { link = "Normal" }, + NotifyWARNBody = { link = "Normal" }, + NotifyINFOBody = { link = "Normal" }, + NotifyDEBUGBody = { link = "Normal" }, + NotifyTRACEBody = { link = "Normal" }, + } +end diff --git a/lua/astrobox/highlights/modules/syntax.lua b/lua/astrobox/highlights/modules/syntax.lua index 8460c30..8951bfc 100644 --- a/lua/astrobox/highlights/modules/syntax.lua +++ b/lua/astrobox/highlights/modules/syntax.lua @@ -1,4 +1,6 @@ -return function(palette) +---@param theme Theme +---@param palette Palette +return function(theme, palette) return { Boolean = { fg = palette.yellow, bg = palette.none }, Character = { link = "String" }, @@ -36,20 +38,20 @@ return function(palette) Typedef = { link = "Keyword" }, -- Diags - DiagnosticError = { fg = palette.red }, - DiagnosticHint = { fg = palette.aqua }, - DiagnosticInfo = { fg = palette.blue }, - DiagnosticWarn = { fg = palette.yellow }, + DiagnosticError = theme.msg.error, + DiagnosticHint = theme.msg.hint, + DiagnosticInfo = theme.msg.info, + DiagnosticWarn = theme.msg.warning, DiagnosticUnderlineError = { sp = palette.red, undercurl = true }, DiagnosticUnderlineHint = { sp = palette.aqua, undercurl = true }, DiagnosticUnderlineInfo = { sp = palette.blue, undercurl = true }, DiagnosticUnderlineWarn = { sp = palette.yellow, undercurl = true }, - LspInlayHint = { fg = palette.other.conceal, bg = palette.other.hard_bg }, + LspInlayHint = theme.conceal, LspCodeLens = { link = "LspInlayHint" }, LspCodeLensSeparator = { link = "LspCodeLens" }, - LspReferenceRead = { fg = palette.none, bg = palette.harder_bg }, + LspReferenceRead = theme.active, LspReferenceWrite = { fg = palette.none, bg = palette.harder_bg }, - LspReferenceText = { fg = palette.none, bg = palette.softer_bg }, -- TODO Keep different? + LspReferenceText = theme.active, ["@annotation"] = { fg = palette.yellow }, ["@attribute"] = { fg = palette.yellow }, diff --git a/lua/astrobox/highlights/modules/vim-illuminate.lua b/lua/astrobox/highlights/modules/vim-illuminate.lua new file mode 100644 index 0000000..418df8a --- /dev/null +++ b/lua/astrobox/highlights/modules/vim-illuminate.lua @@ -0,0 +1,7 @@ +return function() + return { + IlluminatedWordText = { link = "LspeferenceText" }, + IlluminatedWordRead = { link = "LspeferenceRead" }, + IlluminatedWordWrite = { link = "LspeferenceWrite" }, + } +end diff --git a/lua/astrobox/init.lua b/lua/astrobox/init.lua index 04e762e..38c54a2 100644 --- a/lua/astrobox/init.lua +++ b/lua/astrobox/init.lua @@ -1,36 +1,45 @@ +local config = require("astrobox.config") local palette = require("astrobox.palette") local highlights = require("astrobox.highlights") - -local default_cfg = { - contrast = "default", -- soft, default or hard - overrides = {} -} +local theme = require("astrobox.theme") local M = { - cfg = {}, - palette = {}, + ---@type Config + cfg = nil, + ---@type Palette + palette = nil, + ---@type Theme + theme = nil, + ---@type table hl = {}, } +---@param user_cfg Config function M.setup(user_cfg) - M.cfg = user_cfg + M.cfg = config.make_config(user_cfg) + -- If the colors are set, assume we're reloading and auto apply + if vim.g.colors_name == "astrobox" then + vim.notify("Reloading", vim.log.levels.INFO, { title = "Astrobox" }) + vim.cmd.colorscheme("astrobox") + end end function M.set_highlights(list) + vim.cmd.highlight("clear") for hl, def in pairs(list) do vim.api.nvim_set_hl(0, hl, def) end end function M.load() - local cfg = vim.tbl_extend("force", default_cfg, M.cfg or {}) - M.palette = palette(cfg) - M.hl = highlights(M.palette, cfg) - for index, color in ipairs(M.palette.term_colors) do + M.palette = palette(M.cfg) + M.theme = theme.make_theme(M.palette, M.cfg) + M.hl = highlights.make_highlights(M.theme, M.palette, M.cfg) + for index, color in ipairs(M.theme.term_colors) do vim.g["terminal_color_" .. index - 1] = color end - vim.g.colors_name = "astrobox" M.set_highlights(M.hl) + vim.g.colors_name = "astrobox" end return M diff --git a/lua/astrobox/palette.lua b/lua/astrobox/palette.lua deleted file mode 100644 index d30c72d..0000000 --- a/lua/astrobox/palette.lua +++ /dev/null @@ -1,88 +0,0 @@ -local colors = require("astrobox.colors") - -return function(config) - local vimbg = vim.o.background - local dark = vimbg == "dark" - local vimbg_reversed = dark and "light" or "dark" - - -- Build base colors - local base = { - none = "NONE", - fg = colors.grayscale[vimbg_reversed][1], - bg = colors.bg[vimbg][config.contrast], - - harder_bg = colors.bg.harder[vimbg][config.contrast], - softer_bg = colors.bg.softer[vimbg][config.contrast], - - bg_gradiant = colors.grayscale[vimbg], - fg_gradiant = colors.grayscale[vimbg_reversed], - - colored_backgrounds = colors.colored_backgrounds[vimbg][config.contrast], - - gray = colors.gray, - } - -- Append colors - local palette = vim.tbl_extend("error", base, colors.colors[vimbg]) - - palette.ui = { - fg = palette.fg, - bg = palette.none, - bg_hard = palette.harder_bg, - fg_inactive = palette.fg_gradiant[4], - bg_inactive = palette.bg_gradiant[2], - float = { - title = palette.green, - title2 = palette.aqua, - border = palette.fg_gradiant[3], - text = palette.fg_gradiant[2], - scroll = palette.blue, - }, - statusbar = { - fg = palette.fg, - bg = palette.bg_gradiant[1], - }, - winbar = { - fg = palette.fg_gradiant[1], - bg = palette.harder_bg, - fg_inactive = palette.bg_gradiant[3], - bg_inactive = palette.harder_bg, - }, - selection = { - fg = palette.fg, - bg = palette.colored_backgrounds.blue, - }, - win = { - separator = palette.fg_gradiant[4], - }, - } - - palette.other = { - conceal = palette.bg_gradiant[3], - hard_bg = palette.harder_bg, - bg_active = palette.softer_bg, - - -- Special HL group to find what a group maps to - error_hl = { fg = "#000000", bg = "#FF00FF" }, - } - - palette.term_colors = { - palette.bg, - colors.term_colors.red, - colors.term_colors.green, - colors.term_colors.yellow, - colors.term_colors.blue, - colors.term_colors.purple, - colors.term_colors.aqua, - palette.fg_gradiant[4], - palette.gray, - colors.colors.red, - colors.colors.green, - colors.colors.yellow, - colors.colors.blue, - colors.colors.purple, - colors.colors.aqua, - palette.fg, - } - - return palette -end diff --git a/lua/astrobox/colors.lua b/lua/astrobox/palette/colors.lua similarity index 60% rename from lua/astrobox/colors.lua rename to lua/astrobox/palette/colors.lua index a9cd0ed..bffb6a6 100644 --- a/lua/astrobox/colors.lua +++ b/lua/astrobox/palette/colors.lua @@ -1,37 +1,46 @@ +---@class Colors +---@field red string +---@field green string +---@field yellow string +---@field blue string +---@field purple string +---@field aqua string +---@field orange string + return { - none = nil, + none = "NONE", bg = { dark = { soft = "#32302f", - default = "#282828", + medium = "#282828", hard = "#1d2021", }, light = { soft = "#f2e5bc", - default = "#fbf1c7", + medium = "#fbf1c7", hard = "#f9f5d7", }, harder = { dark = { soft = "#282828", - default = "#1d2021", + medium = "#1d2021", hard = "#171a1a", }, light = { soft = "#fbf1c7", - default = "#f9f5d7", + medium = "#f9f5d7", hard = "#faf7df", }, }, softer = { dark = { soft = "#343230", - default = "#32302f", + medium = "#32302f", hard = "#282828", }, light = { soft = "#f1e3ba", - default = "#f2e5bc", + medium = "#f2e5bc", hard = "#fbf1c7", }, }, @@ -55,6 +64,7 @@ return { }, colors = { + --- @type Colors dark = { red = "#fb4934", green = "#b8bb26", @@ -64,6 +74,7 @@ return { aqua = "#8ec07c", orange = "#fe8019", }, + --- @type Colors light = { red = "#9d0006", green = "#79740e", @@ -75,6 +86,7 @@ return { }, }, + --- @type Colors term_colors = { red = "#cc241d", green = "#98971a", @@ -84,47 +96,74 @@ return { aqua = "#689d6a", orange = "#d65d0e", }, - + -- Note: Lerped from colors and backgrounds. colored_backgrounds = { + -- Coeff is 0.8 with exceptions dark = { + --- @type Colors soft = { red = "#5a3530", green = "#4d4c2d", - yellow = "#6e5a2f", + yellow = "#6e5a2f", -- 0.7 blue = "#4a534f", + purple = "#524145", + aqua = "#444d3e", + orange = "#5b402b", }, - default = { + --- @type Colors + medium = { red = "#522f2a", green = "#454528", - yellow = "#67552a", + yellow = "#67552a", -- 0.7 blue = "#434e4a", + purple = "#4a3b3f", + aqua = "#3c4639", + orange = "#533a25", }, + --- @type Colors hard = { red = "#492825", green = "#3c3f22", - yellow = "#5f4f25", + yellow = "#5f4f25", -- 0.7 blue = "#3c4845", + purple = "#413439", + aqua = "#344033", + orange = "#4a331f", }, }, + -- untested + -- 0.6 with exceptions light = { + --- @type Colors soft = { red = "#d08973", green = "#c2b876", yellow = "#e0c48a", - blue = "#acbfa8", + blue = "#acbfa8", -- 0.7 + purple = "#caa39e", + aqua = "#acbb94", + orange = "#d7a172", }, - default = { + --- @type Colors + medium = { red = "#d5917a", green = "#c7bf7d", yellow = "#e6cc91", - blue = "#b2c7af", + blue = "#b2c7af", -- 0.7 + purple = "#d0aaa5", + aqua = "#b1c29b", + orange = "#dda879", }, + --- @type Colors hard = { red = "#d49383", green = "#c6c187", yellow = "#e5cf9d", - blue = "#b0cabb", + blue = "#b0cabb", -- 0.7 + purple = "#cfacae", + aqua = "#b0c4a4", + orange = "#dbaa82", }, }, }, diff --git a/lua/astrobox/palette/init.lua b/lua/astrobox/palette/init.lua new file mode 100644 index 0000000..0699371 --- /dev/null +++ b/lua/astrobox/palette/init.lua @@ -0,0 +1,44 @@ +---@class Palette : Colors +---@field none string +---@field fg string +---@field bg string +---@field harder_bg string +---@field softer_bg string +---@field bg_gradiant table +---@field fg_gradiant table +---@field colored_backgrounds Colors +---@field term_colors Colors +---@field gray string + +local colors = require("astrobox.palette.colors") + +-- TODO Split into palette and theme (float, bars)? + +--- @return Palette +return function(config) + local vimbg = vim.o.background + local dark = vimbg == "dark" + local vimbg_reversed = dark and "light" or "dark" + + -- Build base colors + local base = { + none = colors.none, + fg = colors.grayscale[vimbg_reversed][1], + bg = colors.bg[vimbg][config.contrast], + + harder_bg = colors.bg.harder[vimbg][config.contrast], + softer_bg = colors.bg.softer[vimbg][config.contrast], + + bg_gradiant = colors.grayscale[vimbg], + fg_gradiant = colors.grayscale[vimbg_reversed], + + colored_backgrounds = colors.colored_backgrounds[vimbg][config.contrast], + term_colors = colors.term_colors, + + gray = colors.gray, + } + -- Append colors + local palette = vim.tbl_extend("error", base, colors.colors[vimbg]) + + return palette +end diff --git a/lua/astrobox/theme.lua b/lua/astrobox/theme.lua new file mode 100644 index 0000000..667cd64 --- /dev/null +++ b/lua/astrobox/theme.lua @@ -0,0 +1,136 @@ +local M = {} + +---@param P Palette +---@param C Config +---@return Theme +---@diagnostic disable-next-line: unused-local +function M.make_theme(P, C) + ---@class Theme + local T = { + none = { fg = P.none, bg = P.none }, + normal = { fg = P.fg, bg = P.bg }, + inverted = { fg = P.bg, bg = P.fg }, + inactive = { fg = P.fg_gradiant[4] }, + conceal = { fg = P.bg_gradiant[3], bg = P.harder_bg }, + active = { fg = P.none, bg = P.softer_bg }, + } + T.colors = { + accent = P.blue, + accent2 = P.green, + accent3 = P.aqua, + } + T.backgrounds = { + red = { fg = P.none, bg = P.colored_backgrounds.red }, + green = { fg = P.none, bg = P.colored_backgrounds.green }, + yellow = { fg = P.none, bg = P.colored_backgrounds.yellow }, + blue = { fg = P.none, bg = P.colored_backgrounds.blue }, + purple = { fg = P.none, bg = P.colored_backgrounds.purple }, + aqua = { fg = P.none, bg = P.colored_backgrounds.aqua }, + orange = { fg = P.none, bg = P.colored_backgrounds.orange }, + } + T.diff = { + normal = { + add = { fg = P.green, bg = P.none }, + text = { fg = P.yellow, bg = P.none }, + change = { fg = P.blue, bg = P.none }, + del = { fg = P.red, bg = P.none }, + merge = { fg = P.purple, bg = P.none }, + staged = { fg = P.aqua, bg = P.none }, + }, + bg = { + add = T.backgrounds.green, + text = T.backgrounds.yellow, + change = T.backgrounds.blue, + del = T.backgrounds.red, + }, + } + T.msg = { + error = { fg = P.red, bg = P.none }, + warning = { fg = P.yellow, bg = P.none }, + info = { fg = P.blue, bg = P.none }, + hint = { fg = P.aqua, bg = P.none }, + } + T.files = { + directory = { fg = T.colors.accent }, + file = { fg = T.normal.fg }, + root = { fg = T.normal.fg, bold = true }, + + added = { fg = T.colors.diffadd }, + changed = { fg = T.colors.difftext }, + untracked = { fg = P.orange }, + } + T.scrollbar = { fg = P.none, bg = P.colored_backgrounds.blue } + T.windows = { + separator = { fg = P.fg_gradiant[4], bg = P.none }, + } + T.popup = { + normal = { + fg = P.fg, + bg = P.bg_gradiant[1], + }, + conceal = T.conceal, + inactive = { + fg = P.fg_gradiant[4], + bg = P.bg_gradiant[2], + }, + -- TODO Check if working good + border = C.float_no_borders and { fg = P.none, bg = P.none } or T.windows.separator, + title = { fg = T.colors.accent2, bg = P.none, bold = true }, -- TODO need to switch to normal.bg? + title2 = { fg = T.colors.accent3, bg = P.none, bold = true }, -- TODO need to switch to normal.bg? + } + T.selection = { + fg = P.fg, + bg = P.colored_backgrounds.blue, + } + T.menu = { + normal = { fg = P.fg_gradiant[1], bg = P.harder_bg }, + selection = { fg = P.fg_gradiant[1], bg = T.selection.bg }, + } + T.statusbar = { + normal = { + fg = P.fg_gradiant[1], + bg = P.harder_bg, + }, + active = { + fg = P.fg_gradiant[1], + bg = P.harder_bg, + }, + inactive = { + fg = P.fg, + bg = P.bg_gradiant[1], + }, + } + T.winbar = { + normal = { + fg = P.fg_gradiant[1], + bg = P.harder_bg, + }, + inactive = { + fg = P.bg_gradiant[3], + bg = P.harder_bg, + }, + } + T.term_colors = { + P.bg, + P.term_colors.red, + P.term_colors.green, + P.term_colors.yellow, + P.term_colors.blue, + P.term_colors.purple, + P.term_colors.aqua, + P.fg_gradiant[4], + P.gray, + P.red, + P.green, + P.yellow, + P.blue, + P.purple, + P.aqua, + P.fg, + } + + T.error = { fg = "#000000", bg = "#FF00FF" } + return T +end + +return M diff --git a/lua/astrobox/utils.lua b/lua/astrobox/utils.lua index a1d96a3..a28e430 100644 --- a/lua/astrobox/utils.lua +++ b/lua/astrobox/utils.lua @@ -9,11 +9,13 @@ ASTROBOX_ROOT_PATH = get_module_root_path("astrobox") local M = {} +---@param module string +---@param visitor function function M.visit_astrobox_modules(module, visitor) local modpath = ASTROBOX_ROOT_PATH .. module:gsub("%.", "/") local hdl, err, msg = vim.loop.fs_scandir(modpath) if hdl == nil then - print("Astrobox err: " .. err .. " " .. vim.inspect(msg)) + vim.notify("Astrobox err: " .. err .. " " .. vim.inspect(msg), vim.log.levels.ERROR) return end while true do @@ -27,7 +29,7 @@ function M.visit_astrobox_modules(module, visitor) if ok then visitor(mod, mod_name) else - print("AstroBox:Failed to load module " .. mod_name) + vim.notify("AstroBox:Failed to load module " .. mod_name, vim.log.levels.ERROR) end end end