This is Part 3 of the series on changing Windows console colors to match 
your Leo theme.

This post is Part 3, the last part, of the series on making and using 
Windows console color themes.

The ColorTool.exe program (see Part 1) makes it relatively easy to modify 
an existing theme.  To create one from nothing would be very tedious. 
 Assigning the text foreground and background colors is fairly easy once 
you know them.  The hard part is to find good other colors, such as 
highlight colors, selection colors, etc.  It's hard even to know which 
color name to use for assigning the other colors.  These other colors can 
be important if a program issues special terminal emulator commands to 
print text in some other color, such as red for a warning.

For my solarized dark theme, for example, I took the 
solarized_dark.itermcolors file that came with the ColorTools program, and 
changed only the text and background colors a little.

I have attached a Leo outline with a few scripts to make the process 
easier.  Run them with <CTRL-B> after changing their color values to suit 
yourself. I used each of these scripts as I tuned up the color theme files 
I attached to the Part 1 post.

1. Styles: get colors from palette
This script gets the text and background colors from the current focused 
editor window and prints their CSS hex values to the log pane.  This gives 
you a starting point if you have a Leo theme whose colors you like.

2. Rescale CSS Colors
This script lets you change a CSS hex color by a given factor so that the 
color will be darker or lighter than the starting color.  The new and old 
CSS hex values are printed to the log pane in their respective colors. 
 Using a scale factor < 1 makes a color darker, and > 1 makes it lighter. 
 The scaled r,g,b color components are limited to "ff", which prevents 
overflow if the factor is too large.  Note that if any of the components 
are clipped in this way, the color hue may change noticeably.  The scaling 
does not preserve the hue perfectly, but for small scale factors the new 
hue is not far different from what it would ideally be. (Ideally we would 
do the scaling in HSV space and then convert back to RGB, but it's probably 
not worth the trouble here).

3. Show CSS components in Decimal
To change a color in the console Properties dialog, you need to know their 
decimal red, green, and blue components.  You also need to know them if you 
want to edit the color .ini files directly. This script takes a CSS hex 
color string like "#4a5d63", and prints its r, g, b decimal components to 
the log pane.  In this example, the components are '74 93 99'.

Once you have changed the console colors using the console's Properties 
dialog, click on the "OK" button.  Then you can use the ColorTool program 
to save them to a file.  Assuming that you have changed the current 
directory to the ColorTool directory, the command is

ColorTool -o schemes\<name>.ini

where <name> is whatever file name you like.  The file name must have a 
".ini" extension, such as "new-dark.ini". (The ColorTool program can use 
several file formats including a JSON and an XML file format, but this way 
of saving the console colors produces an .ini file format).

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to leo-editor+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/a4a8ee8b-39d1-4cd1-834f-a1ffa1a322edn%40googlegroups.com.
<?xml version="1.0" encoding="utf-8"?>
<!-- Created by Leo: http://leoeditor.com/leo_toc.html -->
<leo_file xmlns:leo="http://leoeditor.com/namespaces/leo-python-editor/1.1"; >
<leo_header file_format="2"/>
<globals/>
<preferences/>
<find_panel_settings/>
<vnodes>
<v t="tom.20220329141402.1"><vh>Styles: get colors from palette</vh></v>
<v t="tom.20230304220501.1"><vh>Rescale CSS Colors</vh></v>
<v t="tom.20230304220510.1"><vh>Show CSS components in Decimal</vh></v>
</vnodes>
<tnodes>
<t tx="tom.20220329141402.1"># Get current CSS hex colors from the body editor widget
wrapper = c.frame.body.wrapper
w = wrapper.widget
palette = w.viewport().palette()
fg_hex = palette.text().color().rgb() &amp; 0x00ffffff
bg_hex = palette.window().color().rgb()  &amp; 0x00ffffff
fg = f'#{fg_hex:x}'
bg = f'#{bg_hex:x}'
g.es(fg, bg)</t>
<t tx="tom.20230304220501.1">def scale_color(css, factor):
    """Scale CSS colors.
    
    '#xxxxxx -&gt; '#yyyyyy'.  "#" in input is optional.
    Each color value is limited to 0xff maximum.
    """
    if css.startswith('#'):
        css = css[1:]
    factor = abs(factor)
    r, gg, b = [int(css[i:i + 2], 16) for i in (0, 2, 4)]
    rr, ggg, bb = [int(cc * factor) for cc in (r, gg, b)]
    rr, ggg, bb = [min(0xff, c) for c in (rr, ggg, bb)]
    return f'#{rr:02x}{ggg:02x}{bb:02x}'

c1 = '#586e75'
factor = .85
c2 = scale_color(c1, factor)
g.es(c1, color = c1)
g.es(c2, color = c2)



</t>
<t tx="tom.20230304220510.1">def css_color_decimal(css):
    """Return hex CSS colors as a tuple of decimals.
    
    '#xxxxxx' -&gt; 'rr, gg, bb'.  "#" in input is optional.
    The color components are in decimal, not hex.
    """
    if css.startswith('#'):
        css = css[1:]
    r, gg, b = [int(css[i:i + 2], 16) for i in (0, 2, 4)]
    return f'{r} {gg} {b}'

fg = '#4a5d63'
bg = '#ededed'

g.es('fg', css_color_decimal(fg))
g.es('bg', css_color_decimal(bg))</t>
</tnodes>
</leo_file>

Reply via email to