Skip to content

Commit

Permalink
feat: introduce colorblind mode (#15)
Browse files Browse the repository at this point in the history
Co-authored-by: Isrothy <isrothy@gmail.com>
  • Loading branch information
gbprod and Isrothy authored Jan 26, 2023
1 parent 4f53335 commit 72529f6
Show file tree
Hide file tree
Showing 20 changed files with 321 additions and 17 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@ require("nord").setup({
},
},

-- colorblind mode
-- see https://github.com/EdenEast/nightfox.nvim#colorblind
-- simulation mode has not been implemented yet.
colorblind = {
enable = false,
severity = {
protan = 0.0,
deutan = 0.0,
tritan = 0.0,
},
}

--- You can override specific highlights to use other groups or a hex color
--- function will be called with all highlights and the colorScheme table
on_highlights = function(highlights, colors) end,
Expand Down Expand Up @@ -152,3 +164,4 @@ require("bufferline").setup({
his years of good and loyal service.
- [folke/tokyonight.nvim](https://github.com/folke/tokyonight.nvim): For a lot
of code inspiration.
- [EdenEast/nightfox.nvim](https://github.com/EdenEast/nightfox.nvim#colorblind): For daltonization algorithm
2 changes: 1 addition & 1 deletion lua/lualine/themes/nord.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local c = require("nord.colors")
local c = require("nord.colors").palette

local nord = {}

Expand Down
41 changes: 40 additions & 1 deletion lua/nord/colors.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
return {
local colors = {}

local defaults = {
polar_night = {
origin = "#2E3440", -- nord0
bright = "#3B4252", -- nord1
Expand Down Expand Up @@ -26,3 +28,40 @@ return {
},
none = "NONE",
}

colors.palette = defaults

function colors.daltonize(severity)
local daltonize = require("nord.utils.colorblind").daltonize

colors.palette = {
polar_night = {
origin = daltonize(defaults.polar_night.origin, severity),
bright = daltonize(defaults.polar_night.bright, severity),
brighter = daltonize(defaults.polar_night.brighter, severity),
brightest = daltonize(defaults.polar_night.brightest, severity),
light = daltonize(defaults.polar_night.light, severity),
},
snow_storm = {
origin = daltonize(defaults.snow_storm.origin, severity),
brighter = daltonize(defaults.snow_storm.brighter, severity),
brightest = daltonize(defaults.snow_storm.brightest, severity),
},
frost = {
polar_water = daltonize(defaults.frost.polar_water, severity),
ice = daltonize(defaults.frost.polar_water, severity),
artic_water = daltonize(defaults.frost.artic_water, severity),
artic_ocean = daltonize(defaults.frost.artic_ocean, severity),
},
aurora = {
red = daltonize(defaults.aurora.red, severity),
orange = daltonize(defaults.aurora.orange, severity),
yellow = daltonize(defaults.aurora.yellow, severity),
green = daltonize(defaults.aurora.green, severity),
purple = daltonize(defaults.aurora.purple, severity),
},
none = "NONE",
}
end

return colors
8 changes: 8 additions & 0 deletions lua/nord/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ local defaults = {
modified = { italic = true },
},
},
colorblind = {
enable = false,
severity = {
protan = 0,
deutan = 0,
tritan = 0,
},
},
--- You can override specific highlights to use other groups or a hex color
on_highlights = function(highlights, colors) end,
}
Expand Down
2 changes: 1 addition & 1 deletion lua/nord/defaults.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local c = require("nord.colors")
local c = require("nord.colors").palette
local utils = require("nord.utils")

local defaluts = {}
Expand Down
4 changes: 4 additions & 0 deletions lua/nord/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ function nord.load(opts)
require("nord.config").extend(opts)
end

if config.options.colorblind.enable then
require("nord.colors").daltonize(config.options.colorblind.severity)
end

vim.cmd([[ highlight clear ]])

if config.options.terminal_colors then
Expand Down
2 changes: 1 addition & 1 deletion lua/nord/lsp.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local utils = require("nord.utils")
local lsp = {}

local c = require("nord.colors")
local c = require("nord.colors").palette

function lsp.highlights()
return {
Expand Down
3 changes: 2 additions & 1 deletion lua/nord/plugins/bufferline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ local config = require("nord.config").options.styles.bufferline

local bufferline = {}

local c = require("nord.colors")
local c = require("nord.colors").palette

function bufferline.highlights()
local current_hi = vim.tbl_extend("force", { bg = c.polar_night.brighter }, config.current)
Expand Down Expand Up @@ -47,6 +47,7 @@ function bufferline.highlights()
BufferInactiveTarget = { bg = c.polar_night.origin, fg = c.aurora.red, bold = true },
BufferInactiveHINT = { bg = c.polar_night.origin, fg = utils.darken(c.frost.artic_water, 0.4) },
BufferInactiveINFO = { bg = c.polar_night.origin, fg = utils.darken(c.frost.ice, 0.4) },

BufferInactiveWARN = { bg = c.polar_night.origin, fg = utils.darken(c.aurora.yellow, 0.4) },
BufferInactiveERROR = { bg = c.polar_night.origin, fg = utils.darken(c.aurora.red, 0.4) },

Expand Down
2 changes: 1 addition & 1 deletion lua/nord/plugins/completion.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local cmp = {}

local c = require("nord.colors")
local c = require("nord.colors").palette

function cmp.highlights()
return {
Expand Down
2 changes: 1 addition & 1 deletion lua/nord/plugins/filetree.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local filetree = {}

local config = require("nord.config")
local c = require("nord.colors")
local c = require("nord.colors").palette

function filetree.highlights()
return {
Expand Down
2 changes: 1 addition & 1 deletion lua/nord/plugins/git.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local git = {}

local c = require("nord.colors")
local c = require("nord.colors").palette

function git.highlights()
return {
Expand Down
2 changes: 1 addition & 1 deletion lua/nord/plugins/motion.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local motion = {}

local c = require("nord.colors")
local c = require("nord.colors").palette

function motion.highlights()
return {
Expand Down
2 changes: 1 addition & 1 deletion lua/nord/plugins/notify.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local utils = require("nord.utils")
local notify = {}

local c = require("nord.colors")
local c = require("nord.colors").palette

function notify.highlights()
return {
Expand Down
2 changes: 1 addition & 1 deletion lua/nord/plugins/picker.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local picker = {}

local c = require("nord.colors")
local c = require("nord.colors").palette

function picker.highlights()
return {
Expand Down
2 changes: 1 addition & 1 deletion lua/nord/plugins/ui.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local ui = {}

local c = require("nord.colors")
local c = require("nord.colors").palette

function ui.highlights()
return {
Expand Down
2 changes: 1 addition & 1 deletion lua/nord/syntax.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local c = require("nord.colors")
local c = require("nord.colors").palette
local utils = require("nord.utils")

local base = {}
Expand Down
2 changes: 1 addition & 1 deletion lua/nord/terminal.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local terminal = {}

local c = require("nord.colors")
local c = require("nord.colors").palette

function terminal.apply()
-- dark
Expand Down
2 changes: 1 addition & 1 deletion lua/nord/treesitter.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local c = require("nord.colors")
local c = require("nord.colors").palette
local utils = require("nord.utils")

local treesitter = {}
Expand Down
Loading

0 comments on commit 72529f6

Please # to comment.