diff --git a/nvim/lua/darcula/config/init.lua b/nvim/lua/darcula/config/init.lua index 782abca..40ae930 100644 --- a/nvim/lua/darcula/config/init.lua +++ b/nvim/lua/darcula/config/init.lua @@ -22,6 +22,8 @@ local utils = require("darcula.utils") NV_DARCULA_COLOR_COLUMN = utils.parse_env("NV_DARCULA_COLOR_COLUMN", "80") NV_DARCULA_COLOR_SCHEME = utils.parse_env("NV_DARCULA_COLOR_SCHEME", "darcula_lush") +NV_DARCULA_TERMGUI_COLORS = + utils.parse_env("NV_DARCULA_TERMGUI_COLORS", utils.detect_termguicolors()) NV_DARCULA_ENABLE_COC = utils.parse_env("NV_DARCULA_ENABLE_COC", true) NV_DARCULA_ENABLE_CODE_LENS = utils.parse_env("NV_DARCULA_ENABLE_CODE_LENS", false) diff --git a/nvim/lua/darcula/options.lua b/nvim/lua/darcula/options.lua index c6a2f86..19f7185 100644 --- a/nvim/lua/darcula/options.lua +++ b/nvim/lua/darcula/options.lua @@ -101,7 +101,7 @@ vim.opt.splitbelow = true vim.opt.splitright = true vim.opt.syntax = "enable" vim.opt.tabstop = 2 -vim.opt.termguicolors = true +vim.opt.termguicolors = NV_DARCULA_TERMGUI_COLORS vim.opt.undodir = vim.fs.joinpath(vim.fn.stdpath("data"), ".undo") vim.opt.undofile = true vim.opt.updatetime = 250 diff --git a/nvim/lua/darcula/plugins.lua b/nvim/lua/darcula/plugins.lua index f934904..548afeb 100644 --- a/nvim/lua/darcula/plugins.lua +++ b/nvim/lua/darcula/plugins.lua @@ -19,6 +19,9 @@ -- require("darcula.config") +-- The colorscheme is loaded from this module, before darcula.options. +vim.opt.termguicolors = NV_DARCULA_TERMGUI_COLORS + vim.api.nvim_create_autocmd( "PackChanged", { diff --git a/nvim/lua/darcula/setup/500_telescope.lua b/nvim/lua/darcula/setup/500_telescope.lua index 6bf0637..da97566 100644 --- a/nvim/lua/darcula/setup/500_telescope.lua +++ b/nvim/lua/darcula/setup/500_telescope.lua @@ -69,7 +69,6 @@ require("telescope").setup { borderchars = {" ", " ", " ", " ", " ", " ", " ", " "}, color_devicons = true, use_less = true, - set_env = {["COLORTERM"] = "truecolor"}, -- default = nil, file_previewer = require "telescope.previewers".vim_buffer_cat.new, grep_previewer = require "telescope.previewers".vim_buffer_vimgrep.new, qflist_previewer = require "telescope.previewers".vim_buffer_qflist.new, diff --git a/nvim/lua/darcula/utils/init.lua b/nvim/lua/darcula/utils/init.lua index b42e398..9a36b12 100644 --- a/nvim/lua/darcula/utils/init.lua +++ b/nvim/lua/darcula/utils/init.lua @@ -156,6 +156,35 @@ local function iff(b, l, r) return r end +local detect_termguicolors = function() + local term = (vim.env.TERM or ""):lower() + if term == "ansi" or + term == "cons25" or + term == "dumb" or + term == "linux" or + term:match("^vt%d+$") or + term:find("16color", 1, true) then + return false + end + + local colorterm = (vim.env.COLORTERM or ""):lower() + if colorterm == "24bit" or colorterm == "truecolor" then + return true + end + + if vim.fn.executable("tput") == 1 then + local output = vim.fn.system({"tput", "colors"}) + if vim.v.shell_error == 0 then + local color_count = tonumber(output:match("%d+")) + if color_count and color_count <= 16 then + return false + end + end + end + + return true +end + local parse_env = function(var, def) if vim.env[var] ~= nil then if type(def) == "boolean" then @@ -222,6 +251,7 @@ return { copy_file = copy_file, create_vert_display = create_vert_display, cword = cword, + detect_termguicolors = detect_termguicolors, file_exists = file_exists, get_current_filename = get_current_filename, get_files_sorted_without_extension = get_files_sorted_without_extension,