mirror of
https://github.com/catppuccin/nvim
synced 2024-09-16 13:24:08 +02:00
fix(flavour): respect terminal's background (#696)
* fix(flavour): don't respect terminal if options.value is not nil
This commit is contained in:
parent
02bdd74993
commit
d5760c53ae
4 changed files with 8 additions and 17 deletions
|
@ -89,8 +89,7 @@ There is no need to call `setup` if you don't want to change the default options
|
|||
|
||||
```lua
|
||||
require("catppuccin").setup({
|
||||
flavour = "mocha", -- latte, frappe, macchiato, mocha
|
||||
-- flavour = "auto" -- will respect terminal's background
|
||||
flavour = "auto", -- latte, frappe, macchiato, mocha
|
||||
background = { -- :h background
|
||||
light = "latte",
|
||||
dark = "mocha",
|
||||
|
|
|
@ -17,6 +17,7 @@ Table of Contents *catppuccin-table-of-contents*
|
|||
- Wrong treesitter highlights |catppuccin-faq-wrong-treesitter-highlights|
|
||||
- Colors doesn’t match preview screenshots|catppuccin-faq-colors-doesn’t-match-preview-screenshots|
|
||||
9. Thanks to |catppuccin-thanks-to|
|
||||
10. Links |catppuccin-links|
|
||||
|
||||
==============================================================================
|
||||
1. Features *catppuccin-features*
|
||||
|
@ -70,8 +71,7 @@ options and settings.
|
|||
|
||||
>lua
|
||||
require("catppuccin").setup({
|
||||
flavour = "mocha", -- latte, frappe, macchiato, mocha
|
||||
-- flavour = "auto" -- will respect terminal's background
|
||||
flavour = "auto", -- latte, frappe, macchiato, mocha
|
||||
background = { -- :h background
|
||||
light = "latte",
|
||||
dark = "mocha",
|
||||
|
|
|
@ -4,6 +4,7 @@ if is_vim then require "catppuccin.lib.vim" end
|
|||
---@type Catppuccin
|
||||
local M = {
|
||||
default_options = {
|
||||
flavour = "auto",
|
||||
background = {
|
||||
light = "latte",
|
||||
dark = "mocha",
|
||||
|
@ -125,7 +126,7 @@ local function get_flavour(default)
|
|||
if flavour and not M.flavours[flavour] then
|
||||
vim.notify(
|
||||
string.format(
|
||||
"Catppuccin (error): Invalid flavour '%s', flavour must be 'latte', 'frappe', 'macchiato' or 'mocha'",
|
||||
"Catppuccin (error): Invalid flavour '%s', flavour must be 'latte', 'frappe', 'macchiato', 'mocha' or 'auto'",
|
||||
flavour
|
||||
),
|
||||
vim.log.levels.ERROR
|
||||
|
@ -140,15 +141,6 @@ local did_setup = false
|
|||
function M.load(flavour)
|
||||
if M.options.flavour == "auto" then -- set colorscheme based on o:background
|
||||
M.options.flavour = nil -- ensure that this will only run once on startup
|
||||
if not vim.api.nvim_get_option_info2("background", {}).was_set then -- wait for terminal to set o:background
|
||||
vim.api.nvim_create_autocmd("OptionSet", { -- https://github.com/neovim/neovim/pull/26284
|
||||
once = true,
|
||||
nested = true,
|
||||
pattern = "background",
|
||||
callback = function() M.load(flavour) end,
|
||||
})
|
||||
return
|
||||
end
|
||||
end
|
||||
if not did_setup then M.setup() end
|
||||
M.flavour = get_flavour(flavour)
|
||||
|
@ -158,7 +150,7 @@ function M.load(flavour)
|
|||
M.compile()
|
||||
f = assert(loadfile(compiled_path), "could not load cache")
|
||||
end
|
||||
f()
|
||||
f(flavour or M.options.flavour)
|
||||
end
|
||||
|
||||
---@type fun(user_conf: CatppuccinOptions?)
|
||||
|
|
|
@ -25,10 +25,10 @@ function M.compile(flavour)
|
|||
local lines = {
|
||||
string.format(
|
||||
[[
|
||||
return string.dump(function()
|
||||
return string.dump(function(flavour)
|
||||
vim.o.termguicolors = true
|
||||
if vim.g.colors_name then vim.cmd("hi clear") end
|
||||
vim.o.background = "%s"
|
||||
if flavour then vim.o.background = "%s" end
|
||||
vim.g.colors_name = "catppuccin-%s"
|
||||
local h = vim.api.nvim_set_hl]],
|
||||
flavour == "latte" and "light" or "dark",
|
||||
|
|
Loading…
Reference in a new issue