Skip to content

Commit

Permalink
updated lua
Browse files Browse the repository at this point in the history
  • Loading branch information
blacksheepcosmo committed Nov 22, 2024
1 parent 29f305c commit 8257341
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 68 deletions.
61 changes: 10 additions & 51 deletions lua/blackbeard/alacritty.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
-- /cvusmo/blackbeard-nvim/lua/blackbeard/alacritty.lua

local M = {}

local function write_to_file(filepath, content)
Expand Down Expand Up @@ -78,67 +80,24 @@ white = "%s"
)
end

local palettes = {
dark = {
bg = "#1C1B1A",
fg = "#F4E3C1",
cursor = "#F27835",
selection_bg = "#F4A259",
selection_fg = "#1C1B1A",
black = "#454240",
red = "#D13438",
green = "#73A857",
yellow = "#F1C232",
blue = "#5A8CA5",
magenta = "#A066C9",
cyan = "#46B9A0",
white = "#AA9E87",
brblack = "#614A4D",
brred = "#FF5F56",
brgreen = "#88C070",
bryellow = "#FADF60",
brblue = "#73B3D8",
brmagenta = "#B794F4",
brcyan = "#6FE2CA",
brwhite = "#F6E8CD",
},
light = {
bg = "#F4E3C1",
fg = "#1C1B1A",
cursor = "#F27835",
selection_bg = "#F4A259",
selection_fg = "#1C1B1A",
black = "#454240",
red = "#D13438",
green = "#88C070",
yellow = "#F1C232",
blue = "#5A8CA5",
magenta = "#A066C9",
cyan = "#5A8CA5",
white = "#AA9E87",
brblack = "#614A4D",
brred = "#FF5F56",
brgreen = "#88C070",
bryellow = "#FADF60",
brblue = "#73B3D8",
brmagenta = "#B794F4",
brcyan = "#6FE2CA",
brwhite = "#F6E8CD",
},
}

function M.update_theme(theme_name)
if type(theme_name) ~= "string" or not palettes[theme_name] then
local colors
if theme_name == "dark" then
colors = require("blackbeard.dark-mode")
elseif theme_name == "light" then
colors = require("blackbeard.light-mode")
else
vim.notify("Invalid theme: " .. tostring(theme_name), vim.log.levels.ERROR)
return
end

local alacritty_path = vim.fn.expand("~/.config/alacritty/alacritty.toml")
local content = generate_alacritty_config(palettes[theme_name])
local content = generate_alacritty_config(colors)

if write_to_file(alacritty_path, content) then
vim.notify("Alacritty theme updated to " .. theme_name .. " at: " .. alacritty_path, vim.log.levels.INFO)
end
end

return M

26 changes: 26 additions & 0 deletions lua/blackbeard/dark-mode.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
-- /cvusmo/blackbeard-nvim/lua/blackbeard/dark-mode.lua

local M = {
bg = "#1C1B1A",
fg = "#F4E3C1",
cursor = "#F27835",
selection_bg = "#F4A259",
selection_fg = "#1C1B1A",
black = "#454240",
red = "#D13438",
green = "#73A857",
yellow = "#F1C232",
blue = "#5A8CA5",
magenta = "#A066C9",
cyan = "#46B9A0",
white = "#AA9E87",
brblack = "#614A4D",
brred = "#FF5F56",
brgreen = "#88C070",
bryellow = "#FADF60",
brblue = "#73B3D8",
brmagenta = "#B794F4",
brcyan = "#6FE2CA",
brwhite = "#F6E8CD",
}
return M
27 changes: 27 additions & 0 deletions lua/blackbeard/light-mode.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-- /cvusmo/blackbeard-nvim/lua/blackbeard/light-mode.lua

local M = {
bg = "#F4E3C1",
fg = "#1C1B1A",
cursor = "#F27835",
selection_bg = "#F4A259",
selection_fg = "#1C1B1A",
black = "#454240",
red = "#D13438",
green = "#88C070",
yellow = "#F1C232",
blue = "#5A8CA5",
magenta = "#A066C9",
cyan = "#5A8CA5",
white = "#AA9E87",
brblack = "#614A4D",
brred = "#FF5F56",
brgreen = "#88C070",
bryellow = "#FADF60",
brblue = "#73B3D8",
brmagenta = "#B794F4",
brcyan = "#6FE2CA",
brwhite = "#F6E8CD",
}
return M

71 changes: 54 additions & 17 deletions lua/blackbeard/themes.lua
Original file line number Diff line number Diff line change
@@ -1,25 +1,62 @@
-- ~/cvusmo/blackbeard-nvim/lua/blackbeard/themes.lua
-- /cvusmo/blackbeard-nvim/lua/blackbeard/init.lua

local M = {}
local alacritty = require("blackbeard.alacritty")

-- Dark Theme
M.dark = function(palette)
return {
Normal = { fg = palette.fg, bg = palette.bg },
Directory = { fg = palette.blue },
Function = { fg = palette.red },
Identifier = { fg = palette.yellow },
}
M.config = {
theme = "dark", -- Default theme
}

function M.setup(config)
-- Merge user-provided configuration with defaults
M.config = vim.tbl_deep_extend("force", M.config, config or {})

-- Load the initial theme
M.load(M.config.theme)
end

function M.load(theme)
theme = theme or M.config.theme
M.config.theme = theme

-- Load colors directly from dark-mode.lua or light-mode.lua
local colors = require("blackbeard." .. theme .. "-mode")

if not colors then
vim.notify("Blackbeard: Invalid theme specified: " .. theme, vim.log.levels.ERROR)
return
end

-- Apply Neovim highlights for the selected theme
local theme_function = require("blackbeard.themes")[theme]
if theme_function then
local neovim_colors = theme_function(colors)
M.apply_highlights(neovim_colors)

-- Update Alacritty with the current theme's colors
alacritty.update_theme(theme)
else
vim.notify("Blackbeard: Theme function not found for " .. theme, vim.log.levels.ERROR)
end
end

-- Light Theme
M.light = function(palette)
return {
Normal = { fg = palette.brblack, bg = palette.white },
Directory = { fg = palette.blue },
Function = { fg = palette.red },
Identifier = { fg = palette.green },
}
function M.apply_highlights(theme_colors)
for group, settings in pairs(theme_colors) do
local highlight_cmd = "highlight " .. group
if settings.fg then
highlight_cmd = highlight_cmd .. " guifg=" .. settings.fg
end
if settings.bg then
highlight_cmd = highlight_cmd .. " guibg=" .. settings.bg
end
if settings.italic then
highlight_cmd = highlight_cmd .. " gui=italic"
end
if settings.bold then
highlight_cmd = highlight_cmd .. " gui=bold"
end
vim.cmd(highlight_cmd)
end
end

return M

0 comments on commit 8257341

Please sign in to comment.