mirror of
https://github.com/rose-pine/neovim.git
synced 2025-10-15 12:38:53 +02:00
chore!: rename functions
- `rose-pine.functions.select_variant` -> `rose-pine.set` - `rose-pine.functions.toggle_variant` -> `rose-pine.toggle`
This commit is contained in:
parent
6bdbe52159
commit
34aeab3b8e
3 changed files with 38 additions and 47 deletions
|
|
@ -1,35 +0,0 @@
|
|||
local select_variant = function(variant)
|
||||
vim.g.rose_pine_variant = variant
|
||||
local formatted_variant = ''
|
||||
if variant == 'base' then
|
||||
formatted_variant = ''
|
||||
else
|
||||
formatted_variant = variant:sub(1, 1):upper() .. variant:sub(2)
|
||||
end
|
||||
print('Rosé Pine', formatted_variant)
|
||||
vim.cmd([[colorscheme rose-pine]])
|
||||
end
|
||||
|
||||
local toggle_variant = function(variants)
|
||||
local options = variants or { 'base', 'moon', 'dawn' }
|
||||
local index = {}
|
||||
for k, v in pairs(options) do
|
||||
index[v] = k
|
||||
end
|
||||
|
||||
if vim.g.rose_pine_variant_switch == nil then
|
||||
-- Ensure theme toggles from correct position
|
||||
vim.g.rose_pine_variant_switch = index[vim.g.rose_pine_variant] or 0
|
||||
end
|
||||
|
||||
vim.g.rose_pine_variant_switch = (
|
||||
vim.g.rose_pine_variant_switch % table.getn(options)
|
||||
) + 1
|
||||
|
||||
select_variant(options[vim.g.rose_pine_variant_switch])
|
||||
end
|
||||
|
||||
return {
|
||||
select_variant = select_variant,
|
||||
toggle_variant = toggle_variant,
|
||||
}
|
||||
|
|
@ -47,4 +47,28 @@ function M.colorscheme()
|
|||
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
|
||||
|
|
|
|||
28
readme.md
28
readme.md
|
|
@ -119,26 +119,28 @@ vim.cmd('colorscheme rose-pine')
|
|||
## Functions
|
||||
|
||||
```lua
|
||||
-- Toggle between the three variants
|
||||
require('rose-pine.functions').toggle_variant()
|
||||
-- Toggle between all variants
|
||||
require('rose-pine').toggle()
|
||||
|
||||
-- Toggle between base and dawn
|
||||
require('rose-pine.functions').toggle_variant({'base', 'dawn'})
|
||||
-- Toggle between some variants
|
||||
require('rose-pine').toggle({'main', 'dawn'})
|
||||
|
||||
-- Switch to specified variant
|
||||
require('rose-pine.functions').select_variant('moon')
|
||||
-- Set specific variant
|
||||
require('rose-pine').set('moon')
|
||||
```
|
||||
|
||||
## Keymaps
|
||||
|
||||
```lua
|
||||
-- Toggle variant
|
||||
vim.api.nvim_set_keymap('n', '<c-m>', [[<cmd>lua require('rose-pine.functions').toggle_variant()<cr>]], { noremap = true, silent = true })
|
||||
> These are only suggestions; no keymaps are set by the theme
|
||||
|
||||
-- Select each variant
|
||||
vim.api.nvim_set_keymap('n', '<c-8>', [[<cmd>lua require('rose-pine.functions').select_variant('dawn')<cr>]], { noremap = true, silent = true })
|
||||
vim.api.nvim_set_keymap('n', '<c-9>', [[<cmd>lua require('rose-pine.functions').select_variant('moon')<cr>]], { noremap = true, silent = true })
|
||||
vim.api.nvim_set_keymap('n', '<c-0>', [[<cmd>lua require('rose-pine.functions').select_variant('base')<cr>]], { noremap = true, silent = true })
|
||||
```lua
|
||||
-- Toggle variants
|
||||
vim.api.nvim_set_keymap('n', '<c-m>', [[<cmd>lua require('rose-pine').toggle()<cr>]], { noremap = true, silent = true })
|
||||
|
||||
-- Set variant
|
||||
vim.api.nvim_set_keymap('n', '<c-0>', [[<cmd>lua require('rose-pine').set('main')<cr>]], { noremap = true, silent = true })
|
||||
vim.api.nvim_set_keymap('n', '<c-9>', [[<cmd>lua require('rose-pine').set('moon')<cr>]], { noremap = true, silent = true })
|
||||
vim.api.nvim_set_keymap('n', '<c-8>', [[<cmd>lua require('rose-pine').set('dawn')<cr>]], { noremap = true, silent = true })
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue