Browse Source

feat: rewrite colorscheme

!!!WIP

Based on my previous colorscheme (Polyjuice). The dark theme is the
same, the light one is a rework of a previous attempt

Scheme structure inspired by nebulous (https://github.com/Yagua/nebulous.nvim)
main
David JULIEN 3 months ago
parent
commit
c329ff44d3
  1. 34
      lua/astronomy/colors/blackhole.lua
  2. 49
      lua/astronomy/colors/init.lua
  3. 34
      lua/astronomy/colors/pulsar.lua
  4. 44
      lua/astronomy/config.lua
  5. 45
      lua/astronomy/functions.lua
  6. 22
      lua/astronomy/init.lua
  7. 210
      lua/astronomy/scheme.lua
  8. 70
      lua/astronomy/utils.lua

34
lua/astronomy/colors/blackhole.lua

@ -0,0 +1,34 @@
-- Author : swytch
-- Created : Friday Oct. 22, 2021 22:04:40 CET
-- License : GPLv3
-- Description : dark theme colors file
local M = {
-- dark
black = "#131616",
darkred = "#b73935",
darkgreen = "#427d61",
orange = "#f7a583",
darkblue = "#458588",
darkmagenta = "#b16286",
darkcyan = "#7cafa3",
grey = "#a89984",
-- light
darkgrey = "#373737",
red = "#ea6962",
green = "#89b482",
yellow = "#ffeca3",
blue = "#7daea3",
magenta = "#d3869b",
cyan = "#ace5d7",
white = "#fbf1c7",
background = "#131616",
background_alt = "#373737",
foreground = "#fbf1c7",
foreground_alt = "#a89984",
}
return M

49
lua/astronomy/colors/init.lua

@ -0,0 +1,49 @@
-- Author : swytch
-- Created : Friday Oct. 22, 2021 22:04:40 CET
-- License : GPLv3
-- Description : variant management file
local colors = {}
colors.variants = {
[1] = "blackhole",
[2] = "pulsar",
}
-- Check for the existence of a variant in the variant table
--@param val string: variant to search for
--@return exists boolean: boolean value with the search response
local function variant_exists(val)
local variant = val or ""
local index = vim.fn.index(colors.variants, variant)
local exists = index >= 0 and true or false
return exists, (index + 1)
end
-- Select variant color and return it
--@param variant string: name of the selected color variant
--@return scheme table: editor elements with its respective colors
function colors.set_scheme(variant)
local scheme = {}
local variant_selected = variant or ""
local exists, index = variant_exists(variant_selected)
if exists then
_, scheme = pcall(require,
string.format("astronomy.colors.%s", variant_selected))
vim.g.astronomy_variant_loaded = index
else
scheme = require("astronomy.colors.blackhole")
print(string.format(
"[astronomy] the variant '%s' does not exists;",
variant_selected),
"default variant was set."
)
vim.g.astronomy_variant_loaded = 1
end
scheme.none = "NONE"
return scheme
end
return colors

34
lua/astronomy/colors/pulsar.lua

@ -0,0 +1,34 @@
-- Author : swytch
-- Created : Friday Oct. 22, 2021 22:04:40 CET
-- License : GPLv3
-- Description : light theme colors file
local M = {
-- dark
black = "#1d2021",
darkred = "#9d0006",
darkgreen = "#427d61",
orange = "#d65d0e",
darkblue = "#076678",
darkmagenta = "#8f3f71",
darkcyan = "#4a8785",
grey = "#a89984",
-- light
darkgrey = "#373737",
red = "#b73935",
green = "#689d6a",
yellow = "#e1aa2a",
blue = "#458588",
magenta = "#b16286",
cyan = "#7cafa3",
white = "#fbf1c7",
background = "#fbf1c7",
background_alt = "#ebdbb2",
foreground = "#1d2021",
foreground_alt = "#665c64",
}
return M

44
lua/astronomy/config.lua

@ -0,0 +1,44 @@
-- Author : swytch
-- Created : Friday Oct. 22, 2021 22:04:40 CET
-- License : GPLv3
-- Description : colorscheme config file
local M = {}
-- Default scheme options
M.scheme_options = {
variant = "blackhole",
disable = {
background = false,
endOfBuffer = true,
},
custom_colors = {}
}
-- Set custom options to the editor
--@param opts table: custom options for editor
function M.set_options(opts)
local options = opts or {}
if type(options) == "table" then
local new_sets = vim.tbl_deep_extend(
"force", {}, M.scheme_options, options
)
M.scheme_options = new_sets
end
end
-- Get the value of secheme options
--@param tab table: custom options to be applied to the editor scheme
--@returns settings table: settings adapted to load the scheme
function M.get_options()
local settings = {}
local opts = M.scheme_options
settings.eof = opts.disable.endOfBuffer
settings.disable_bg = opts.disable.background and "NONE"
return settings
end
return M

45
lua/astronomy/functions.lua

@ -0,0 +1,45 @@
-- Author : swytch
-- Created : Friday Oct. 22, 2021 22:04:40 CET
-- License : GPLv3
-- Description : top-level functions file
local M = {}
local utils = require("astronomy.utils")
local variants = require("astronomy.colors").variants
local g = vim.g
--- Returns the position of the variant that will be loaded.
--@param v_tab table: table of variants
--@parma pos number: a position to search in the table of variants
--@return position number: a valid position for setting a variant from the variant table
local function change_variant(v_tab, pos)
if next(v_tab) == nil then return end
return table.getn(v_tab) > pos and pos + 1 or 1
end
---Set a especific variant
--@param scheme string: name of the variant to be set
function M.set_variant(scheme)
local variant = scheme or ""
utils.setup_scheme { variant = variant }
end
--- Sets a variant in accordance with a valid position in the variants table
--@param position number: position to load a variant from the variant table
local function load_variant(position)
local variant = variants[position]
g.astronomy_variant_loaded = position
M.set_variant(variant)
vim.api.nvim_command(string.format("echo \"[astronomy] colorscheme changed to '%s'\"", variant))
end
--- Set a variant by scrolling through the variant table in an orderly fashion
function M.toggle_variant()
local position = change_variant(
variants, g.astronomy_variant_loaded
)
load_variant(position)
end
return M

22
lua/astronomy/init.lua

@ -0,0 +1,22 @@
--[[
Title: astronomy.nvim
Description: Simplistic theme for neovim, written in lua
Author: swy7ch <swy7ch@protonmail.com>
Website: https://github.com/swy7ch/astronomy.git
--]]
local utils = require("astronomy.utils")
local functions = require("astronomy.functions")
local M = {}
-- Setup function to load the colorscheme
--@param opts table: custom options to be applied to the editor
function M.setup(opts)
utils.setup_scheme(opts)
end
M.toggle_variant = functions.toggle_variant
M.random_variant = functions.random_variant
M.set_variant = functions.set_variant
return M

210
lua/astronomy/scheme.lua

@ -0,0 +1,210 @@
-- Author : swytch
-- Created : Friday Oct. 22, 2021 22:04:40 CET
-- License : GPLv3
-- Description : scheme loading file
-- local config = require("astronomy.config")
local M = {}
local g = vim.g
-- Load terminal colors
--@param tab table: scheme colors to apply
local function terminal_colors(tab)
g.terminal_color_0 = tab.black
g.terminal_color_1 = tab.darkred
g.terminal_color_2 = tab.darkgreen
g.terminal_color_3 = tab.orange
g.terminal_color_4 = tab.darkblue
g.terminal_color_5 = tab.darkmagenta
g.terminal_color_6 = tab.darkcyan
g.terminal_color_7 = tab.grey
g.terminal_color_8 = tab.darkgrey
g.terminal_color_9 = tab.red
g.terminal_color_10 = tab.green
g.terminal_color_11 = tab.yellow
g.terminal_color_12 = tab.blue
g.terminal_color_13 = tab.magenta
g.terminal_color_14 = tab.cyan
g.terminal_color_15 = tab.white
end
-- load colorscheme elements
--@param scheme table: colors to apply
--@param settings table: custom options to be applied to the scheme
--@return colors table: all groups and its respectives colors
function M.load_colors(scheme)
-- local opts = config.get_options()
local colors = {
---------------------
-- EDITOR COLORS --
---------------------
Normal = { fg = scheme.foreground, bg = scheme.background, scheme.none },
NormalFloat = { fg = scheme.foreground, bg = scheme.background_alt, scheme.none },
Terminal = { link = "Normal" },
Visual = { fg = scheme.yellow, bg = scheme.background_alt, scheme.none },
VisualNOS = { link = "Visual" },
Cursor = { fg = scheme.background, bg = scheme.foreground, scheme.none },
CursorLine = { fg = scheme.none, bg = scheme.background_alt, scheme.none },
CursorColumn = { link = "CursorLine" },
CursorLineNr = { fg = scheme.orange, bg = scheme.none, scheme.none },
LineNr = { fg = scheme.grey, bg = scheme.none, scheme.none },
VertSplit = { fg = scheme.grey, bg = scheme.none, scheme.none },
SignColumn = { fg = scheme.yellow, bg = scheme.none, scheme.none },
Folded = { fg = scheme.orange, bg = scheme.background_alt, scheme.none },
---------------------
---- STATUSLINE -----
---------------------
StatusLine = { fg = scheme.none, bg = scheme.background, scheme.none },
StatusLineTerm = { fg = scheme.none, bg = scheme.green, scheme.none },
StatusLineNF = { fg = scheme.foreground, bg = scheme.background_alt, scheme.none },
StatusLineNC = { fg = scheme.none, bg = scheme.none, scheme.none },
Top = { fg = scheme.background, bg = scheme.foreground_alt, scheme.none },
Middle = { fg = scheme.foreground, bg = scheme.background_alt, scheme.none },
Bottom = { fg = scheme.darkcyan, bg = scheme.background, scheme.none },
NormalMode = { fg = scheme.black, bg = scheme.green, style = "bold" },
VisualMode = { fg = scheme.black, bg = scheme.magenta, style = "bold" },
InsertMode = { fg = scheme.black, bg = scheme.cyan, style = "bold" },
ReplaceMode = { fg = scheme.black, bg = scheme.orange, style = "bold" },
CommandMode = { fg = scheme.black, bg = scheme.yellow, style = "bold" },
---------------------
----- MESSAGES ------
---------------------
Title = { fg = scheme.orange, bg = scheme.none, style = "bold" },
ErrorMsg = { fg = scheme.yellow, bg = scheme.darkred, style = "bold" },
ModeMsg = { fg = scheme.none, bg = scheme.none, style = "bold" },
MoreMsg = { fg = scheme.green, bg = scheme.none, style = "bold" },
WarningMsg = { fg = scheme.red, bg = scheme.none, style = "bold" },
---------------------
------- MENUS -------
---------------------
Pmenu = { fg = scheme.foreground, bg = scheme.background_alt, scheme.none },
PmenuSel = { fg = scheme.background, bg = scheme.darkgreen, style = "bold" },
PmenuSbar = { fg = scheme.none, bg = scheme.background_alt, scheme.none },
PmenuThumb = { link = "PmenuSbar" },
WildMenu = { link = "PmenuSel" },
---------------------
------- MENUS -------
---------------------
Conceal = { fg = scheme.grey, bg = scheme.background_alt, scheme.none },
Directory = { fg = scheme.magenta, bg = scheme.none, style = "bold" },
NonText = { fg = scheme.blue, bg = scheme.none, scheme.none },
EndOfBuffer = { link = "Nontext" },
Question = { fg = scheme.green, bg = scheme.none, style = "bold" },
Search = { fg = scheme.background, bg = scheme.grey, scheme.none },
QuickFixLine = { link = "Search" },
IncSearch = { fg = scheme.none, bg = scheme.none, style = "reverse" },
SpecialKey = { fg = scheme.green, bg = scheme.none, scheme.none },
---------------------
---- IDENTFIERS -----
---------------------
MatchParen = { fg = scheme.background, bg = scheme.blue, style = "bold" },
Comment = { fg = scheme.grey, bg = scheme.none, scheme.none },
Ignore = { link = "Comment" },
Whitespace = { link = "Comment" },
Constant = { fg = scheme.green, bg = scheme.none, scheme.none },
Boolean = { link = "Constant" },
Character = { link = "Constant" },
Number = { link = "Constant" },
Float = { link = "Constant" },
String = { link = "Constant" },
Error = { link = "ErrorMsg" },
Identifier = { fg = scheme.blue, bg = scheme.none, style = "bold" },
Function = { link = "Identifier" },
PreProc = { fg = scheme.red, bg = scheme.none, scheme.none },
Define = { link = "PreProc" },
Include = { link = "PreProc" },
Macro = { link = "PreProc" },
PreCondit = { link = "PreProc" },
Special = { fg = scheme.orange, bg = scheme.none, scheme.none },
SpecialChar = { link = "Special" },
SpecialComment = { link = "Special" },
Debug = { link = "Special" },
Delimiter = { link = "Special" },
Tag = { link = "Special" },
Statement = { fg = scheme.magenta, bg = scheme.none, scheme.none },
Conditional = { link = "Statement" },
Exception = { link = "Statement" },
Keyword = { link = "Statement" },
Label = { link = "Statement" },
Operator = { link = "Statement" },
Repeat = { link = "Statement" },
Todo = { fg = scheme.black, bg = scheme.yellow, style = "bold" },
Type = { fg = scheme.yellow, bg = scheme.none, style = "bold" },
StorageClass = { link = "Type" },
Structure = { link = "Type" },
Typedef = { link = "Type" },
Underlined = { fg = scheme.darkblue, bg = scheme.none, style = "underline" },
---------------------
-- LANGUAGE COLORS --
---------------------
---------
-- GIT --
---------
signifySignAdd = { fg = scheme.green, bg = scheme.none, scheme.none },
signifySignChange = { fg = scheme.yellow, bg = scheme.none, scheme.none },
signifySignDelete = { fg = scheme.red, bg = scheme.none, scheme.none },
gitcommitComment = { fg = scheme.grey, bg = scheme.none, scheme.none },
gitcommitDiscardedType = { fg = scheme.red, bg = scheme.none, scheme.none },
gitcommitSelectedType = { fg = scheme.green, bg = scheme.none, scheme.none },
gitcommitHeader = { fg = scheme.none, bg = scheme.none, scheme.none },
gitcommitUntrackedFile = { fg = scheme.cyan, bg = scheme.none, scheme.none },
gitcommitDiscardedFile = { fg = scheme.red, bg = scheme.none, scheme.none },
gitcommitSelectedFile = { fg = scheme.green, bg = scheme.none, scheme.none },
gitcommitUnmergedFile = { fg = scheme.yellow, bg = scheme.none, scheme.none },
gitcommitUnmerged = { fg = scheme.green, bg = scheme.none, scheme.none },
gitcommitOnBranch = { fg = scheme.none, bg = scheme.none, scheme.none },
gitcommitBranch = { fg = scheme.magenta, bg = scheme.none, scheme.none },
----------
-- diff --
----------
diffAdded = { fg = scheme.green, bg = scheme.none, scheme.none },
diffFile = { fg = scheme.orange, bg = scheme.none, scheme.none },
diffNewFile = { fg = scheme.yellow, bg = scheme.none, scheme.none },
diffChanged = { fg = scheme.cyan, bg = scheme.none, scheme.none },
diffRemoved = { fg = scheme.red, bg = scheme.none, scheme.none },
diffLine = { fg = scheme.blue, bg = scheme.none, scheme.none },
----------------
-- LSP COLORS --
----------------
DiagnosticVirtualTextWarn = { fg = scheme.orange, bg = scheme.none, scheme.none },
DiagnosticUnderlineWarn = { fg = scheme.orange, bg = scheme.none, style = "underline" },
DiagnosticFloatingWarn = { link = "DiagnosticVirtualTextWarn" },
DiagnosticSignWarn = { link = "DiagnosticVirtualTextWarn" },
DiagnosticVirtualTextError = { fg = scheme.red, bg = scheme.none, scheme.none },
DiagnosticUnderlineError = { fg = scheme.red, bg = scheme.none, style = "underline" },
DiagnosticFloatingError = { link = "DiagnosticVirtualTextError" },
DiagnosticSignError = { link = "DiagnosticVirtualTextError" },
DiagnosticVirtualTextInfo = { fg = scheme.blue, bg = scheme.none, scheme.none },
DiagnosticUnderlineInfo = { fg = scheme.blue, bg = scheme.none, style = "underline" },
DiagnosticFloatingInfo = { link = "DiagnosticVirtualTextInfo" },
DiagnosticSignInfo = { link = "DiagnosticVirtualTextInfo" },
DiagnosticVirtualTextHint = { fg = scheme.yellow, bg = scheme.none, scheme.none },
DiagnosticUnderlineHint = { fg = scheme.yellow, bg = scheme.none, style = "underline" },
DiagnosticFloatingHint = { link = "DiagnosticVirtualTextHint" },
DiagnosticSignHint = { link = "DiagnosticVirtualTextHint" },
----------------
-- COQ COLORS --
----------------
CoqtailChecked = { fg = scheme.none, bg = scheme.darkgreen, scheme.none },
CoqtailSent = { fg = scheme.none, bg = scheme.darkgrey, scheme.none },
}
terminal_colors(scheme)
return colors
end
return M

70
lua/astronomy/utils.lua

@ -0,0 +1,70 @@
-- Author : swytch
-- Created : Friday Oct. 22, 2021 22:04:40 CET
-- License : GPLv3
-- Description : core-level functions file
local config = require("astronomy.config")
local theme = require("astronomy.scheme")
local colors = require("astronomy.colors")
local api = vim.api
local M = {}
-- Apply colors in the editor
--@param group string: group name
--@param cols string: color name to be applied to the groups
local function set_highlights(group, cols)
api.nvim_command(string.format('highlight %s gui=%s guifg=%s guibg=%s guisp=%s',
group,
cols.style or "NONE",
cols.fg or "NONE",
cols.bg or "NONE",
cols.sp or "NONE"
))
if cols.link then
api.nvim_command(string.format("highlight! link %s %s", group, cols.link))
end
end
-- Load colorscheme
--@param scheme table: editor elements with its colors
--@param custom_tab table: custom color table
local function load_colorscheme(scheme, custom_tab)
local color_table = scheme or {}
local custom_colors = custom_tab or {}
-- reset the highlighting
if vim.fn.exists("sintax_on") then api.nvim_command("syntax reset") end
vim.opt.background = "dark"
vim.g.colors_name = "astronomy"
vim.g.astronomy = 1
vim.opt.termguicolors = true
if type(custom_colors) == "table" then
if next(custom_colors) ~= nil then
color_table = vim.tbl_deep_extend("force", {}, color_table, custom_colors)
end
end
--Load editor colors
for grp, col in pairs(color_table) do
set_highlights(grp, col)
end
end
-- Set and load the color scheme
--@param opts table: custom options to be applied to the editor
function M.setup_scheme(opts)
config.set_options(opts)
local sch_opts = config.scheme_options
local scheme = colors.set_scheme(sch_opts.variant)
local colorscheme = theme.load_colors(scheme)
load_colorscheme(colorscheme, sch_opts.custom_colors)
end
return M
Loading…
Cancel
Save