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

add predefined color schemes #94

Open
clinty opened this issue Dec 30, 2018 · 6 comments
Open

add predefined color schemes #94

clinty opened this issue Dec 30, 2018 · 6 comments
Labels
beginner-friendly Good for newcomers enhancement New feature or request help wanted Extra attention is needed

Comments

@clinty
Copy link

clinty commented Dec 30, 2018

Please include a mechanism for easily enabling Solarized Light and Solarized Dark color schemes (without defining all the colors by hand).

@cdepillabout cdepillabout added enhancement New feature or request help wanted Extra attention is needed beginner-friendly Good for newcomers labels Dec 31, 2018
@cdepillabout cdepillabout changed the title support Solarized color schemes add predefined color schemes Dec 31, 2018
@cdepillabout
Copy link
Owner

cdepillabout commented Dec 31, 2018

I think it would be a good idea to provide some predefined color schemes that people could easily use. I rewrote the title to reflect this.

If you (or anyone else) wants to add some predefined color schemes, please feel free to send a PR. This should be a relatively easy change. The predefined color schemes should probably go in the Termonad.Config.Colour module. Also, it'd be really great if you could add a picture to the haddocks showing what the color scheme looks like for people who aren't familiar with it. You can add the image to the img/ directory.

@craigem Added an example of defining a color scheme here:

https://github.com/cdepillabout/termonad/blob/90ad90c20f922ffe33f90e847c5b0f58902dfd93/example-config/ExampleSolarizedColourExtension.hs

@craigem
Copy link
Contributor

craigem commented Jan 2, 2019

I've got some screen shots in this blog post which I'll happily upload to the haddocks if they're good enough.

On a related topic, I've been wondering about how to load the Solarized themes and switch between light and dark with a key stroke toggle. At the moment I'm just mentally kicking tyres but if there's any known engineering hurdles to the idea it would be good to know before I expend actual effort and ground myself on them :-)

@cdepillabout
Copy link
Owner

@craigem Hmm, I wonder what end users would like to see. I was thinking it would be nice to just get a picture of what each color actually looks like.

I was thinking of running a command like this and taking a picture of it:

$ echo ; for ((i=0; i<=15; i++)); do tput init; [ "$i" -eq 8 ] && echo; printf "%2d. " "${i}"; tput setaf "${i}"; echo -n "TEST "; done ; echo; echo

Here's the default color scheme:

termonad-colors

Although maybe end users would also like pictures of actually doing stuff like editing files.

@cdepillabout
Copy link
Owner

@craigem

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):

https://github.com/cdepillabout/termonad/blob/db185e34a4b678183d8d1b1ce0be4c8bf3532fc8/src/Termonad/Keys.hs

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
#endif
where
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 .
lensTerm
foldMap (\vteTerm -> terminalSetFont vteTerm (Just fontDesc)) terms


If you don't feel like implementing this, could you create an issue requesting this hook be added? Also link to this comment where I describe how to add it.

@craigem
Copy link
Contributor

craigem commented Jan 4, 2019

I was thinking of running a command like this and taking a picture of it:

$ echo ; for ((i=0; i<=15; i++)); do tput init; [ "$i" -eq 8 ] && echo; printf "%2d. " "${i}"; tput setaf "${i}"; echo -n "TEST "; done ; echo; echo

Did that via PR #103

Termonad, Solarized Dark

Termonad, Solarized Light

Although maybe end users would also like pictures of actually doing stuff like editing files.

I'm happy to add my existing Haskell examples. Should they also be added to the doco or just dumped in /img as well?

@cdepillabout
Copy link
Owner

cdepillabout commented Jan 4, 2019

@craigem

Thanks for #103.

I added a comment there but I probably should have added it in this thread:

#103 (comment)

Basically it explains the steps you would take for adding a predefined solarized theme to the Termonad.Config.Colour module. If you (or anyone else reading this) want to implement this, I would definitely accept a PR for this.

I'm happy to add my existing Haskell examples. Should they also be added to the doco or just dumped in /img as well?

I think they should only be added if you want to link to them from the Haddocks (if you want to add the solarizedDarkPalette and solarizedLightPalette). I'm not sure whether end users would want to see something like that in the haddocks, so I'll leave it up to you for you send the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beginner-friendly Good for newcomers enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants