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

Dynamically Toggle Between Colour Schemes in Existing Tabs and Windows Without Recompiling #104

craigem opened this Issue Jan 4, 2019 · 2 comments


None yet
2 participants
Copy link

craigem commented Jan 4, 2019

I've been wondering about how to load the Solarized themes and switch between light and dark with a key stroke toggle.

This should be possible, but will require changing a few things.

You'll have to send a PR to add a hook that gets called right as Termonad is about to launch. Probably around here:

widgetShowAll win
widgetGrabFocus $ terminal ^. lensTerm

In your own config, you'll have to override that hook to define a new key binding for each existing terminal.

Here's an example of defining a key binding (this code defines the Alt-1, Alt-2, etc bindings for switching tabs):

void $ onWidgetKeyPressEvent vteTerm $ handleKeyPress mvarTMState
void $ onWidgetKeyPressEvent scrolledWin $ handleKeyPress mvarTMState

Your key binding will have to call a function that loops through all the open tabs and sets the colors for the terminal.

Here's where that is currently being done:

-- | The default 'createTermHook' for 'colourExtCreateTermHook'. Set the colors
-- for a terminal based on the given 'ColourConfig'.
colourHook :: MVar (ColourConfig (Colour Double)) -> TMState -> Terminal -> IO ()
colourHook mvarColourConf _ vteTerm = do
colourConf <- readMVar mvarColourConf
terminalSetColors vteTerm Nothing Nothing . Just
=<< traverse toRGBA (paletteToList . palette $ colourConf)
-- PR #28 / issue #29: Setting the background colour is broken in gi-vte or VTE. If
-- this next line is called, then you are no longer able to set the
-- background color using the palette.
-- terminalSetColorBackground vteTerm =<< toRGBA (backgroundColour colourConf)
terminalSetColorForeground vteTerm =<< toRGBA (foregroundColour colourConf)
let optPerform setC cField = whenSet (cField colourConf) $ \c ->
setC vteTerm . Just =<< toRGBA c
optPerform terminalSetColorCursor cursorBgColour
#ifdef VTE_VERSION_GEQ_0_44
optPerform terminalSetColorCursorForeground cursorFgColour
toRGBA :: Colour Double -> IO RGBA
toRGBA colour = do
let RGB red green blue = toSRGB colour
rgba <- newZeroRGBA
setRGBARed rgba red
setRGBAGreen rgba green
setRGBABlue rgba blue
pure rgba

This is only setting colors for a single terminal, so you'll have to change it so it loops through all tabs.

Here's a function that loops through all tabs (although this is changing the font size):

let terms =
tmState ^..
lensTMStateNotebook .
lensTMNotebookTabs .
traverse .
lensTMNotebookTabTerm .
foldMap (\vteTerm -> terminalSetFont vteTerm (Just fontDesc)) terms

Originally posted by @cdepillabout in #94 (comment)


This comment has been minimized.

Copy link

craigem commented Jan 4, 2019

For the record, I am happy to work on this (probably as soon as next week), I just felt a new issue was appropriate as I felt we'd strayed from the original issue's remit, @cdepillabout


This comment has been minimized.

Copy link

cdepillabout commented Jan 4, 2019

@craigem Thanks for copying this issue over!

I'd definitely accept something like this if you wanted to take a shot at implementing it. Looking forward to the PR!

@cdepillabout cdepillabout changed the title Toggle Between Solarized Schemes in Existing Tabs and Windows Without Recompiling Dynamically Toggle Between Colour Schemes in Existing Tabs and Windows Without Recompiling Jan 4, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment