UI (colour) themes play a role in two parts: when writing to the
console and for the xpce-based development tools such as
PceEmacs or the graphical debugger. Coloured console output is based on
ansi_format/3.
The central message infra structure based on
print_message/2
labels message (components) with a Prolog term that specifies the role.
This is mapped to concrete colours for the current theme by means of the
hook prolog:console_color/3.
The IDE uses xpce
theme colours: colours whose name describes their role, such as
syntax_comment for comments in PceEmacs. A theme defines
the values of these colours. The IDE can switch between themes while it
is running. See the section Themes of the XPCE User Guide and
the library library(pce_theme) for details.
The current theme is the value of the Prolog flag theme.
This flag is shared by all threads. Setting it loads the theme file, a
Prolog file in the file search path library/theme, and calls the hook
prolog:theme_hook/1,
which allows, for example, xpce to switch the theme of the IDE. A theme
can be selected using the command line option -Dtheme=dark
or the directive below in the user's initialization file (see section
2.2).
:- set_prolog_flag(theme, dark).
If the flag has its initial value default, loading a
theme file using use_module/1
selects the theme of this file for the console.
The theme file library(theme/auto) is provided to
automatically choose a reasonable theme based on the environment. The
current version detects the background color on xterm compatible
terminal emulators (found on most Unix systems) and loads the dark
theme if the background is ‘darkish’.
The console classes that are used by the interactive top level are
listed below. They are only defined by the dark and
light themes because a background colour can only be chosen
if the background colour of the terminal is known. The default only
makes the prompt and the variable names bold.
prompt | The ?- prompt and its |
continuation |
input | The text typed by the user. These attributes remain in effect while the user is typing |
answer(Parity) | An
answer that shows bindings, residual goals or delays. Parity
is odd or even and alternates over the answers
of a single query. Using a different background colour for both this
stripes the answers of a non-deterministic query. true., false.
and the empty line before the next query are not decorated |
binding(name) | The variable name in a
binding such as
X = 1 |
Messages that list predicates to choose from, for example the
alternatives for an unknown procedure, tag each predicate with its
kind. These tags use the class
predicate(Kind), where Kind
is one of
iso, built_in, foreign,
library(Name), module(Module),
user or undefined.
If one of these classes defines a background colour the remainder of
the line is painted using \e[K (Erase in Line),
which makes the coloured block extend to the right margin. This requires
a terminal that implements background colour erase, which most
modern terminal emulators do.
The following notes apply to the different platforms on which SWI-Prolog is supported:
library(theme/auto).swipl-win
-Dtheme=dark, or set
display.theme in the xpce Defaults file. The
IDE sets the flag theme
when it switches theme, so the console colours (prolog:console_color/3)
follow the theme. Text that is already written keeps its colours.
Code that renders using the theme can respond to switching the theme using the hook below.
forall(prolog:theme_hook(Theme), true) in the thread that
sets the flag, before the flag is changed. If the hook raises
an exception, the flag keeps its old value and set_prolog_flag/2
raises the exception. The system defines a clause that loads
library(theme/Theme) if this file exists and Theme
is not yet defined, i.e., prolog:theme(Theme) is false.Theme support was added in SWI-Prolog 8.1.11. The xpce user interface
and the development tools use theme colours, which allows switching
themes at runtime. The themes light (the default) and
dark are provided. A new theme is a file in
library(theme) that defines the theme colours. The
predicate
check_theme/1
from library library(pce_theme) verifies that a theme
defines all theme colours of xpce and the development tools. Please
contribute themes or improvements to the existing themes.