Module cursive::theme
[−]
[src]
Handle colors and themes in the UI.
Color palette
To achieve a customizable, yet unified look, Cursive uses a configurable palette of colors to be used through the entire application.
These colors are:
background
: used to color the application background (around views). Defaults to blue.shadow
: used to color shadow around views. Defaults to black.view
: used to color the background for views. Defaults to white.primary
: used to print primary text. Defaults to black.secondary
: used to print secondary text. Defaults to blue.tertiary
: used to print tertiary text. Defaults to white.title_primary
: used to print primary titles. Defaults to red.title_secondary
: used to print secondary titles. Defaults to yellow.highlight
: used to highlight selected items. Defaults to red.highlight_inactive
: used to highlight selected but inactive items. Defaults to blue.
Color Styles
Each cell of the terminal uses two colors: foreground and background.
Color styles are defined to easily refer to a pair of colors from the palette.
Background
: style used to print the application background.- Its background color is
background
. - Its foreground color is unimportant as no characters are ever printed in the background.
- Its background color is
Shadow
: style used to print shadows behind views.- Its background color is
shadow
. - Here again, the foreground color is unimportant.
- Its background color is
Primary
: style used to print primary text.- Its background color is
view
. - Its foreground color is
primary
.
- Its background color is
Secondary
: style used to print secondary text.- Its background color is
view
. - Its foreground color is
secondary
.
- Its background color is
Tertiary
: style used to print tertiary text.- Its background color is
view
. - Its foreground color is
tertiary
.
- Its background color is
TitlePrimary
: style used to print titles.- Its background color is
view
. - Its foreground color is
title_primary
.
- Its background color is
TitleSecondary
: style used to print secondary titles.- Its background color is
view
. - Its foreground color is
title_secondary
.
- Its background color is
Highlight
: style used to print selected items.- Its background color is
highlight
. - Its foreground color is
view
.
- Its background color is
HighlightInactive
: style used to print selected, but inactive items.- Its background color is
highlight_inactive
. - Its foreground color is
view
.
- Its background color is
Using one of these pairs when styling your application helps give it a coherent look.
Effects
On top of a color style, some effects can be applied on cells: Reverse
,
for instance, swaps the foreground and background colors of a cell.
Themes
A theme defines the color palette an application will use, as well as various options to style views.
Themes are described in toml configuration files. All fields are optional.
Here are the possible entries:
# Every field in a theme file is optional.
# First come some various options
shadow = false # Don't draw shadows around stacked views
borders = "simple" # Alternatives are "none" and "outset"
# Here we define the color palette.
[colors]
background = "black"
# If the value is an array, the first valid color will be used.
# If the terminal doesn't support custom color,
# non-base colors will be skipped.
shadow = ["#000000", "black"]
view = "#d3d7cf"
# Array and simple values have the same effect.
primary = ["#111111"]
secondary = "#EEEEEE"
tertiary = "#444444"
# Hex values can use lower or uppercase.
# (base color MUST be lowercase)
title_primary = "#ff5555"
title_secondary = "#ffff55"
# Lower precision values can use only 3 digits.
highlight = "#F00"
highlight_inactive = "#5555FF"
Structs
Palette |
Color configuration for the application. |
Theme |
Represents the style a Cursive application will use. |
Enums
BaseColor |
One of the 8 base colors. |
BorderStyle |
Specifies how some borders should be drawn. |
Color |
Represents a color used by the theme. |
ColorStyle |
Possible color style for a cell. |
Effect |
Text effect |
Error |
Possible error returned when loading a theme. |
Functions
load_default |
Loads the default theme, and returns its representation. |
load_theme |
Loads a theme string and sets it as active. |
load_theme_file |
Loads a theme from file and sets it as active. |