Skip to content

Colours and styles ​

Every element of the bar takes a foreground colour (<element>_color_fg), a background colour (<element>_color_bg) and a style (<element>_style), by name. The names are those of FACE, which writes them as ANSI escape sequences; they are case insensitive (red, RED, Red). A colour may also be a 24-bit value, #rrggbb.

A name that is not in these lists, or a malformed #rrggbb, stops the program in initialize, with a message that names it.

Colours ​

The same 17 names for the foreground and the background:

NameForeground codeBackground code
black3040
red3141
green3242
yellow3343
blue3444
magenta3545
cyan3646
white3747
default3949
black_intense90100
red_intense91101
green_intense92102
yellow_intense93103
blue_intense94104
magenta_intense95105
cyan_intense96106
white_intense97107

How a named colour looks depends on the palette of the terminal.

24-bit colours ​

#rrggbb, three hexadecimal pairs in any case (#2EF5C0, #2ef5c0), is written as ESC[38;2;r;g;bm in the foreground and ESC[48;2;r;g;bm in the background: the exact colour, whatever the palette of the terminal. Most modern terminals support it; one that does not shows an approximation, or no colour. The short form #rgb is not accepted.

Styles ​

One style for each element:

NameCode
bold_on1
italics_on3
underline_on4
inverse_on (foreground and background swapped)7
strikethrough_on9
framed_on51
encircled_on52
overlined_on53

The _off names (bold_off, italics_off, underline_off, inverse_off, strikethrough_off, framed_off, encircled_off, overlined_off) exist too, but have no use here: every element ends with a reset of all colours and styles. Many terminals do not support framed_on, encircled_on and overlined_on.

Zones ​

bar_zones colours each filled cell of the bar body by its position, as the tachometer of a car turns amber, then red, towards the end of its scale. It is a list of limit:colour items separated by blanks:

  • the limit is a fraction of the body, in (0, 1], increasing from item to item;
  • the colour is a name or #rrggbb, and replaces the foreground colour of filled_char (its background and style stay).

A filled cell takes the colour of the first zone whose limit reaches the end of the cell: with width=40 and '0.7:… 0.88:… 1:…', cells 1–28, 29–35 and 36–40. Cells beyond the last limit keep the filled_char colour; empty cells keep the empty_char colours. The partial block of partial_blocks takes the colour of its cell, and so do the block of an indeterminate bar and its full body at the end. A log has no colours: the zones change nothing there.

A wrong item stops the program in initialize, with a message that names it: no colon, a limit that is not a number, not in (0, 1] or not above the previous one, an unknown colour.

f90
call bar%initialize(prefix_string='RPM ', prefix_color_fg='#2EF5C0', prefix_style='bold_on',               &
                    filled_char_string='▌', empty_char_string='▌', empty_char_color_fg='#0E342C',          &
                    bar_zones='0.7:#2EF5C0 0.88:#FFB000 1:#FF3B30',                                        &
                    add_progress_percent=.true., progress_percent_color_fg='#FFB000',                      &
                    width=40, max_value=real(steps, R8P))

At 80%, the dark empty_char cells are the unlit segments:

$ tach
RPM ▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌  80%

Themes ​

theme gives a bar the look of a 1980s dashboard display in one keyword: the segments of the bar, lit and unlit, and the colours of every element. Every keyword passed explicitly wins over the theme, so a theme is a starting point:

ThemeLooks likeLitUnlitNumbersPulse trail
vfda vacuum fluorescent display, blue-green#2EF5C0#0E342C#FFB000#1FB08A #137057 #0B3F31
amberan amber liquid crystal display#FFB000#3A2800#FFB000#C08400 #7A5400 #3F2B00
kittthe red scanner of a talking car#FF3B30#3C0C0A#FFB000#C0281E #7A1912 #4A0F0B

A theme sets:

  • the filled and empty strings to ▌, a segment with the gap of its right half (unless partial_blocks);
  • the filled colour to lit and the empty colour to unlit, which a ramp uses too;
  • the prefix, suffix and spinner to lit, the prefix in bold;
  • the percent, count, speed, ETA, scale, date and summary to numbers;
  • the unlit 8s of segment digits to #3A2800;
  • on an indeterminate bar, the pulse trail.

It sets no zones, no profile and no segment digits: add them as you like. An unknown theme stops the program.

f90
call vfd%initialize(theme='vfd', prefix_string='vfd   ', add_progress_percent=.true., width=30, &
                    max_value=real(steps, R8P))
call amber%initialize(theme='amber', prefix_string='amber ', bar_profile='ramp', add_progress_percent=.true., &
                      width=30, max_value=real(steps, R8P), position=1)
call kitt%initialize(theme='kitt', prefix_string='kitt  ', indeterminate=.true., add_progress_count=.true., &
                     width=30, position=2)

Three bars, one per theme, the second with a ramp:

$ march
vfd   ▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌  58%
amber ▁▁▁▁▁▂▂▂▂▃▃▃▃▄▄▄▄▅▅▅▅▆▆▆▆▇▇▇▇█  58%
kitt  ▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌ 29

Example ​

f90
call bar%initialize(prefix_string='march ', prefix_color_fg='cyan', prefix_style='bold_on',             &
                    bracket_left_string='[', bracket_right_string=']',                                  &
                    filled_char_string='█', filled_char_color_fg='green',                               &
                    empty_char_string='█', empty_char_color_fg='black_intense',                         &
                    suffix_string=' time steps', suffix_color_fg='yellow', suffix_style='italics_on', &
                    width=40, max_value=real(steps, R8P))
$ march
march [████████████████████████████████████████] time steps

Released under the GPL v3, BSD 2-Clause, BSD 3-Clause or MIT License.