Skip to content
Alexandre Bury edited this page Jul 1, 2016 · 2 revisions

Description

Cursive has a flexible coloring module, to allow easy customization while keeping a unified look.

To achieve this, a theme will define a 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.

These colors are then used in pairs (foreground and background) to define some color styles:

  • 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.
  • Shadow: style used to print shadows behind views.
    • Its background color is shadow.
    • Here again, the foreground color is unimportant.
  • Primary: style used to print primary text.
    • Its background color is view.
    • Its foreground color is primary.
  • Secondary: style used to print secondary text.
    • Its background color is view.
    • Its foreground color is secondary.
  • Tertiary: style used to print tertiary text.
    • Its background color is view.
    • Its foreground color is tertiary.
  • TitlePrimary: style used to print titles.
    • Its background color is view.
    • Its foreground color is title_primary.
  • TitleSecondary: style used to print secondary titles.
    • Its background color is view.
    • Its foreground color is title_secondary.
  • Highlight: style used to print selected items.
    • Its background color is highlight.
    • Its foreground color is view.
  • HighlightInactive: style used to print selected, but inactive items.
    • Its background color is highlight_inactive.
    • Its foreground color is view.

On top of a color style, some effects can be applied, like Reverse, which swaps the foreground and background colors.

Users then simply select the color style and effects they want to use for each part of the application, and the corresponding colors from the theme are applied.

Initialization sequence

  1. The color palette is read from the configuration file (or the default one is used).
    • At this point, colors are downcasted to the best compatible one.
      • This mean stick to 8 colors on TTY
      • Ideally, this also means trying true colors, or sticking to 256 colors.
  2. When text is printed on the screen, the printer is given a color role.
    • ncurses only needs this color pair, as it saves a mapping to colors internally
    • termion wants the foreground/background color everytime.
      • solution: have the termion wrapper save its own map of roles to color pairs?