Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Preview (temporarily apply) colour schemes when the name is highlighted in the list. #2677

Open
HubKing opened this issue Jan 10, 2023 · 1 comment

Comments

@HubKing
Copy link

HubKing commented Jan 10, 2023

It is very annoying to try each and every colour scheme one by one by typing set colorscheme [name] again and again. It would be much faster and easier if Micro just temporarily switch to the colour theme (preview) when the name is selected like below.

2023-01-10-15-33-19.mp4
@dmaluka
Copy link
Collaborator

dmaluka commented Jan 30, 2023

In principle it should be possible with a simple Lua plugin like the following:

local config = import("micro/config")

local origColorscheme = config.GetGlobalOption("colorscheme")
local tempColorscheme = nil

function onCommandComplete(bp)
    if bp.PromptType == "Command" and bp.Buf:Line(0):match("^set colorscheme ") and
            bp.Buf.HasSuggestions and bp.Buf.CurSuggestion >= 0 then
        tempColorscheme = bp.Buf.Completions[bp.Buf.CurSuggestion + 1]
        config.SetGlobalOption("colorscheme", tempColorscheme)
    end
end

function onExecuteCommand(bp)
    if tempColorscheme ~= nil and tempColorscheme ~= origColorscheme then
        origColorscheme = tempColorscheme
    end
end

function onAbortCommand(bp)
    if tempColorscheme ~= nil and tempColorscheme ~= origColorscheme then
        config.SetGlobalOption("colorscheme", origColorscheme)
        tempColorscheme = nil
    end
end

Unfortunately, as I've found, micro currently executes onAction callbacks only for actions triggered in a normal buffer pane only, not in the command bar, so those onCommandComplete, onExecuteCommand, onAbortCommand functions are never executed (so I cannot even test if the above Lua code is correct). But I think it should not be too difficult to fix this limitation in micro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants