Added notermguicolor support and special effects (#27)

* Added notermguicolor support and special effects
* Added notermgui support
* Exposed special parameters for highlight(like bold,italic) to themes
  with gui like to bold "B" in normal mode do normal.b.gui = 'bold'
* Changed CONTRIBUTING.md to reflect current notermguicolor support
* Added calculating cterm values from rgb
* refactored highlight function
* Removed 'bold' default for a element
* Updated themes
* Adding function genarated cterm values to themes
* Updating CONTRIBUTING.md
* made colorschemes more compact

Co-authored-by: hoob3rt <pelczarskihubert@gmail.com>
This commit is contained in:
Shadman 2021-01-08 07:35:09 +06:00 committed by GitHub
parent 3de3eb289f
commit 7460fe5aa2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 536 additions and 598 deletions

View File

@ -18,117 +18,74 @@
<summary><b>theme example</b></summary> <summary><b>theme example</b></summary>
To create a custom theme you need to define a colorscheme for each of vim's modes. Each mode has a `fg` and `bg` field for every lualine section. To create a custom theme you need to define a colorscheme for each of vim's modes. Each mode has a `fg` and `bg` field for every lualine section.
This is really easy in lua. Here is and example of a gruvbox theme. You can add special effects with `gui`.
You can provide colors in two ways
1. As a table like `{'hexcode', 256_color_code}`
2. As a String like `'hexcode'`
Note : You can use `lualine.util.get_cterm_color(hex_color)` function to genarate 256_color_codes from hex_codes.
When method 2 is used 256_color_codes are genarated with that .
Adding theme is really easy in lua. Here is and example of a gruvbox theme.
```lua ```lua
local gruvbox = { } local gruvbox = { }
local colors = { local colors = {
black = "#282828", -- color format { hex_color, 256_color_code}
white = '#ebdbb2', black = {"#282828", 235},
red = '#fb4934', white = {'#ebdbb2', 223},
green = '#b8bb26', red = {'#fb4934', 203},
blue = '#83a598', green = {'#b8bb26', 143},
yellow = '#fe8019', blue = {'#83a598', 108},
yellow = {'#fe8019', 209},
gray = '#a89984', -- color format 'hex_color'
darkgray = '#3c3836', gray = '#a89984',
darkgray = '#3c3836',
lightgray = '#504945', lightgray = '#504945',
inactivegray = '#7c6f64', inactivegray = '#7c6f64',
} }
gruvbox.normal = { gruvbox.normal = {
a = { -- gui parameter is optional and behaves the same way as in vim's highlight command
bg = colors.gray, a = { bg = colors.gray, fg = colors.black, gui = "bold", },
fg = colors.black, b = { bg = colors.lightgray, fg = colors.white, },
}, c = { bg = colors.darkgray, fg = colors.gray }
b = {
bg = colors.lightgray,
fg = colors.white,
},
c = {
bg = colors.darkgray,
fg = colors.gray
}
} }
gruvbox.insert = { gruvbox.insert = {
a = { a = { bg = colors.blue, fg = colors.black, gui = "bold", },
bg = colors.blue, b = { bg = colors.lightgray, fg = colors.white, },
fg = colors.black, c = { bg = colors.lightgray, fg = colors.white }
},
b = {
bg = colors.lightgray,
fg = colors.white,
},
c = {
bg = colors.lightgray,
fg = colors.white
}
} }
gruvbox.visual = { gruvbox.visual = {
a = { a = { bg = colors.yellow, fg = colors.black, gui = "bold", },
bg = colors.yellow, b = { bg = colors.lightgray, fg = colors.white, },
fg = colors.black, c = { bg = colors.inactivegray, fg = colors.black },
},
b = {
bg = colors.lightgray,
fg = colors.white,
},
c = {
bg = colors.inactivegray,
fg = colors.black
},
} }
gruvbox.replace = { gruvbox.replace = {
a = { a = { bg = colors.red, fg = colors.black, gui = "bold", },
bg = colors.red, b = { bg = colors.lightgray, fg = colors.white, },
fg = colors.black, c = { bg = colors.black, fg = colors.white },
},
b = {
bg = colors.lightgray,
fg = colors.white,
},
c = {
bg = colors.black,
fg = colors.white
},
} }
gruvbox.command = { gruvbox.command = {
a = { a = { bg = colors.green, fg = colors.black, gui = "bold", },
bg = colors.green, b = { bg = colors.lightgray, fg = colors.white, },
fg = colors.black, c = { bg = colors.inactivegray, fg = colors.black },
},
b = {
bg = colors.lightgray,
fg = colors.white,
},
c = {
bg = colors.inactivegray,
fg = colors.black
},
} }
-- you can assign one colorscheme to another, if a colorscheme is
-- undefined it falls back to normal
gruvbox.terminal = gruvbox.normal gruvbox.terminal = gruvbox.normal
gruvbox.inactive = { gruvbox.inactive = {
a = { a = { bg = colors.darkgray, fg = colors.gray, gui = "bold", },
bg = colors.darkgray, b = { bg = colors.darkgray, fg = colors.gray, },
fg = colors.gray, c = { bg = colors.darkgray, fg = colors.gray },
},
b = {
bg = colors.darkgray,
fg = colors.gray,
},
c = {
bg = colors.darkgray,
fg = colors.gray
},
} }
lualine.theme = gruvbox lualine.theme = gruvbox

View File

@ -1,12 +1,16 @@
local M = { } local M = { }
local utils = require "lualine.utils"
local function highlight (name, foreground, background, special) local function highlight (name, foreground, background, gui)
local command = { local command = {
'highlight', name, 'highlight', name,
'guifg=' .. foreground, 'ctermfg=' .. (foreground[2] or utils.get_cterm_color(foreground)),
'guibg=' .. background, 'ctermbg=' .. (background[2] or utils.get_cterm_color(background)),
'gui=' .. (special or 'none'), 'cterm=' .. (gui or 'none'),
} 'guifg=' .. (foreground[1] or foreground),
'guibg=' .. (background[1] or background),
'gui=' .. (gui or 'none'),
}
return table.concat(command, ' ') return table.concat(command, ' ')
end end
@ -28,12 +32,8 @@ function M.create_highlight_groups(theme)
apply_defaults_to_theme(theme) apply_defaults_to_theme(theme)
for mode, sections in pairs(theme) do for mode, sections in pairs(theme) do
for section, colorscheme in pairs(sections) do for section, colorscheme in pairs(sections) do
local special = nil
if section == 'a' then
special = 'bold'
end
local highlight_group_name = { 'lualine', section, mode } local highlight_group_name = { 'lualine', section, mode }
vim.cmd(highlight(table.concat(highlight_group_name, '_'), colorscheme.fg, colorscheme.bg, special)) vim.cmd(highlight(table.concat(highlight_group_name, '_'), colorscheme.fg, colorscheme.bg, colorscheme.gui))
end end
end end
end end

View File

@ -1,109 +1,51 @@
local M = { } local dracula = {}
local colors = { local colors = {
grey = "#44475a", grey = {"#44475a", 238},
light_gray = "#5f6a8e", light_gray = {"#5f6a8e", 60 },
orange = "#ffb86c", orange = {"#ffb86c", 215},
purple = "#bd93f9", purple = {"#bd93f9", 141},
red = "#ff5555", red = {"#ff5555", 203},
yellow = "#f1fa8c", yellow = {"#f1fa8c", 228},
green = "#50fa7b", green = {"#50fa7b", 84 },
white = {"#f8f8f2", 255},
white = "#f8f8f2", black = {"#282a36", 236},
black = "#282a36",
} }
M.normal = { dracula.normal = {
a = { a = { bg = colors.purple, fg = colors.black, gui = 'bold', },
bg = colors.purple, b = { bg = colors.light_gray, fg = colors.white, },
fg = colors.black, c = { bg = colors.grey, fg = colors.white, }
},
b = {
bg = colors.light_gray,
fg = colors.white,
},
c = {
bg = colors.grey,
fg = colors.white,
}
} }
M.insert = { dracula.insert = {
a = { a = { bg = colors.green, fg = colors.black, gui = 'bold', },
bg = colors.green, b = { bg = colors.light_gray, fg = colors.white, },
fg = colors.black, c = { bg = colors.grey, fg = colors.white, }
},
b = {
bg = colors.light_gray,
fg = colors.white,
},
c = {
bg = colors.grey,
fg = colors.white,
}
} }
dracula.visual = {
M.visual = { a = { bg = colors.yellow, fg = colors.black, gui = 'bold', },
a = { b = { bg = colors.light_gray, fg = colors.white, },
bg = colors.yellow, c = { bg = colors.grey, fg = colors.white, },
fg = colors.black,
},
b = {
bg = colors.light_gray,
fg = colors.white,
},
c = {
bg = colors.grey,
fg = colors.white,
},
} }
M.replace = { dracula.replace = {
a = { a = { bg = colors.red, fg = colors.black, gui = 'bold', },
bg = colors.red, b = { bg = colors.light_gray, fg = colors.white, },
fg = colors.black, c = { bg = colors.grey, fg = colors.white, },
},
b = {
bg = colors.light_gray,
fg = colors.white,
},
c = {
bg = colors.grey,
fg = colors.white,
},
} }
M.command = { dracula.command = {
a = { a = { bg = colors.grey, fg = colors.white, gui = 'bold', },
bg = colors.grey, b = { bg = colors.light_gray, fg = colors.white, },
fg = colors.white, c = { bg = colors.purple, fg = colors.white },
},
b = {
bg = colors.light_gray,
fg = colors.white,
},
c = {
bg = colors.purple,
fg = colors.white
},
} }
M.terminal = M.normal dracula.inactive = {
a = { bg = colors.white, fg = colors.purple, gui = 'bold', },
M.inactive = { b = { bg = colors.grey, fg = colors.purple, },
a = { c = { bg = colors.purple, fg = colors.purple, },
bg = colors.white,
fg = colors.purple,
},
b = {
bg = colors.grey,
fg = colors.purple,
},
c = {
bg = colors.purple,
fg = colors.purple,
},
} }
return M return dracula

View File

@ -1,121 +1,58 @@
local forest_night = {} local forest_night = {}
local colors = { local colors = {
bg0 = "#323d43", bg0 = {"#323d43", 237},
bg1 = "#3c474d", bg1 = {"#3c474d", 238},
bg3 = "#505a60", bg3 = {"#505a60", 240},
fg = "#d8caac", fg = {"#d8caac", 187},
aqua = "#87c095", aqua = {"#87c095", 108},
green = "#a7c080", green = {"#a7c080", 144},
orange = "#e39b7b", orange = {"#e39b7b", 180},
purple = "#d39bb6", purple = {"#d39bb6", 181},
red = "#e68183", red = {"#e68183", 174},
grey1 = "#868d80", grey1 = {"#868d80", 102},
} }
forest_night.normal = { forest_night.normal = {
a = { a = { bg = colors.green, fg = colors.bg0, gui = 'bold', },
bg = colors.green, b = { bg = colors.bg3, fg = colors.fg, },
fg = colors.bg0, c = { bg = colors.bg1, fg = colors.fg, },
},
b = {
bg = colors.bg3,
fg = colors.fg,
},
c = {
bg = colors.bg1,
fg = colors.fg,
},
} }
forest_night.insert = { forest_night.insert = {
a = { a = { bg = colors.fg, fg = colors.bg0, gui = 'bold', },
bg = colors.fg, b = { bg = colors.bg3, fg = colors.fg, },
fg = colors.bg0, c = { bg = colors.bg1, fg = colors.fg, },
},
b = {
bg = colors.bg3,
fg = colors.fg,
},
c = {
bg = colors.bg1,
fg = colors.fg,
},
} }
forest_night.visual = { forest_night.visual = {
a = { a = { bg = colors.red, fg = colors.bg0, gui = 'bold', },
bg = colors.red, b = { bg = colors.bg3, fg = colors.fg, },
fg = colors.bg0, c = { bg = colors.bg1, fg = colors.fg, },
},
b = {
bg = colors.bg3,
fg = colors.fg,
},
c = {
bg = colors.bg1,
fg = colors.fg,
},
} }
forest_night.replace = { forest_night.replace = {
a = { a = { bg = colors.orange, fg = colors.bg0, gui = 'bold', },
bg = colors.orange, b = { bg = colors.bg3, fg = colors.fg, },
fg = colors.bg0, c = { bg = colors.bg1, fg = colors.fg, },
},
b = {
bg = colors.bg3,
fg = colors.fg,
},
c = {
bg = colors.bg1,
fg = colors.fg,
},
} }
forest_night.command = { forest_night.command = {
a = { a = { bg = colors.aqua, fg = colors.bg0, gui = 'bold', },
bg = colors.aqua, b = { bg = colors.bg3, fg = colors.fg, },
fg = colors.bg0, c = { bg = colors.bg1, fg = colors.fg, },
},
b = {
bg = colors.bg3,
fg = colors.fg,
},
c = {
bg = colors.bg1,
fg = colors.fg,
},
} }
forest_night.terminal = { forest_night.terminal = {
a = { a = { bg = colors.purple, fg = colors.bg0, gui = 'bold', },
bg = colors.purple, b = { bg = colors.bg3, fg = colors.fg, },
fg = colors.bg0, c = { bg = colors.bg1, fg = colors.fg, },
},
b = {
bg = colors.bg3,
fg = colors.fg,
},
c = {
bg = colors.bg1,
fg = colors.fg,
},
} }
forest_night.inactive = { forest_night.inactive = {
a = { a = { bg = colors.bg1, fg = colors.grey1, gui = 'bold', },
bg = colors.bg1, b = { bg = colors.bg1, fg = colors.grey1, },
fg = colors.grey1, c = { bg = colors.bg1, fg = colors.grey1, },
},
b = {
bg = colors.bg1,
fg = colors.grey1,
},
c = {
bg = colors.bg1,
fg = colors.grey1,
},
} }
return forest_night return forest_night

View File

@ -1,111 +1,53 @@
local M = { } local gruvbox = {}
local colors = { local colors = {
black = "#282828", black = {"#282828", 235},
white = '#ebdbb2', white = {'#ebdbb2', 223},
red = '#fb4934', red = {'#fb4934', 203},
green = '#b8bb26', green = {'#b8bb26', 143},
blue = '#83a598', blue = {'#83a598', 108},
yellow = '#fe8019', yellow = {'#fe8019', 209},
gray = {'#a89984', 144},
gray = '#a89984', darkgray = {'#3c3836', 237},
darkgray = '#3c3836', lightgray = {'#504945', 239},
inactivegray = {'#7c6f64', 242},
lightgray = '#504945',
inactivegray = '#7c6f64',
} }
M.normal = { gruvbox.normal = {
a = { a = { bg = colors.gray, fg = colors.black, gui = 'bold', },
bg = colors.gray, b = { bg = colors.lightgray, fg = colors.white, },
fg = colors.black, c = { bg = colors.darkgray, fg = colors.gray }
},
b = {
bg = colors.lightgray,
fg = colors.white,
},
c = {
bg = colors.darkgray,
fg = colors.gray
}
} }
M.insert = { gruvbox.insert = {
a = { a = { bg = colors.blue, fg = colors.black, gui = 'bold', },
bg = colors.blue, b = { bg = colors.lightgray, fg = colors.white, },
fg = colors.black, c = { bg = colors.lightgray, fg = colors.white }
},
b = {
bg = colors.lightgray,
fg = colors.white,
},
c = {
bg = colors.lightgray,
fg = colors.white
}
} }
M.visual = { gruvbox.visual = {
a = { a = { bg = colors.yellow, fg = colors.black, gui = 'bold', },
bg = colors.yellow, b = { bg = colors.lightgray, fg = colors.white, },
fg = colors.black, c = { bg = colors.inactivegray, fg = colors.black },
},
b = {
bg = colors.lightgray,
fg = colors.white,
},
c = {
bg = colors.inactivegray,
fg = colors.black
},
} }
M.replace = { gruvbox.replace = {
a = { a = { bg = colors.red, fg = colors.black, gui = 'bold', },
bg = colors.red, b = { bg = colors.lightgray, fg = colors.white, },
fg = colors.black, c = { bg = colors.black, fg = colors.white },
},
b = {
bg = colors.lightgray,
fg = colors.white,
},
c = {
bg = colors.black,
fg = colors.white
},
} }
M.command = { gruvbox.command = {
a = { a = { bg = colors.green, fg = colors.black, gui = 'bold', },
bg = colors.green, b = { bg = colors.lightgray, fg = colors.white, },
fg = colors.black, c = { bg = colors.inactivegray, fg = colors.black },
},
b = {
bg = colors.lightgray,
fg = colors.white,
},
c = {
bg = colors.inactivegray,
fg = colors.black
},
} }
M.terminal = M.normal gruvbox.inactive = {
a = { bg = colors.darkgray, fg = colors.gray, gui = 'bold', },
M.inactive = { b = { bg = colors.darkgray, fg = colors.gray, },
a = { c = { bg = colors.darkgray, fg = colors.gray },
bg = colors.darkgray,
fg = colors.gray,
},
b = {
bg = colors.darkgray,
fg = colors.gray,
},
c = {
bg = colors.darkgray,
fg = colors.gray
},
} }
return M return gruvbox

View File

@ -1,76 +1,37 @@
local M = { } local nord = {}
local colors = { local colors = {
nord1 = "#3B4252", nord1 = {"#3B4252", 237},
nord3 = "#4C566A", nord3 = {"#4C566A", 240},
nord5 = "#E5E9F0", nord5 = {"#E5E9F0", 254},
nord6 = "#ECEFF4", nord6 = {"#ECEFF4", 255},
nord7 = "#8FBCBB", nord7 = {"#8FBCBB", 158},
nord8 = "#88C0D0", nord8 = {"#88C0D0", 159},
nord13 = "#EBCB8B", nord13 = {"#EBCB8B", 221},
} }
M.normal = { nord.normal = {
a = { a = { fg = colors.nord1, bg = colors.nord8, gui = 'bold', },
fg = colors.nord1, b = { fg = colors.nord5, bg = colors.nord1, },
bg = colors.nord8, c = { fg = colors.nord5, bg = colors.nord3, }
},
b = {
fg = colors.nord5,
bg = colors.nord1,
},
c = {
fg = colors.nord5,
bg = colors.nord3,
}
} }
M.insert = { nord.insert = {
a = { a = { fg = colors.nord1, bg = colors.nord6, gui = 'bold', },
fg = colors.nord1,
bg = colors.nord6,
},
b = M.normal.b,
c = M.normal.c,
} }
nord.visual = {
M.visual = { a = { fg = colors.nord1, bg = colors.nord7, gui = 'bold', },
a = {
fg = colors.nord1,
bg = colors.nord7,
},
b = M.normal.b,
c = M.normal.c,
} }
M.replace = { nord.replace = {
a = { a = { fg = colors.nord1, bg = colors.nord13, gui = 'bold', },
fg = colors.nord1,
bg = colors.nord13,
},
b = M.normal.b,
c = M.normal.c,
} }
M.command = M.normal nord.inactive = {
a = { fg = colors.nord1, bg = colors.nord8, gui = 'bold', },
M.terminal = M.normal b = { fg = colors.nord5, bg = colors.nord1, },
c = { fg = colors.nord5, bg = colors.nord1, },
M.inactive = {
a = {
fg = colors.nord1,
bg = colors.nord8,
},
b = {
fg = colors.nord5,
bg = colors.nord1,
},
c = {
fg = colors.nord5,
bg = colors.nord1,
},
} }
return M return nord

View File

@ -1,102 +1,44 @@
local M = { } local onedark = {}
local colors = { local colors = {
red = "#E06C75", red = {"#E06C75", 168},
dark_red = "#BE5046", dark_red = {"#BE5046", 131},
green = "#98C379", green = {"#98C379", 114},
yellow = "#E5C07B", blue = {"#61AFEF", 75 },
dark_yellow = "#D19A66", purple = {"#C678DD", 176},
blue = "#61AFEF", white = {"#ABB2BF", 249},
purple = "#C678DD", black = {"#282C34", 236},
cyan = "#56B6C2", visual_grey = {"#3E4452", 238},
white = "#ABB2BF",
black = "#282C34",
visual_black = "NONE",
comment_grey = "#5C6370",
gutter_fg_grey = "#4B5263",
cursor_grey = "#2C323C",
visual_grey = "#3E4452",
menu_grey = "#3E4452",
special_grey = "#3B4048",
vertsplit = "#181A1F",
} }
M.normal = { onedark.normal = {
a = { a = { fg = colors.black, bg = colors.green, gui = 'bold', },
fg = colors.black, b = { fg = colors.white, bg = colors.visual_grey, },
bg = colors.green, c = { fg = colors.green, bg = colors.black, },
},
b = {
fg = colors.white,
bg = colors.visual_grey,
},
c = {
fg = colors.green,
bg = colors.black,
},
} }
M.insert = { onedark.insert = {
a = { a = { fg = colors.black, bg = colors.blue, gui = 'bold', },
fg = colors.black, b = { fg = colors.white, bg = colors.visual_grey, },
bg = colors.blue, c = { fg = colors.blue, bg = colors.black, },
},
b = {
fg = colors.white,
bg = colors.visual_grey,
},
c = {
fg = colors.blue,
bg = colors.black,
},
} }
M.visual = { onedark.visual = {
a = { a = { fg = colors.black, bg = colors.purple, gui = 'bold', },
fg = colors.black, b = { fg = colors.white, bg = colors.visual_grey, },
bg = colors.purple, c = { fg = colors.purple, bg = colors.black, },
},
b = {
fg = colors.white,
bg = colors.visual_grey,
},
c = {
fg = colors.purple,
bg = colors.black,
},
} }
M.replace = { onedark.replace = {
a = { a = { fg = colors.black, bg = colors.red, gui = 'bold', },
fg = colors.black, b = { fg = colors.white, bg = colors.visual_grey, },
bg = colors.red, c = { fg = colors.red, bg = colors.black, },
},
b = {
fg = colors.white,
bg = colors.visual_grey,
},
c = {
fg = colors.red,
bg = colors.black,
},
} }
M.terminal = M.normal onedark.inactive = {
M.command = M.normal a = { fg = colors.black, bg = colors.white, gui = 'bold', },
b = { fg = colors.white, bg = colors.visual_grey, },
M.inactive = { c = { fg = colors.white, bg = colors.visual_grey, },
a = {
fg = colors.black,
bg = colors.white,
},
b = {
fg = colors.white,
bg = colors.visual_grey,
},
c = {
fg = colors.white,
bg = colors.visual_grey,
},
} }
return M return onedark

View File

@ -1,88 +1,48 @@
local M = { } local powerline = { }
local Colors = { local Colors = {
white = '#ffffff', white = {'#ffffff', 231},
darkestgreen = '#005f00', darkestgreen = {'#005f00', 22 },
brightgreen = '#afdf00', brightgreen = {'#afdf00', 148},
darkestcyan = '#005f5f', darkestcyan = {'#005f5f', 23 },
mediumcyan = '#87dfff', mediumcyan = {'#87dfff', 117},
darkestblue = '#005f87', darkestblue = {'#005f87', 24 },
darkred = '#870000', darkred = {'#870000', 88 },
brightred = '#df0000', brightred = {'#df0000', 160},
brightorange = '#ff8700', brightorange = {'#ff8700', 214},
gray1 = '#262626', gray1 = {'#262626', 235},
gray2 = '#303030', gray2 = {'#303030', 236},
gray4 = '#585858', gray4 = {'#585858', 240},
gray5 = '#606060', gray5 = {'#606060', 241},
gray7 = '#9e9e9e', gray7 = {'#9e9e9e', 245},
gray10 = '#f0f0f0', gray10 = {'#f0f0f0', 252},
} }
M.normal = { powerline.normal = {
a = { a = { fg = Colors.darkestgreen, bg = Colors.brightgreen, gui = 'bold', },
fg = Colors.darkestgreen, b = { fg = Colors.gray10, bg = Colors.gray5, },
bg = Colors.brightgreen, c = { fg = Colors.gray7, bg = Colors.gray2, },
},
b = {
fg = Colors.gray10,
bg = Colors.gray5,
},
c = {
fg = Colors.gray7,
bg = Colors.gray2,
},
} }
M.insert = { powerline.insert = {
a = { a = { fg = Colors.darkestcyan, bg = Colors.white, gui = 'bold', },
fg = Colors.darkestcyan, b = { fg = Colors.darkestcyan, bg = Colors.mediumcyan, },
bg = Colors.white, c = { fg = Colors.mediumcyan, bg = Colors.darkestblue, },
},
b = {
fg = Colors.darkestcyan,
bg = Colors.mediumcyan,
},
c = {
fg = Colors.mediumcyan,
bg = Colors.darkestblue,
},
} }
M.visual = { powerline.visual = {
a = { a = { fg = Colors.darkred, bg = Colors.brightorange, gui = 'bold', },
fg = Colors.darkred,
bg = Colors.brightorange,
},
b = M.normal.b,
c = M.normal.c,
} }
M.replace = { powerline.replace = {
a = { a = { fg = Colors.white, bg = Colors.brightred, gui = 'bold', },
fg = Colors.white,
bg = Colors.brightred,
},
b = M.normal.b,
c = M.normal.c,
} }
M.command = M.normal powerline.inactive = {
M.terminal = M.normal a = { fg = Colors.gray1, bg = Colors.gray5, gui = 'bold', },
b = { fg = Colors.gray1, bg = Colors.gray5, },
M.inactive = { c = { bg = Colors.gray1, fg = Colors.gray5, },
a = {
fg = Colors.gray1,
bg = Colors.gray5,
},
b = {
fg = Colors.gray1,
bg = Colors.gray5,
},
c = {
bg = Colors.gray1,
fg = Colors.gray5,
},
} }
return M return powerline

View File

@ -18,4 +18,301 @@ function M.draw_section(section, separator)
return ' ' .. table.concat(status, sep) .. ' ' return ' ' .. table.concat(status, sep) .. ' '
end end
-- color conversion
local color_table = {
-- lookup table for cterm colors
-- format {'color_code', {r,g,b}}
-- Primary 3-bit (8 colors). Unique representation!
{'00', { 0, 0, 0 }},
{'01', { 128, 0, 0 }},
{'02', { 0, 128, 0 }},
{'03', { 128, 128, 0 }},
{'04', { 0, 0, 128 }},
{'05', { 128, 0, 128 }},
{'06', { 0, 128, 128 }},
{'07', { 192, 192, 192 }},
-- equivalent "bright" versions of original 8 colors.
{'08', { 128, 128, 128 }},
{'09', { 255, 0, 0 }},
{'10', { 0, 255, 0 }},
{'11', { 255, 255, 0 }},
{'12', { 0, 0, 255 }},
{'13', { 255, 0, 255 }},
{'14', { 0, 255, 255 }},
{'15', { 255, 255, 255 }},
-- Strictly ascending.
{'16', { 0, 0, 0 }},
{'17', { 0, 0, 95 }},
{'18', { 0, 0, 135 }},
{'19', { 0, 0, 175 }},
{'20', { 0, 0, 215 }},
{'21', { 0, 0, 255 }},
{'22', { 0, 95, 0 }},
{'23', { 0, 95, 95 }},
{'24', { 0, 95, 135 }},
{'25', { 0, 95, 175 }},
{'26', { 0, 95, 215 }},
{'27', { 0, 95, 255 }},
{'28', { 0, 135, 0 }},
{'29', { 0, 135, 95 }},
{'30', { 0, 135, 135 }},
{'31', { 0, 135, 175 }},
{'32', { 0, 135, 215 }},
{'33', { 0, 135, 255 }},
{'34', { 0, 175, 0 }},
{'35', { 0, 175, 95 }},
{'36', { 0, 175, 135 }},
{'37', { 0, 175, 175 }},
{'38', { 0, 175, 215 }},
{'39', { 0, 175, 255 }},
{'40', { 0, 215, 0 }},
{'41', { 0, 215, 95 }},
{'42', { 0, 215, 135 }},
{'43', { 0, 215, 175 }},
{'44', { 0, 215, 215 }},
{'45', { 0, 215, 255 }},
{'46', { 0, 255, 0 }},
{'47', { 0, 255, 95 }},
{'48', { 0, 255, 135 }},
{'49', { 0, 255, 175 }},
{'50', { 0, 255, 215 }},
{'51', { 0, 255, 255 }},
{'52', { 95, 0, 0 }},
{'53', { 95, 0, 95 }},
{'54', { 95, 0, 135 }},
{'55', { 95, 0, 175 }},
{'56', { 95, 0, 215 }},
{'57', { 95, 0, 255 }},
{'58', { 95, 95, 0 }},
{'59', { 95, 95, 95 }},
{'60', { 95, 95, 135 }},
{'61', { 95, 95, 175 }},
{'62', { 95, 95, 215 }},
{'63', { 95, 95, 255 }},
{'64', { 95, 135, 0 }},
{'65', { 95, 135, 95 }},
{'66', { 95, 135, 135 }},
{'67', { 95, 135, 175 }},
{'68', { 95, 135, 215 }},
{'69', { 95, 135, 255 }},
{'70', { 95, 175, 0 }},
{'71', { 95, 175, 95 }},
{'72', { 95, 175, 135 }},
{'73', { 95, 175, 175 }},
{'74', { 95, 175, 215 }},
{'75', { 95, 175, 255 }},
{'76', { 95, 215, 0 }},
{'77', { 95, 215, 95 }},
{'78', { 95, 215, 135 }},
{'79', { 95, 215, 175 }},
{'80', { 95, 215, 215 }},
{'81', { 95, 215, 255 }},
{'82', { 95, 255, 0 }},
{'83', { 95, 255, 95 }},
{'84', { 95, 255, 135 }},
{'85', { 95, 255, 175 }},
{'86', { 95, 255, 215 }},
{'87', { 95, 255, 255 }},
{'88', { 135, 0, 0 }},
{'89', { 135, 0, 95 }},
{'90', { 135, 0, 135 }},
{'91', { 135, 0, 175 }},
{'92', { 135, 0, 215 }},
{'93', { 135, 0, 255 }},
{'94', { 135, 95, 0 }},
{'95', { 135, 95, 95 }},
{'96', { 135, 95, 135 }},
{'97', { 135, 95, 175 }},
{'98', { 135, 95, 215 }},
{'99', { 135, 95, 255 }},
{'100', { 135, 135, 0 }},
{'101', { 135, 135, 95 }},
{'102', { 135, 135, 135 }},
{'103', { 135, 135, 175 }},
{'104', { 135, 135, 215 }},
{'105', { 135, 135, 255 }},
{'106', { 135, 175, 0 }},
{'107', { 135, 175, 95 }},
{'108', { 135, 175, 135 }},
{'109', { 135, 175, 175 }},
{'110', { 135, 175, 215 }},
{'111', { 135, 175, 255 }},
{'112', { 135, 215, 0 }},
{'113', { 135, 215, 95 }},
{'114', { 135, 215, 135 }},
{'115', { 135, 215, 175 }},
{'116', { 135, 215, 215 }},
{'117', { 135, 215, 255 }},
{'118', { 135, 255, 0 }},
{'119', { 135, 255, 95 }},
{'120', { 135, 255, 135 }},
{'121', { 135, 255, 175 }},
{'122', { 135, 255, 215 }},
{'123', { 135, 255, 255 }},
{'124', { 175, 0, 0 }},
{'125', { 175, 0, 95 }},
{'126', { 175, 0, 135 }},
{'127', { 175, 0, 175 }},
{'128', { 175, 0, 215 }},
{'129', { 175, 0, 255 }},
{'130', { 175, 95, 0 }},
{'131', { 175, 95, 95 }},
{'132', { 175, 95, 135 }},
{'133', { 175, 95, 175 }},
{'134', { 175, 95, 215 }},
{'135', { 175, 95, 255 }},
{'136', { 175, 135, 0 }},
{'137', { 175, 135, 95 }},
{'138', { 175, 135, 135 }},
{'139', { 175, 135, 175 }},
{'140', { 175, 135, 215 }},
{'141', { 175, 135, 255 }},
{'142', { 175, 175, 0 }},
{'143', { 175, 175, 95 }},
{'144', { 175, 175, 135 }},
{'145', { 175, 175, 175 }},
{'146', { 175, 175, 215 }},
{'147', { 175, 175, 255 }},
{'148', { 175, 215, 0 }},
{'149', { 175, 215, 95 }},
{'150', { 175, 215, 135 }},
{'151', { 175, 215, 175 }},
{'152', { 175, 215, 215 }},
{'153', { 175, 215, 255 }},
{'154', { 175, 255, 0 }},
{'155', { 175, 255, 95 }},
{'156', { 175, 255, 135 }},
{'157', { 175, 255, 175 }},
{'158', { 175, 255, 215 }},
{'159', { 175, 255, 255 }},
{'160', { 215, 0, 0 }},
{'161', { 215, 0, 95 }},
{'162', { 215, 0, 135 }},
{'163', { 215, 0, 175 }},
{'164', { 215, 0, 215 }},
{'165', { 215, 0, 255 }},
{'166', { 215, 95, 0 }},
{'167', { 215, 95, 95 }},
{'168', { 215, 95, 135 }},
{'169', { 215, 95, 175 }},
{'170', { 215, 95, 215 }},
{'171', { 215, 95, 255 }},
{'172', { 215, 135, 0 }},
{'173', { 215, 135, 95 }},
{'174', { 215, 135, 135 }},
{'175', { 215, 135, 175 }},
{'176', { 215, 135, 215 }},
{'177', { 215, 135, 255 }},
{'178', { 215, 175, 0 }},
{'179', { 215, 175, 95 }},
{'180', { 215, 175, 135 }},
{'181', { 215, 175, 175 }},
{'182', { 215, 175, 215 }},
{'183', { 215, 175, 255 }},
{'184', { 215, 215, 0 }},
{'185', { 215, 215, 95 }},
{'186', { 215, 215, 135 }},
{'187', { 215, 215, 175 }},
{'188', { 215, 215, 215 }},
{'189', { 215, 215, 255 }},
{'190', { 215, 255, 0 }},
{'191', { 215, 255, 95 }},
{'192', { 215, 255, 135 }},
{'193', { 215, 255, 175 }},
{'194', { 215, 255, 215 }},
{'195', { 215, 255, 255 }},
{'196', { 255, 0, 0 }},
{'197', { 255, 0, 95 }},
{'198', { 255, 0, 135 }},
{'199', { 255, 0, 175 }},
{'200', { 255, 0, 215 }},
{'201', { 255, 0, 255 }},
{'202', { 255, 95, 0 }},
{'203', { 255, 95, 95 }},
{'204', { 255, 95, 135 }},
{'205', { 255, 95, 175 }},
{'206', { 255, 95, 215 }},
{'207', { 255, 95, 255 }},
{'208', { 255, 135, 0 }},
{'209', { 255, 135, 95 }},
{'210', { 255, 135, 135 }},
{'211', { 255, 135, 175 }},
{'212', { 255, 135, 215 }},
{'213', { 255, 135, 255 }},
{'214', { 255, 175, 0 }},
{'215', { 255, 175, 95 }},
{'216', { 255, 175, 135 }},
{'217', { 255, 175, 175 }},
{'218', { 255, 175, 215 }},
{'219', { 255, 175, 255 }},
{'220', { 255, 215, 0 }},
{'221', { 255, 215, 95 }},
{'222', { 255, 215, 135 }},
{'223', { 255, 215, 175 }},
{'224', { 255, 215, 215 }},
{'225', { 255, 215, 255 }},
{'226', { 255, 255, 0 }},
{'227', { 255, 255, 95 }},
{'228', { 255, 255, 135 }},
{'229', { 255, 255, 175 }},
{'230', { 255, 255, 215 }},
{'231', { 255, 255, 255 }},
-- Gray-scale range.
{'232', { 8, 8, 8 }},
{'233', { 18, 18, 18 }},
{'234', { 28, 28, 28 }},
{'235', { 38, 38, 38 }},
{'236', { 48, 48, 48 }},
{'237', { 58, 58, 58 }},
{'238', { 68, 68, 68 }},
{'239', { 78, 78, 78 }},
{'240', { 88, 88, 88 }},
{'241', { 98, 98, 98 }},
{'242', { 108, 108, 108 }},
{'243', { 118, 118, 118 }},
{'244', { 128, 128, 128 }},
{'245', { 138, 138, 138 }},
{'246', { 148, 148, 148 }},
{'247', { 158, 158, 158 }},
{'248', { 168, 168, 168 }},
{'249', { 178, 178, 178 }},
{'250', { 188, 188, 188 }},
{'251', { 198, 198, 198 }},
{'252', { 208, 208, 208 }},
{'253', { 218, 218, 218 }},
{'254', { 228, 228, 228 }},
{'255', { 238, 238, 238 }},
}
function M.get_cterm_color(hex_color)
local function get_color_distance(color1, color2)
-- returns how much color2 deviates from color1
local dr = math.abs(color1[1] - color2[1]) / (color1[1]+1) * 100
local dg = math.abs(color1[2] - color2[2]) / (color1[2]+1) * 100
local db = math.abs(color1[3] - color2[3]) / (color1[3]+1) * 100
return (dr + dg + db)
end
local r = tonumber(hex_color:sub(2,3), 16)
local g = tonumber(hex_color:sub(4,5), 16)
local b = tonumber(hex_color:sub(6,7), 16)
-- check which cterm color is closest to hex colors in terms of rgb values
local closest_cterm_color = 0
local min_distance = 10000
for _, color in ipairs(color_table) do
local current_distance = get_color_distance(color[2], {r,g,b})
if current_distance < min_distance then
min_distance = current_distance
closest_cterm_color = color[1]
end
end
return closest_cterm_color
end
return M return M