Skip to content

[UI] Automatically enable 'termguicolors' #2086

@miEsMar

Description

@miEsMar

I've searched open issues for similar requests

  • Yes

Is your feature request related to a problem? Please describe.

In cases where the user has vim.opt.termguicolors = false, Mason UI looks "broken", i.e. the progress bar just does not render, among many other broken components.
Therefore, let Mason automatically enable it internally for the time the Mason window is shown, then restore previous value.

Describe the solution you'd like

Proposed patch:

diff --git a/lua/mason-core/ui/display.lua b/lua/mason-core/ui/display.lua
index 72583a7..4191640 100644
--- a/lua/mason-core/ui/display.lua
+++ b/lua/mason-core/ui/display.lua
@@ -5,6 +5,8 @@ local state = require "mason-core.ui.state"
 
 local M = {}
 
+local user_tgc = nil;
+
 ---@generic T
 ---@param debounced_fn fun(arg1: T)
 ---@return fun(arg1: T)
@@ -552,6 +554,11 @@ function M.new_view_only_win(name, filetype)
                 -- window is already open
                 return
             end
+
+            -- Cache and enable 'termguicolors'
+            user_tgc = vim.opt.termguicolors._value;
+            vim.opt.termguicolors = true;
+
             unsubscribe(false)
             open()
             draw(renderer(get_state()))
@@ -564,6 +571,9 @@ function M.new_view_only_win(name, filetype)
             close_window()
             vim.api.nvim_del_augroup_by_id(window_mgmt_augroup)
             vim.api.nvim_del_augroup_by_id(autoclose_augroup)
+
+            -- Restore user's 'termguicolors'
+            vim.opt.termguicolors = _usr_tgc;
         end),
         ---@param pos number[]: (row, col) tuple
         set_cursor = function(pos)

Describe potential alternatives you've considered

No response

Additional context

The would be one issue with the overly simplified solution, which is that Mason should be able to restore 'tgc' as soon as the Mason window looses focus, i.e. multi-window tab, or even switching to a different tab.
The original value is not restore until the user exits Mason, which should anyway cover I would say >>50% of usages.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions