Skip to content

Commit

Permalink
Fix state/config loading, test on all PRs and add use case (#115)
Browse files Browse the repository at this point in the history
Co-authored-by: Alexander van Zyl <[email protected]>
  • Loading branch information
5-pebbles and AlexvZyl authored Mar 11, 2024
1 parent 2d35c1e commit ad0da11
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
branches: [ "**" ]

jobs:
tests:
Expand Down
62 changes: 26 additions & 36 deletions lua/nordic/colors/init.lua
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
local U = require 'nordic.utils'
local C = require 'nordic.colors.nordic'

C.extended = false

function C.extend_palette()
local O = require 'nordic.config'.options
local options = require('nordic.config').options

C.extended = true
-- `white0` is used as the default fg, and has a blue tint.
-- Reduce that amount of tint.
C.white0 = (options.reduced_blue and C.white0_reduce_blue) or C.white0_normal

-- Modify the palette before generating colors.
C = O.on_palette(C)
C = options.on_palette(C)

-- Add these for international convenience :)
C.grey0 = C.gray0
Expand All @@ -23,19 +23,28 @@ function C.extend_palette()
-- Some of the format is from @folke/tokyonight.nvim.

-- Backgrounds
C.bg = (O.transparent_bg and C.none) or C.gray0
C.bg_dark = (O.transparent_bg and C.none) or C.black0
C.bg_highlight = U.blend(C.bg_dark, C.bg, O.cursorline.blend)
C.bg_visual = C.bg_highlight
C.bg_sidebar = (O.transparent_bg and C.none) or C.bg
C.bg_popup = (O.transparent_bg and C.none) or C.bg
C.bg_statusline = C.bg_dark
C.bg = (options.transparent_bg and C.none) or
((options.swap_backgrounds and C.black1) or C.gray0)
C.bg_dark = (options.transparent_bg and C.none) or C.black0
C.bg_sidebar = (options.transparent_bg and C.none) or C.bg
C.bg_popup = (options.transparent_bg and C.none) or C.bg
C.bg_statusline = C.black0
C.bg_selected = U.blend(C.gray2, C.black0, 0.4)
C.bg_fold = C.gray2

-- Cursorline Background
if options.cursorline.theme == 'light' then
options.cursorline.bg = C.gray1
else
options.cursorline.bg = C.black0
end

C.bg_visual = (options.transparent_bg and options.cursorline.bg)
or U.blend(options.cursorline.bg, C.bg, options.cursorline.blend)

-- Borders
C.border_fg = (O.bright_border and C.white0) or C.black0
C.border_bg = (O.transparent_bg and C.none) or C.bg
C.border_fg = (options.bright_border and C.white0) or C.black0
C.border_bg = (options.transparent_bg and C.none) or C.bg

-- Foregrounds
C.fg = C.white0
Expand All @@ -52,7 +61,8 @@ function C.extend_palette()
C.fg_popup_border = C.border_fg

-- Floating windows
C.bg_float = (O.transparent_bg and C.none) or C.black1
C.bg_float = (options.transparent_bg and C.none) or
((options.swap_backgrounds and C.gray0) or C.black1)
C.fg_float = C.fg
C.bg_float_border = C.bg_float
C.fg_float_border = C.border_fg
Expand Down Expand Up @@ -86,26 +96,6 @@ end

-- Sometimes the palette is required before the theme has been loaded,
-- so we need to extend the palette in those cases.
if not C.extended then C.extend_palette() end

-- We only want to call these on setup.
function C.apply_modifications()
local O = require 'nordic.config'.options
-- Cursorline
if O.cursorline.theme == 'light' then
C.bg_highlight = U.blend(C.gray1, C.bg, O.cursorline.blend)
C.bg_visual = C.bg_highlight
end
-- Swap background
if O.swap_backgrounds then
local gray0 = C.gray0
C.gray0 = C.black1
C.black1 = gray0
end
-- Change white.
if O.reduced_blue then
C.white0 = C.white0_alt
end
end
C.extend_palette()

return C
8 changes: 4 additions & 4 deletions lua/nordic/colors/nordic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ local palette = {
gray5 = '#60728A',

-- Dim white.
-- `white0` is used as the default fg, and has a blue tint.
-- Reduce that amount of tint.
white0_alt = '#C0C8D8',
white0 = '#BBC3D4',
-- default fg, has a blue tint.
white0_normal = '#BBC3D4',
-- less blue tint
white0_reduce_blue = '#C0C8D8',

-- Snow storm.
white1 = '#D8DEE9',
Expand Down
2 changes: 2 additions & 0 deletions lua/nordic/groups/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ function M.get_groups()
require('nordic.groups.native').get_groups(),
require('nordic.groups.integrations').get_groups()
)


return merge(
groups,
require 'nordic.config'.options.override
Expand Down
30 changes: 15 additions & 15 deletions lua/nordic/groups/integrations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ function M.get_groups()
G.NoiceCmdline = { bg = C.bg_dark, fg = C.fg }
G.NoiceCmdlineIcon = { bg = C.bg_float, fg = C.yellow.base }
G.NoiceCmdlineIconSearch = { bg = C.bg_dark, fg = C.yellow.base }
G.NoicePopupBorder = { fg = C.black0, bg = C.black1 }
G.NoicePopupBorder = { fg = C.black0, bg = C.bg_float }
G.NoiceCmdlinePopupBorder = { link = 'NoicePopupBorder' }
G.NoiceCmdlinePopupBorderSearch = { link = 'NoicePopupBorder' }
G.NoiceCmdlinePopup = { bg = C.black1 }
G.NoiceCmdlinePopup = { bg = C.bg_float }

-- Noice Classic.
if O.noice.style == 'classic' then
Expand Down Expand Up @@ -190,7 +190,7 @@ function M.get_groups()
G.DapBreakPoint = { fg = C.red.bright }

-- Nvim DAP UI.
G.DapUINormal = { bg = C.black1 }
G.DapUINormal = { bg = C.bg_float }
G.DapUIStop = { fg = C.red.bright, bold = true }
G.DapUIRestart = { fg = C.green.bright, bold = true }
G.DapUIPlayPause = { fg = C.green.bright, bold = true }
Expand Down Expand Up @@ -251,22 +251,22 @@ function M.get_groups()

-- Telescope Flat.
if O.telescope.style == 'flat' then
G.TelescopeNormal = { bg = C.black1 }
G.TelescopeNormal = { bg = C.bg_float }
G.TelescopePromptNormal = { bg = C.black2 }
G.TelescopeResultsNormal = { bg = C.black1 }
G.TelescopePreviewNormal = { bg = C.black1 }
G.TelescopeSelection = { bg = C.black1, fg = C.yellow.bright }
G.TelescopeSelectionCaret = { fg = C.yellow.bright, bg = C.black1, bold = true }
G.TelescopeResultsNormal = { bg = C.bg_float }
G.TelescopePreviewNormal = { bg = C.bg_float }
G.TelescopeSelection = { bg = C.bg_float, fg = C.yellow.bright }
G.TelescopeSelectionCaret = { fg = C.yellow.bright, bg = C.bg_float, bold = true }
G.TelescopePreviewTitle = { bg = C.blue2, fg = C.black0, bold = true }
G.TelescopeResultsTitle = { bg = C.orange.base, fg = C.black0, bold = true }
G.TelescopePromptTitle = { bg = C.orange.base, fg = C.black0, bold = true }
G.TelescopeTitle = { bg = C.orange.base, fg = C.black0, bold = true }
G.TelescopeBorder = { fg = C.black0, bg = C.black0 }
G.TelescopePromptBorder = { bg = C.black2, fg = C.black0 }
G.TelescopeResultsBorder = { bg = C.black1, fg = C.black0 }
G.TelescopePreviewBorder = { bg = C.black1, fg = C.black0 }
G.TelescopeMultiIcon = { fg = C.yellow.bright, bg = C.black1, bold = true }
G.TelescopeMultiSelection = { bg = C.black1 }
G.TelescopeResultsBorder = { bg = C.bg_float, fg = C.black0 }
G.TelescopePreviewBorder = { bg = C.bg_float, fg = C.black0 }
G.TelescopeMultiIcon = { fg = C.yellow.bright, bg = C.bg_float, bold = true }
G.TelescopeMultiSelection = { bg = C.bg_float }
G.TelescopePromptPrefix = { bg = C.black2, fg = C.orange.bright }
G.TelescopePreviewLine = { bg = C.gray1 }
end
Expand Down Expand Up @@ -415,7 +415,7 @@ function M.get_groups()
G.TreesitterContextLineNumber = { fg = fg, bg = bg }

-- Trouble.
G.TroubleNormal = { bg = C.black1 }
G.TroubleNormal = { bg = C.bg_float }
G.TroubleText = { fg = C.fg }
G.TroubleCount = { fg = C.white1, bg = C.gray2 }
G.TroubleIndent = { fg = C.gray1 }
Expand Down Expand Up @@ -450,10 +450,10 @@ function M.get_groups()

-- Whichkey.
G.WhichKey = { fg = C.yellow.base }
G.WhichKeyFloat = { bg = C.black1 }
G.WhichKeyFloat = { bg = C.bg_float }
G.WhichKeyDesc = { fg = C.white0 }
G.WhichKeyGroup = { fg = C.orange.bright, bold = true }
G.WhichKeyBorder = { fg = C.black0, bg = C.black1 }
G.WhichKeyBorder = { fg = C.black0, bg = C.bg_float }
-- TODO: Unsure.
G.WhichKeySeperator = {}
G.WhichKeyValue = {}
Expand Down
14 changes: 7 additions & 7 deletions lua/nordic/groups/native.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function M.get_groups()
G.htmlH1 = { fg = C.yellow.base, bold = true }
G.htmlH2 = { fg = C.orange.base }
G.Link = { fg = C.blue1, underline = true }
G.CodeBlock = { bg = C.black1, fg = C.fg }
G.CodeBlock = { bg = C.bg_float, fg = C.fg }
G.mkdHeading = { link = 'htmlH1' }
G.mkdCode = { link = 'CodeBlock' }
G.mkdCodeDelimiter = { link = 'CodeBlock' }
Expand Down Expand Up @@ -111,7 +111,7 @@ function M.get_groups()
G.DiagnosticUnderlineWarn = { undercurl = true, sp = C.warning } -- Used to underline "Warning" diagnostics
G.DiagnosticUnderlineInfo = { undercurl = true, sp = C.info } -- Used to underline "Information" diagnostics
G.DiagnosticUnderlineHint = { undercurl = true, sp = C.hint } -- Used to underline "Hint" diagnostics
G.DiagnosticText = { bg = C.black1 }
G.DiagnosticText = { bg = C.bg_float }
G.LspSignatureActiveParameter = { bg = C.gray3, bold = true }
G.LspCodeLens = { fg = C.comment }
G.LspInfoBorder = { link = 'FloatBorder' }
Expand All @@ -128,8 +128,8 @@ function M.get_groups()
G.Cursor = { fg = C.black0, bg = C.fg } -- character under the cursor
G.lCursor = { fg = C.black0 } -- the character under the cursor when |language-mapping| is used (see 'guicursor')
G.CursorIM = { fg = C.black0 } -- like Cursor, but used when in IME mode |CursorIM|
G.CursorColumn = { bg = C.bg_highlight, bold = O.cursorline.bold } -- Screen-column at the cursor, when 'cursorcolumn' is set.
G.CursorLine = { bg = C.bg_highlight, bold = O.cursorline.bold } -- Screen-line at the cursor, when 'cursorline' is set. Low-priority if foreground (ctermfg OR guifg) is not set.
G.CursorColumn = { bg = C.bg_visual, bold = O.cursorline.bold } -- Screen-column at the cursor, when 'cursorcolumn' is set.
G.CursorLine = { bg = C.bg_visual, bold = O.cursorline.bold } -- Screen-line at the cursor, when 'cursorline' is set. Low-priority if foreground (ctermfg OR guifg) is not set.
G.CursorLineNr = { fg = C.gray5, bold = O.cursorline.bold_number } -- Like LineNr when 'cursorline' or 'relativenumber' is set for the cursor line.
G.CursorLineSign = {}
G.Directory = { fg = C.blue1 } -- directory names (and other special names in listings)
Expand Down Expand Up @@ -163,8 +163,8 @@ function M.get_groups()
G.PmenuThumb = { bg = C.gray2, fg = C.gray2 } -- Popup menu: Thumb of the scrollbar.
G.Question = { fg = C.info } -- |hit-enter| prompt and yes/no questions
G.QuickFixLine = { bg = C.bg_visual, bold = true } -- Current |quickfix| item in the quickfix window. Combined with |hl-CursorLine| when the cursor is there.
G.Search = { bg = C.black1, fg = C.yellow.bright, bold = true, underline = true } -- Last search pattern highlighting (see 'hlsearch'). Also used for similar items that need to stand out.
G.IncSearch = { bg = C.yellow.base, fg = C.black0, bold = true } -- 'incsearch' highlighting; also used for the text replaced with ":s///c"
G.Search = { bg = C.bg_visual, fg = C.yellow.bright, bold = true, underline = true } -- Last search pattern highlighting (see 'hlsearch'). Also used for similar items that need to stand out.
G.IncSearch = { bg = C.yellow.base, fg = C.bg_visual, bold = true } -- 'incsearch' highlighting; also used for the text replaced with ":s///c"
G.CurSearch = { link = 'IncSearch' }
G.SpecialKey = { fg = C.gray5 } -- Unprintable characters: text displayed differently from what it really is. But not 'listchars' whitespace. |hl-Whitespace|
G.SpellBad = { sp = C.error, undercurl = true } -- Word that is not recognized by the spellchecker. |spell| Combined with the highlighting used otherwise.
Expand All @@ -175,7 +175,7 @@ function M.get_groups()
G.StatusLineNC = { fg = C.gray4, bg = C.bg_statusline } -- status lines of not-current windows Note: if this is equal to "StatusLine" Vim will use "^^^" in the status line of the current window.
G.TabLine = { bg = C.bg_statusline, fg = C.fg } -- tab pages line, not active tab page label
G.TabLineFill = { bg = C.black0, fg = C.none } -- tab pages line, where there are no labels
G.TabLineSel = { fg = C.fg_bright, bg = C.gray0 } -- tab pages line, active tab page label
G.TabLineSel = { fg = C.fg_bright, bg = C.bg } -- tab pages line, active tab page label
G.Title = { fg = C.fg_bright, bold = true } -- titles for output from ":set all", ":autocmd" etc.
G.Visual = { bg = C.bg_visual, bold = O.cursorline.bold } -- Visual mode selection
G.VisualNOS = { bg = C.bg_visual } -- Visual mode selection when vim is "Not Owning the Selection".
Expand Down
10 changes: 4 additions & 6 deletions lua/nordic/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ function M.load(opts)
require 'nordic.config'.setup(opts)
end

-- Setup colors.
local colors = require('nordic.colors')
colors.apply_modifications()
colors.extend_palette()
-- Setup colors
require('nordic.colors').extend_palette()

-- Apply theme.
-- Apply theme
local G = require 'nordic.groups'
U.highlight(G.get_groups())
G.set_term_colors()
Expand All @@ -31,6 +29,6 @@ end, {
nargs = 1,
})

M.setup = require 'nordic.config'.setup
M.setup = require('nordic.config').setup

return M

0 comments on commit ad0da11

Please sign in to comment.