Skip to content

Commit

Permalink
feat(terminal): bright ansi colors (#648)
Browse files Browse the repository at this point in the history
## Description

<!-- Describe the big picture of your changes to communicate to the
maintainers
  why we should accept this pull request. -->
Generate bright ansi colors based on the ansi colors.
  • Loading branch information
folke authored Oct 23, 2024
1 parent 4867d10 commit 5e64b21
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 34 deletions.
21 changes: 21 additions & 0 deletions lua/tokyonight/colors/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,27 @@ function M.setup(opts)

colors.rainbow = { colors.blue, colors.yellow, colors.green, colors.teal, colors.magenta, colors.purple }

-- stylua: ignore
--- @class TerminalColors
colors.terminal = {
black = colors.black,
black_bright = colors.terminal_black,
red = colors.red,
red_bright = Util.brighten(colors.red),
green = colors.green,
green_bright = Util.brighten(colors.green),
yellow = colors.yellow,
yellow_bright = Util.brighten(colors.yellow),
blue = colors.blue,
blue_bright = Util.brighten(colors.blue),
magenta = colors.magenta,
magenta_bright = Util.brighten(colors.magenta),
cyan = colors.cyan,
cyan_bright = Util.brighten(colors.cyan),
white = colors.fg_dark,
white_bright = colors.fg,
}

opts.on_colors(colors)

return colors, opts
Expand Down
32 changes: 16 additions & 16 deletions lua/tokyonight/extra/kitty.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,24 @@ active_border_color ${blue}
inactive_border_color ${bg_highlight}
# normal
color0 ${black}
color1 ${red}
color2 ${green}
color3 ${yellow}
color4 ${blue}
color5 ${magenta}
color6 ${cyan}
color7 ${fg_dark}
color0 ${terminal.black}
color1 ${terminal.red}
color2 ${terminal.green}
color3 ${terminal.yellow}
color4 ${terminal.blue}
color5 ${terminal.magenta}
color6 ${terminal.cyan}
color7 ${terminal.white}
# bright
color8 ${terminal_black}
color9 ${red}
color10 ${green}
color11 ${yellow}
color12 ${blue}
color13 ${magenta}
color14 ${cyan}
color15 ${fg}
color8 ${terminal.black_bright}
color9 ${terminal.red_bright}
color10 ${terminal.green_bright}
color11 ${terminal.yellow_bright}
color12 ${terminal.blue_bright}
color13 ${terminal.magenta_bright}
color14 ${terminal.cyan_bright}
color15 ${terminal.white_bright}
# extended colors
color16 ${orange}
Expand Down
4 changes: 2 additions & 2 deletions lua/tokyonight/extra/wezterm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ split = "${blue}"
compose_cursor = "${orange}"
scrollbar_thumb = "${bg_highlight}"
ansi = ["${black}", "${red}", "${green}", "${yellow}", "${blue}", "${magenta}", "${cyan}", "${fg_dark}"]
brights = ["${terminal_black}", "${red}", "${green}", "${yellow}", "${blue}", "${magenta}", "${cyan}", "${fg}"]
ansi = ["${terminal.black}", "${terminal.red}", "${terminal.green}", "${terminal.yellow}", "${terminal.blue}", "${terminal.magenta}", "${terminal.cyan}", "${terminal.white}"]
brights = ["${terminal.black_bright}", "${terminal.red_bright}", "${terminal.green_bright}", "${terminal.yellow_bright}", "${terminal.blue_bright}", "${terminal.magenta_bright}", "${terminal.cyan_bright}", "${terminal.white_bright}"]
[colors.tab_bar]
inactive_tab_edge = "${bg_dark}"
Expand Down
32 changes: 16 additions & 16 deletions lua/tokyonight/theme.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,31 @@ end
---@param colors ColorScheme
function M.terminal(colors)
-- dark
vim.g.terminal_color_0 = colors.black
vim.g.terminal_color_8 = colors.terminal_black
vim.g.terminal_color_0 = colors.terminal.black
vim.g.terminal_color_8 = colors.terminal.black_bright

-- light
vim.g.terminal_color_7 = colors.fg_dark
vim.g.terminal_color_15 = colors.fg
vim.g.terminal_color_7 = colors.terminal.white
vim.g.terminal_color_15 = colors.terminal.white_bright

-- colors
vim.g.terminal_color_1 = colors.red
vim.g.terminal_color_9 = Util.blend_fg(colors.red, 0.5)
vim.g.terminal_color_1 = colors.terminal.red
vim.g.terminal_color_9 = colors.terminal.red_bright

vim.g.terminal_color_2 = colors.green
vim.g.terminal_color_10 = Util.blend_fg(colors.green, 0.5)
vim.g.terminal_color_2 = colors.terminal.green
vim.g.terminal_color_10 = colors.terminal.green_bright

vim.g.terminal_color_3 = colors.yellow
vim.g.terminal_color_11 = Util.blend_fg(colors.yellow, 0.5)
vim.g.terminal_color_3 = colors.terminal.yellow
vim.g.terminal_color_11 = colors.terminal.yellow_bright

vim.g.terminal_color_4 = colors.blue
vim.g.terminal_color_12 = Util.blend_fg(colors.blue, 0.5)
vim.g.terminal_color_4 = colors.terminal.blue
vim.g.terminal_color_12 = colors.terminal.blue_bright

vim.g.terminal_color_5 = colors.magenta
vim.g.terminal_color_13 = Util.blend_fg(colors.magenta, 0.5)
vim.g.terminal_color_5 = colors.terminal.magenta
vim.g.terminal_color_13 = colors.terminal.magenta_bright

vim.g.terminal_color_6 = colors.cyan
vim.g.terminal_color_14 = Util.blend_fg(colors.cyan, 0.5)
vim.g.terminal_color_6 = colors.terminal.cyan
vim.g.terminal_color_14 = colors.terminal.cyan_bright
end

return M
21 changes: 21 additions & 0 deletions lua/tokyonight/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,27 @@ function M.invert(color)
return color
end

---@param color string -- The hex color string to be adjusted
---@param lightness_amount number? -- The amount to increase lightness by (optional, default: 0.1)
---@param saturation_amount number? -- The amount to increase saturation by (optional, default: 0.15)
function M.brighten(color, lightness_amount, saturation_amount)
lightness_amount = lightness_amount or 0.05
saturation_amount = saturation_amount or 0.2
local hsluv = require("tokyonight.hsluv")

-- Convert the hex color to HSLuv
local hsl = hsluv.hex_to_hsluv(color)

-- Increase lightness slightly
hsl[3] = math.min(hsl[3] + (lightness_amount * 100), 100)

-- Increase saturation a bit more to make the color more vivid
hsl[2] = math.min(hsl[2] + (saturation_amount * 100), 100)

-- Convert the HSLuv back to hex and return
return hsluv.hsluv_to_hex(hsl)
end

---@param groups tokyonight.Highlights
---@return table<string, vim.api.keyset.highlight>
function M.resolve(groups)
Expand Down

0 comments on commit 5e64b21

Please sign in to comment.