Colors

Okay, so far so good. We can use macros like @red and the tprint function to print colored strings. But so far we've only been using few named colors, but..

there's a whole rainbow
 of colors out there

so how can we use different kinds of colors? It's all done through Term's markup syntax of course. Look:

tprint("{(255, 50, 100)}colors!{/(255, 50, 100)}"; highlight=false)
colors!

yep, you can pass a set of (r, g, b) values and that'll do it. Personally, I prefer working with hex codes, and so Term can accept them too:

indigo = "#42A5F5"

tprint("Some {$indigo}color!{/$indigo}"; highlight=false)
Some color!

Under the hood

What Term is doing here is taking each bit of style information in the markup tag (each word or each (...) within {...}) and constructing style codes with an ANSICode object.

If the style information represents a color, Term first represents it as a AbstractColor type: NamedColor or BitColor or RGBColor.

NamedColor objects represent simple colors like red and blue, BitColor represent 16-bit colors like dark_goldenrod and RGBColor, surprisingly, represents rgb-style colors. There's no method to represent hex colors as these are converted into rgb first.

The distinction between NamedColor, BitColor and RGBColor is necessary because the three color styles are represented by a different syntax in the ANSI codes. Naturally, Term users won't normally worry about this and can use whichever color formulation is most convenient.

Panel

Term defines a Theme type that carries styling information used throughout. It tells highlight what color things should be, it stores the colors of elements of Tree, and of the Repr functionality.

import Term: Theme, set_theme, TERM_THEME

default = TERM_THEME[]
╭──── Theme: default ──────────────────────╮
│                                          
      ──────────── Base ────────────      
      ■■  docstring                       
      ■■  string                          
      ■■  type                            
      ■■  emphasis                        
      ■■  emphasis_light                  
      ■■  code                            
      ■■  multiline_code                  
      ■■  symbol                          
      ■■  expression                      
      ■■  number                          
      ■■  operator                        
      ■■  func                            
                                          
      ─────────── Logging ──────────      
      ■■  info                            
      ■■  debug                           
      ■■  warn                            
      ■■  error                           
                                          
      ──────────── Tree ────────────      
      ■■  tree_title_style                
      ■■  tree_node_style                 
      ■■  tree_leaf_style                 
      ■■  tree_guide_style                
      44  tree_max_width                  
                                          
      ──────────── REPL ────────────      
      ■■  repr_accent_style               
      ■■  repr_name_style                 
      ■■  repr_type_style                 
      ■■  repr_values_style               
      ■■  repr_line_style                 
      ■■  repr_panel_style                
                                          
╰──────────────────────────────────────────╯

You can create a new theme with different colors:

newtheme = Theme(string="red", code="black on_white")
╭──── Theme: default ──────────────────────╮
│                                          
      ──────────── Base ────────────      
      ■■  docstring                       
      ■■  string                          
      ■■  type                            
      ■■  emphasis                        
      ■■  emphasis_light                  
      ■■  code                            
      ■■  multiline_code                  
      ■■  symbol                          
      ■■  expression                      
      ■■  number                          
      ■■  operator                        
      ■■  func                            
                                          
      ─────────── Logging ──────────      
      ■■  info                            
      ■■  debug                           
      ■■  warn                            
      ■■  error                           
                                          
      ──────────── Tree ────────────      
      ■■  tree_title_style                
      ■■  tree_node_style                 
      ■■  tree_leaf_style                 
      ■■  tree_guide_style                
      44  tree_max_width                  
                                          
      ──────────── REPL ────────────      
      ■■  repr_accent_style               
      ■■  repr_name_style                 
      ■■  repr_type_style                 
      ■■  repr_values_style               
      ■■  repr_line_style                 
      ■■  repr_panel_style                
                                          
╰──────────────────────────────────────────╯

and set it as the new theme to be used by Term:

set_theme(newtheme)
╭──── Theme: default ──────────────────────╮
│                                          
      ──────────── Base ────────────      
      ■■  docstring                       
      ■■  string                          
      ■■  type                            
      ■■  emphasis                        
      ■■  emphasis_light                  
      ■■  code                            
      ■■  multiline_code                  
      ■■  symbol                          
      ■■  expression                      
      ■■  number                          
      ■■  operator                        
      ■■  func                            
                                          
      ─────────── Logging ──────────      
      ■■  info                            
      ■■  debug                           
      ■■  warn                            
      ■■  error                           
                                          
      ──────────── Tree ────────────      
      ■■  tree_title_style                
      ■■  tree_node_style                 
      ■■  tree_leaf_style                 
      ■■  tree_guide_style                
      44  tree_max_width                  
                                          
      ──────────── REPL ────────────      
      ■■  repr_accent_style               
      ■■  repr_name_style                 
      ■■  repr_type_style                 
      ■■  repr_values_style               
      ■■  repr_line_style                 
      ■■  repr_panel_style                
                                          
╰──────────────────────────────────────────╯
╭──── Theme: default ──────────────────────╮
│                                          
      ──────────── Base ────────────      
      ■■  docstring                       
      ■■  string                          
      ■■  type                            
      ■■  emphasis                        
      ■■  emphasis_light                  
      ■■  code                            
      ■■  multiline_code                  
      ■■  symbol                          
      ■■  expression                      
      ■■  number                          
      ■■  operator                        
      ■■  func                            
                                          
      ─────────── Logging ──────────      
      ■■  info                            
      ■■  debug                           
      ■■  warn                            
      ■■  error                           
                                          
      ──────────── Tree ────────────      
      ■■  tree_title_style                
      ■■  tree_node_style                 
      ■■  tree_leaf_style                 
      ■■  tree_guide_style                
      44  tree_max_width                  
                                          
      ──────────── REPL ────────────      
      ■■  repr_accent_style               
      ■■  repr_name_style                 
      ■■  repr_type_style                 
      ■■  repr_values_style               
      ■■  repr_line_style                 
      ■■  repr_panel_style                
                                          
╰──────────────────────────────────────────╯