Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 54 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,76 @@ on:
pull_request:
branches: [main]

permissions:
contents: read

concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true

jobs:
check:
runs-on: ubuntu-latest
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
neovim: [v0.11.7, v0.12.6]
steps:
- uses: actions/checkout@v4

- uses: rhysd/action-setup-vim@v1
with:
neovim: true
version: v0.12.0
- name: Validate config loads without errors
run: nvim --headless -c "lua vim.cmd('q!')" -c "qa!"
version: ${{ matrix.neovim }}

- name: Use the repository config
run: |
mkdir -p "$HOME/.config"
ln -sfn "$GITHUB_WORKSPACE" "$HOME/.config/nvim"

- name: Check palettes and contrast
run: nvim --headless -u NONE --cmd "set rtp+=." -l scripts/check_colors.lua

- name: Load core config modules
run: |
nvim --headless -u NONE --cmd "set rtp+=." \
-c "lua for _, m in ipairs({ 'config.options', 'config.locale', 'config.keymaps', 'config.autocmds', 'config.theme' }) do require(m) end" \
-c "qa!"

- name: Check Lua syntax
run: |
for f in $(find lua colors -name '*.lua' -not -path '*/lazy-lock.json'); do
nvim --headless -c "lua local ok, err = loadfile('$f'); if not ok then io.stderr:write(err..'\n'); vim.cmd('cquit!') else vim.cmd('q!') end" 2>/dev/null || exit 1
for f in $(find lua colors scripts -name '*.lua' -not -path '*/lazy-lock.json'); do
nvim --headless -u NONE -c "lua local ok, err = loadfile('$f'); if not ok then io.stderr:write(err..'\n'); vim.cmd('cquit!') else vim.cmd('q!') end" 2>/dev/null || exit 1
done

- name: Install plugins and validate startup
run: |
timeout 300 nvim --headless "+Lazy! sync" +qa
nvim --headless -c "lua vim.cmd('q!')" -c "qa!"

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install stylua
run: |
curl -sL https://github.com/JohnnyMorganz/StyLua/releases/download/v2.5.2/stylua-linux-x86_64.zip -o stylua.zip
unzip -o stylua.zip && rm stylua.zip
chmod +x stylua && sudo mv stylua /usr/local/bin/
python3 -c "import zipfile; zipfile.ZipFile('stylua.zip').extractall('.')"
rm stylua.zip
chmod +x stylua
sudo mv stylua /usr/local/bin/

- name: Check Lua formatting
run: stylua --check lua/
run: stylua --check lua/ colors/ scripts/

- name: Install selene
run: |
curl -sL https://github.com/Kampfkarren/selene/releases/download/0.32.0/selene-0.32.0-linux.zip -o selene.zip
python3 -c "import zipfile; zipfile.ZipFile('selene.zip').extractall('.')"
rm selene.zip
chmod +x selene

- name: Lint with selene
run: ./selene .
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ vim.g.langmap_en = ""

<a href="https://xscriptor.io">Dev</a>
&
<a href="https://github.com/xscriptor">github</a>
<a href="https://github.com/xscriptor">Github</a>
&
<a href="https://www.xscriptor.com">X</a>

Expand Down
85 changes: 85 additions & 0 deletions lua/themes/colors.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
local M = {}

function M.strip_alpha(hex)
if #hex == 9 then
return hex:sub(1, 7)
end
return hex
end

local function hex_to_rgb(hex)
hex = M.strip_alpha(hex):gsub("#", "")
return tonumber(hex:sub(1, 2), 16), tonumber(hex:sub(3, 4), 16), tonumber(hex:sub(5, 6), 16)
end

function M.luminance(hex)
local r, g, b = hex_to_rgb(hex)
local function channel(value)
value = value / 255
if value <= 0.03928 then
return value / 12.92
end
return ((value + 0.055) / 1.055) ^ 2.4
end
return 0.2126 * channel(r) + 0.7152 * channel(g) + 0.0722 * channel(b)
end

function M.is_light(hex)
return M.luminance(hex) > 0.6
end

function M.contrast(a, b)
local left = M.luminance(a)
local right = M.luminance(b)
local lighter = math.max(left, right)
local darker = math.min(left, right)
return (lighter + 0.05) / (darker + 0.05)
end

function M.blend(from, to, percent)
local fr, fg, fb = hex_to_rgb(from)
local tr, tg, tb = hex_to_rgb(to)
local function channel(a, b)
return math.floor(a + (b - a) * percent + 0.5)
end
return string.format("#%02x%02x%02x", channel(fr, tr), channel(fg, tg), channel(fb, tb))
end

-- Raise a colour's contrast against the background until it reaches `minimum`.
-- This keeps the palette identity for colours that are already readable and
-- only nudges the ones that would otherwise disappear (for example Paris
-- comments, whose color7 is the same as its background).
function M.readable(colour, background, minimum)
if M.contrast(colour, background) >= minimum then
return M.strip_alpha(colour)
end

local target = M.is_light(background) and "#000000" or "#ffffff"
for percent = 0.1, 1.0, 0.1 do
local candidate = M.blend(colour, target, percent)
if M.contrast(candidate, background) >= minimum then
return candidate
end
end
return target
end

function M.surface(palette)
return M.blend(palette.background, palette.foreground, 0.1)
end

function M.comment(palette)
local background = palette.background
local candidates = { palette.color7, palette.color8, palette.foreground }
if palette.comment then
table.insert(candidates, 1, palette.comment)
end
for _, candidate in ipairs(candidates) do
if candidate and M.contrast(candidate, background) >= 3.0 then
return M.strip_alpha(candidate)
end
end
return M.readable(palette.color7 or palette.foreground, background, 3.0)
end

return M
125 changes: 84 additions & 41 deletions lua/themes/init.lua
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
local colors = require("themes.colors")
local palettes = require("themes.palettes")

local M = {}

local function hex_to_rgb(hex)
hex = palettes.strip_alpha(hex):gsub("#", "")
return tonumber(hex:sub(1, 2), 16), tonumber(hex:sub(3, 4), 16), tonumber(hex:sub(5, 6), 16)
end

local function is_light(hex)
local r, g, b = hex_to_rgb(hex)
local luma = (0.2126 * r + 0.7152 * g + 0.0722 * b) / 255
return luma > 0.6
end

local function set_hl(group, opts)
vim.api.nvim_set_hl(0, group, opts)
end

function M.apply(name)
local p = palettes[name]
if not p then
return
if type(p) ~= "table" then
return false
end

if vim.g.colors_name then
Expand All @@ -30,28 +20,35 @@ function M.apply(name)
vim.cmd("syntax reset")

vim.o.termguicolors = true
vim.o.background = is_light(p.background) and "light" or "dark"
vim.o.background = colors.is_light(p.background) and "light" or "dark"
vim.g.colors_name = name

local bg = colors.strip_alpha(p.background)
local fg = colors.strip_alpha(p.foreground)
local function readable(colour)
return colors.readable(colour, bg, 4.5)
end

local c = {
bg = palettes.strip_alpha(p.background),
fg = palettes.strip_alpha(p.foreground),
bg_alt = palettes.strip_alpha(p.color8),
fg_alt = palettes.strip_alpha(p.color15),
comment = palettes.strip_alpha(p.color7),
red = palettes.strip_alpha(p.color1),
green = palettes.strip_alpha(p.color2),
yellow = palettes.strip_alpha(p.color3),
orange = palettes.strip_alpha(p.color4),
purple = palettes.strip_alpha(p.color5),
blue = palettes.strip_alpha(p.color6),
cyan = palettes.strip_alpha(p.color6),
bright_red = palettes.strip_alpha(p.color9),
bright_green = palettes.strip_alpha(p.color10),
bright_yellow = palettes.strip_alpha(p.color11),
bright_orange = palettes.strip_alpha(p.color12),
bright_purple = palettes.strip_alpha(p.color13),
bright_cyan = palettes.strip_alpha(p.color14),
bg = bg,
fg = fg,
bg_alt = colors.surface(p),
surface_fg = colors.readable(fg, colors.surface(p), 4.5),
fg_alt = colors.readable(p.color15, colors.surface(p), 4.5),
comment = colors.comment(p),
red = readable(p.color1),
green = readable(p.color2),
yellow = readable(p.color3),
orange = readable(p.color4),
purple = readable(p.color5),
blue = readable(p.color6),
cyan = readable(p.color6),
bright_red = readable(p.color9),
bright_green = readable(p.color10),
bright_yellow = readable(p.color11),
bright_orange = readable(p.color12),
bright_purple = readable(p.color13),
bright_cyan = readable(p.color14),
}

set_hl("Normal", { fg = c.fg, bg = c.bg })
Expand All @@ -64,7 +61,7 @@ function M.apply(name)
set_hl("VertSplit", { fg = c.bg_alt })
set_hl("WinSeparator", { fg = c.bg_alt })

set_hl("Pmenu", { fg = c.fg, bg = c.bg_alt })
set_hl("Pmenu", { fg = c.surface_fg, bg = c.bg_alt })
set_hl("PmenuSel", { fg = c.bg, bg = c.bright_cyan, bold = true })
set_hl("PmenuSbar", { bg = c.bg_alt })
set_hl("PmenuThumb", { bg = c.comment })
Expand All @@ -76,7 +73,7 @@ function M.apply(name)
set_hl("IncSearch", { fg = c.bg, bg = c.bright_orange })
set_hl("MatchParen", { fg = c.bright_cyan, bold = true })

set_hl("StatusLine", { fg = c.fg, bg = c.bg_alt })
set_hl("StatusLine", { fg = c.surface_fg, bg = c.bg_alt })
set_hl("StatusLineNC", { fg = c.comment, bg = c.bg_alt })
set_hl("TabLine", { fg = c.comment, bg = c.bg_alt })
set_hl("TabLineSel", { fg = c.fg, bg = c.bg })
Expand Down Expand Up @@ -183,9 +180,40 @@ function M.apply(name)
set_hl("@tag.attribute", { fg = c.yellow })
set_hl("@tag.delimiter", { fg = c.comment })

-- Captures added/moved in recent Neovim releases. Unknown groups are
-- harmless on older versions, but having them keeps syntax highlighting
-- consistent across supported versions.
set_hl("@keyword.import", { link = "Keyword" })
set_hl("@keyword.type", { link = "Type" })
set_hl("@keyword.modifier", { link = "Keyword" })
set_hl("@keyword.coroutine", { link = "Keyword" })
set_hl("@function.method", { link = "Function" })
set_hl("@function.method.call", { link = "Function" })
set_hl("@type.qualifier", { link = "Type" })
set_hl("@variable.member", { fg = c.cyan })
set_hl("@variable.parameter", { fg = c.fg })
set_hl("@string.documentation", { link = "String" })
set_hl("@string.special.url", { fg = c.cyan, underline = true })
set_hl("@comment.documentation", { link = "Comment" })
set_hl("@markup.link.label", { fg = c.cyan })
set_hl("@markup.link.url", { fg = c.cyan, underline = true })
set_hl("@markup.raw.block", { fg = c.green })

set_hl("VisualNOS", { bg = c.bright_cyan, fg = c.bg })
set_hl("Cursor", { fg = c.bg, bg = c.fg })
set_hl("lCursor", { fg = c.bg, bg = c.fg })
set_hl("TermCursor", { fg = c.bg, bg = c.fg })
set_hl("TermCursorNC", { fg = c.bg, bg = c.comment })
set_hl("WinBar", { fg = c.surface_fg, bg = c.bg_alt })
set_hl("WinBarNC", { fg = c.comment, bg = c.bg_alt })
set_hl("PmenuMatch", { fg = c.bright_cyan, bold = true })
set_hl("PmenuMatchSel", { fg = c.bg, bg = c.bright_cyan, bold = true })
set_hl("DiagnosticUnnecessary", { fg = c.comment })
set_hl("DiagnosticDeprecated", { fg = c.red, strikethrough = true })

set_hl("TelescopeBorder", { fg = c.comment, bg = c.bg })
set_hl("TelescopePromptBorder", { fg = c.comment, bg = c.bg_alt })
set_hl("TelescopePromptNormal", { fg = c.fg, bg = c.bg_alt })
set_hl("TelescopePromptNormal", { fg = c.surface_fg, bg = c.bg_alt })
set_hl("TelescopePromptPrefix", { fg = c.cyan, bg = c.bg_alt })

set_hl("GitSignsAdd", { fg = c.green })
Expand All @@ -194,12 +222,12 @@ function M.apply(name)

set_hl("BufferLineFill", { bg = c.bg_alt })
set_hl("BufferLineBackground", { fg = c.comment, bg = c.bg_alt })
set_hl("BufferLineBufferVisible", { fg = c.fg, bg = c.bg_alt })
set_hl("BufferLineBufferVisible", { fg = c.surface_fg, bg = c.bg_alt })
set_hl("BufferLineBufferSelected", { fg = c.fg, bg = c.bg })

set_hl("NoiceCmdlinePopup", { fg = c.fg, bg = c.bg_alt })
set_hl("NoiceCmdlinePopup", { fg = c.surface_fg, bg = c.bg_alt })
set_hl("NoiceCmdlinePopupBorder", { fg = c.cyan, bg = c.bg_alt })
set_hl("NoicePopup", { fg = c.fg, bg = c.bg_alt })
set_hl("NoicePopup", { fg = c.surface_fg, bg = c.bg_alt })

set_hl("NotifyERROR", { fg = c.red })
set_hl("NotifyWARN", { fg = c.yellow })
Expand All @@ -226,7 +254,10 @@ function M.apply(name)
set_hl("CmpItemKind", { fg = c.purple })
set_hl("CmpItemMenu", { fg = c.comment })

vim.g.terminal_color_0 = c.bg
-- ANSI slots 1-6 and 9-14 keep the canonical palette. Slots 7, 8 and 15 use
-- the readable foreground/comment colours because several palettes (notably
-- Paris) define color7 as the background itself.
vim.g.terminal_color_0 = colors.strip_alpha(p.color0)
vim.g.terminal_color_1 = c.red
vim.g.terminal_color_2 = c.green
vim.g.terminal_color_3 = c.yellow
Expand All @@ -242,12 +273,24 @@ function M.apply(name)
vim.g.terminal_color_13 = c.bright_purple
vim.g.terminal_color_14 = c.bright_cyan
vim.g.terminal_color_15 = c.fg_alt

return true
end

M.names = vim.tbl_keys(palettes)
M.names = {}
for name, palette in pairs(palettes) do
if type(palette) == "table" then
table.insert(M.names, name)
end
end
table.sort(M.names)

vim.api.nvim_create_user_command("Theme", function(opts)
M.apply(opts.args)
if not M.apply(opts.args) then
vim.notify(("Unknown theme %q. Available: %s"):format(opts.args, table.concat(M.names, ", ")), vim.log.levels.ERROR)
return
end

local lualine_ok, lualine = pcall(require, "lualine")
if lualine_ok then
lualine.setup({ options = { theme = require("themes.lualine").theme(opts.args) } })
Expand Down
Loading
Loading