Re: Windows Console Colors To Match Your Leo Theme (Part 2)

2023-03-04 Thread Thomas Passin
To make changing your console color themes easier, it's worth while making 
either a batch file or some aliases.  Doskey aliases are probably less 
familiar, so that's what I will cover in this post.

Here is a doskey alias for making the console change to the tbp-dark.ini 
theme (the command should be all on one line but it will probably be 
wrapped in this post:

doskey dark=C:\utility\ColorTool\ColorTool.exe -b 
C:\utility\ColorTool\schemes\tbp-dark.ini ^& cls

Of course, change the paths to match what you use on your system.  The last 
part, "^& cls", means for run the cls command after changing the theme. 
 The "&" character has to be escaped with "^" because it has a special 
meaning to doskey.  I have one of these aliases for each of four color 
themes.

It's best to keep all these doskey aliases - also called "macros" by 
doskeys - in a batch file so that they can be reloaded easily for new 
terminals.  I use a batch file named "aliases.cmd".  Put it somewhere on 
your path.  Now when you open a new terminal, just run "aliases".  Here's 
part of mine (again, the lines may look wrapped in this post but should 
each be on its own line):

@echo off
:: = Change the paths to match your own computer =
:: = Define an editor program and alias to edit this file 
set ep="C:\Program Files\EditPlus\editplus.exe"
::  Doskey uses "$" instead of "%" for parameters
doskey ep=start "$1" /b %ep% $*

::  Alias to edit this file =
doskey ea=%ep% "c:\usr\bin\aliases.cmd"

::  Aliases to activate the color themes =
doskey solardark=C:\utility\ColorTool\ColorTool.exe -b 
C:\utility\ColorTool\schemes\tbp-dark-solarized.ini ^& cls
doskey light=C:\utility\ColorTool\ColorTool.exe -b 
C:\utility\ColorTool\schemes\tbp-light.ini ^& cls
doskey lightgray=C:\utility\ColorTool\ColorTool.exe -b 
C:\utility\ColorTool\schemes\tbp-light-gray.ini ^& cls
doskey dark=C:\utility\ColorTool\ColorTool.exe -b 
C:\utility\ColorTool\schemes\tbp-dark.ini ^& cls

If you start a console using , you can load the aliases at 
startup with this command:

cmd /k aliases

To edit the aliases file, just type "ea".  To change the color theme to, 
e.g., solardark, just type "solardark".

-- 
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/dc4b5129-5ae7-4aba-bceb-a580160eef1bn%40googlegroups.com.


Re: Windows Console Colors To Match Your Leo Theme (Part 2)

2023-03-04 Thread Thomas Passin
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  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\.ini

where  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.


http://leoeditor.com/namespaces/leo-python-editor/1.1"; >





Styles: get colors from palette
Rescale CSS Colors
Show CSS components in Decimal


# 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() & 0x00ff
bg_hex = palette.window().color().rgb()  & 0x00ff
fg = f'#{fg_hex:x}'
bg = f'#{bg_hex:x}'
g.es(fg, bg)
def scale_color(css, factor):
"""Scale CSS colors.

'#xx -> '#yy'.  "#" 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)




def css_color_decimal(css):
"""Return hex CSS colors as a tuple of decimals.

'#xx' -> '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))