fix(flavour): respect terminal's background (#696)

* fix(flavour): don't respect terminal if options.value is not nil
This commit is contained in:
Null Chilly 2024-04-13 00:04:21 +07:00 committed by GitHub
parent 02bdd74993
commit d5760c53ae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 8 additions and 17 deletions

View file

@ -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",

View file

@ -17,6 +17,7 @@ Table of Contents *catppuccin-table-of-contents*
- Wrong treesitter highlights |catppuccin-faq-wrong-treesitter-highlights|
- Colors doesnt match preview screenshots|catppuccin-faq-colors-doesnt-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",

View file

@ -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?)

View file

@ -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",