Skip to content

Commit

Permalink
breaking: move to lua config (#64)
Browse files Browse the repository at this point in the history
Co-authored-by: fvrests <[email protected]>
  • Loading branch information
mvllow and fvrests committed Feb 13, 2022
1 parent 71c27e5 commit b425bbd
Show file tree
Hide file tree
Showing 8 changed files with 648 additions and 683 deletions.
3 changes: 0 additions & 3 deletions colors/rose-pine.vim
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
lua package.loaded['rose-pine'] = nil
lua package.loaded['rose-pine.config'] = nil
lua package.loaded['rose-pine.palette'] = nil
lua package.loaded['rose-pine.theme'] = nil

lua require('rose-pine').colorscheme()
23 changes: 0 additions & 23 deletions lua/rose-pine/bufferline/init.lua

This file was deleted.

74 changes: 0 additions & 74 deletions lua/rose-pine/config.lua

This file was deleted.

22 changes: 11 additions & 11 deletions lua/rose-pine/galaxyline/theme.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ if not present then
return
end

local palette = require('rose-pine.palette')
local p = require('rose-pine.palette')

galaxyline_colors['rose-pine'] = {
bg = palette.overlay,
fg = palette.text,
fg_alt = palette.subtle,
blue = palette.foam,
cyan = palette.foam,
green = palette.muted,
magenta = palette.iris,
orange = palette.rose,
red = palette.love,
yellow = palette.gold,
bg = p.overlay,
fg = p.text,
fg_alt = p.subtle,
blue = p.foam,
cyan = p.foam,
green = p.muted,
magenta = p.iris,
orange = p.rose,
red = p.love,
yellow = p.gold,
}
204 changes: 172 additions & 32 deletions lua/rose-pine/init.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,156 @@
local M = {}
local show_init_messages = true

local function check_for_deprecated_opts()
local alerts = {}
local should_alert = false

-- Deprecated options
if vim.g.rose_pine_bold_vertical_split_line ~= nil then
should_alert = true
table.insert(alerts, 'vim.g.rose_pine_bold_vertical_split_line renamed to bold_vert_split')
end

if vim.g.rose_pine_inactive_background ~= nil then
should_alert = true
table.insert(alerts, 'vim.g.rose_pine_inactive_background renamed to dim_nc_background')
end

if vim.g.rose_pine_disable_background ~= nil then
should_alert = true
table.insert(alerts, 'vim.g.rose_pine_disable_background renamed to disable_background')
end

if vim.g.rose_pine_disable_float_background ~= nil then
should_alert = true
table.insert(
alerts,
'vim.g.rose_pine_disable_float_background renamed to disable_float_background'
)
end

if vim.g.rose_pine_disable_italics ~= nil then
should_alert = true
table.insert(alerts, 'vim.g.rose_pine_disable_italics renamed to disable_italics')
end

if vim.g.rose_pine_colors ~= nil then
should_alert = true
table.insert(alerts, 'vim.g.rose_pine_colors renamed to groups')
end

if should_alert then
local prefix = ' '
print('Rosé Pine – https://github.com/rose-pine/neovim')
print(prefix .. 'vim.g.rose_pine_<option> moved to lua setup:')
print(prefix .. " require('rose-pine').setup({ ... })")
for _, message in ipairs(alerts) do
print(prefix .. message)
end
should_alert = false
end
end

---@class RosePineConfig
---@field bold_vert_split boolean
---@field dark_variant 'main'|'moon'
---@field dim_nc_background boolean
---@field disable_background boolean
---@field disable_float_background boolean
---@field disable_italics boolean
---@field groups RosePineGroups

---@class RosePineGroups
---@field border string
---@field comment string
---@field link string
---@field punctuation string
---@field error string
---@field hint string
---@field info string
---@field warn string
---@field git RosePineGit
---@field headings string|RosePineHeadings

---@class RosePineGit
---@field add string
---@field change string
---@field delete string
---@field dirty string
---@field ignore string
---@field merge string
---@field rename string
---@field stage string
---@field text string

---@class RosePineHeadings
---@field h1 string
---@field h2 string
---@field h3 string
---@field h4 string
---@field h5 string
---@field h6 string

---@type RosePineConfig
local config = {
bold_vert_split = false,
dark_variant = 'main',
dim_nc_background = false,
disable_background = false,
disable_float_background = false,
disable_italics = false,

groups = {
border = 'highlight_med',
comment = 'muted',
link = 'iris',
punctuation = 'subtle',

error = 'love',
hint = 'iris',
info = 'foam',
warn = 'gold',

git_add = 'foam',
git_change = 'rose',
git_delete = 'love',
git_dirty = 'rose',
git_ignore = 'muted',
git_merge = 'iris',
git_rename = 'pine',
git_stage = 'iris',
git_text = 'rose',

headings = {
h1 = 'iris',
h2 = 'foam',
h3 = 'rose',
h4 = 'gold',
h5 = 'pine',
h6 = 'foam',
},
},
}

---@param opts RosePineConfig
function M.setup(opts)
opts = opts or {}
vim.g.rose_pine_variant = opts.dark_variant or 'main'

if opts.groups and type(opts.groups.headings) == 'string' then
opts.groups.headings = {
h1 = opts.groups.headings,
h2 = opts.groups.headings,
h3 = opts.groups.headings,
h4 = opts.groups.headings,
h5 = opts.groups.headings,
h6 = opts.groups.headings,
}
end

config.user_variant = opts.dark_variant or nil
config = vim.tbl_deep_extend('force', config, opts)
end

function M.colorscheme()
if vim.g.colors_name then
Expand All @@ -8,20 +160,29 @@ function M.colorscheme()
vim.opt.termguicolors = true
vim.g.colors_name = 'rose-pine'

-- Match terminal theme if no variant is set
if vim.g.rose_pine_variant == nil and vim.o.background == 'light' then
vim.g.rose_pine_variant = 'dawn'
elseif vim.g.rose_pine_variant == 'dawn' then
vim.o.background = 'light'
if show_init_messages then
check_for_deprecated_opts()
show_init_messages = false
end

---@param color string
local function get_palette_color(color)
local p = require('rose-pine.palette')

if color and not color:find('#') then
return p[color:lower()]
end

return color:lower()
end

---@param group string
---@param color table<string, string>
local function highlight(group, color)
local style = color.style and 'gui=' .. color.style or 'gui=NONE'
local fg = color.fg and 'guifg=' .. color.fg or 'guifg=NONE'
local bg = color.bg and 'guibg=' .. color.bg or 'guibg=NONE'
local sp = color.sp and 'guisp=' .. color.sp or ''
local fg = color.fg and 'guifg=' .. get_palette_color(color.fg) or 'guifg=NONE'
local bg = color.bg and 'guibg=' .. get_palette_color(color.bg) or 'guibg=NONE'
local sp = color.sp and 'guisp=' .. get_palette_color(color.sp) or ''

local hl = 'highlight ' .. group .. ' ' .. style .. ' ' .. fg .. ' ' .. bg .. ' ' .. sp

Expand All @@ -31,33 +192,12 @@ function M.colorscheme()
end
end

for group, colors in pairs(require('rose-pine.theme')) do
highlight(group, colors)
local theme = require('rose-pine.theme').get(config)
for group, color in pairs(theme) do
highlight(group, color)
end

require('rose-pine.galaxyline.theme')
end

function M.set(variant)
vim.g.rose_pine_variant = variant
vim.cmd('colorscheme rose-pine')
end

function M.toggle(variants)
variants = variants or { 'main', 'moon', 'dawn' }

local index = {}
for k, v in pairs(variants) do
index[v] = k
end

if vim.g.rose_pine_current_variant == nil then
vim.g.rose_pine_current_variant = index[vim.g.rose_pine_variant] or 0
end

vim.g.rose_pine_current_variant = (vim.g.rose_pine_current_variant % #variants) + 1

M.set(variants[vim.g.rose_pine_current_variant])
end

return M
8 changes: 4 additions & 4 deletions lua/rose-pine/palette.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ local variants = {
},
}

local palette = variants.main
local palette = {}

if string.match(vim.g.rose_pine_variant or '', 'moon') then
palette = variants.moon
elseif string.match(vim.g.rose_pine_variant or '', 'dawn') then
if vim.o.background == 'light' then
palette = variants.dawn
else
palette = variants[(vim.g.rose_pine_variant == 'moon' and 'moon') or 'main']
end

vim.tbl_deep_extend('force', palette, { none = 'NONE' })
Expand Down
Loading

0 comments on commit b425bbd

Please sign in to comment.