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.

Theme

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 ────────────────────────────────────────────╮
                                                                
                        ■■  name                                
                        ■■  docstring                           
                        ■■  string                              
                        ■■  type                                
                        ■■  code                                
                        ■■  multiline_code                      
                        ■■  symbol                              
                        ■■  expression                          
                        ■■  number                              
                        ■■  operator                            
                        ■■  func                                
                        ■■  link                                
                        ■■  text                                
                        ■■  text_accent                         
                        ■■  emphasis                            
                        ■■  emphasis_light                      
                        ■■  line                                
                   ROUNDED  box                                 
                        ■■  info                                
                        ■■  debug                               
                        ■■  warn                                
                        ■■  error                               
                        ■■  logmsg                              
                        ■■  tree_mid                            
                        ■■  tree_terminator                     
                        ■■  tree_skip                           
                        ■■  tree_dash                           
                        ■■  tree_trunc                          
                        ■■  tree_pair                           
                        ■■  tree_keys                           
                        ■■  tree_title                          
                        44  tree_max_leaf_width                 
                        ■■  repr_accent                         
                        ■■  repr_name                           
                        ■■  repr_type                           
                        ■■  repr_values                         
                        ■■  repr_line                           
                        ■■  repr_panel                          
                        ■■  repr_array_panel                    
                        ■■  repr_array_title                    
                        ■■  repr_array_text                     
                        ■■  err_accent                          
                        ■■  er_bt                               
                        ■■  err_btframe_panel                   
                        ■■  err_filepath                        
                        ■■  err_errmsg                          
                        ■■  inspect_highlight                   
                        ■■  inspect_accent                      
                        ■■  progress_accent                     
                        ■■  progress_elapsedcol_default         
                        ■■  progress_etacol_default             
                        ■■  progress_spiner_default             
                        ■■  progress_spinnerdone_default        
                        ■■  dendo_title                         
                        ■■  dendo_pretitle                      
                        ■■  dendo_leaves                        
                        ■■  dendo_lines                         
                        ■■  md_h1                               
                        ■■  md_h2                               
                        ■■  md_h3                               
                        ■■  md_h4                               
                        ■■  md_h5                               
                        ■■  md_h6                               
                        ■■  md_latex                            
                        ■■  md_code                             
                        ■■  md_codeblock_bg                     
                        ■■  md_quote                            
                        ■■  md_footnote                         
                        ■■  md_table_header                     
                        ■■  md_admonition_note                  
                        ■■  md_admonition_info                  
                        ■■  md_admonition_warning               
                        ■■  md_admonition_danger                
                        ■■  md_admonition_tip                   
                        ■■  tb_style                            
                        ■■  tb_header                           
                        ■■  tb_columns                          
                        ■■  tb_footer                           
        MINIMAL_HEAVY_HEAD  tb_box                              
                        ■■  prompt_text                         
                        ■■  prompt_default_option               
                        ■■  prompt_options                      
                        ■■  annotation_color                    
                                                                
╰────────────────────────────────────────────────────────────────╯

You can create a new theme with different colors:

newtheme = Theme(string="red", code="black on_white")
╭──── Theme: default ────────────────────────────────────────────╮
                                                                
                        ■■  name                                
                        ■■  docstring                           
                        ■■  string                              
                        ■■  type                                
                        ■■  code                                
                        ■■  multiline_code                      
                        ■■  symbol                              
                        ■■  expression                          
                        ■■  number                              
                        ■■  operator                            
                        ■■  func                                
                        ■■  link                                
                        ■■  text                                
                        ■■  text_accent                         
                        ■■  emphasis                            
                        ■■  emphasis_light                      
                        ■■  line                                
                   ROUNDED  box                                 
                        ■■  info                                
                        ■■  debug                               
                        ■■  warn                                
                        ■■  error                               
                        ■■  logmsg                              
                        ■■  tree_mid                            
                        ■■  tree_terminator                     
                        ■■  tree_skip                           
                        ■■  tree_dash                           
                        ■■  tree_trunc                          
                        ■■  tree_pair                           
                        ■■  tree_keys                           
                        ■■  tree_title                          
                        44  tree_max_leaf_width                 
                        ■■  repr_accent                         
                        ■■  repr_name                           
                        ■■  repr_type                           
                        ■■  repr_values                         
                        ■■  repr_line                           
                        ■■  repr_panel                          
                        ■■  repr_array_panel                    
                        ■■  repr_array_title                    
                        ■■  repr_array_text                     
                        ■■  err_accent                          
                        ■■  er_bt                               
                        ■■  err_btframe_panel                   
                        ■■  err_filepath                        
                        ■■  err_errmsg                          
                        ■■  inspect_highlight                   
                        ■■  inspect_accent                      
                        ■■  progress_accent                     
                        ■■  progress_elapsedcol_default         
                        ■■  progress_etacol_default             
                        ■■  progress_spiner_default             
                        ■■  progress_spinnerdone_default        
                        ■■  dendo_title                         
                        ■■  dendo_pretitle                      
                        ■■  dendo_leaves                        
                        ■■  dendo_lines                         
                        ■■  md_h1                               
                        ■■  md_h2                               
                        ■■  md_h3                               
                        ■■  md_h4                               
                        ■■  md_h5                               
                        ■■  md_h6                               
                        ■■  md_latex                            
                        ■■  md_code                             
                        ■■  md_codeblock_bg                     
                        ■■  md_quote                            
                        ■■  md_footnote                         
                        ■■  md_table_header                     
                        ■■  md_admonition_note                  
                        ■■  md_admonition_info                  
                        ■■  md_admonition_warning               
                        ■■  md_admonition_danger                
                        ■■  md_admonition_tip                   
                        ■■  tb_style                            
                        ■■  tb_header                           
                        ■■  tb_columns                          
                        ■■  tb_footer                           
        MINIMAL_HEAVY_HEAD  tb_box                              
                        ■■  prompt_text                         
                        ■■  prompt_default_option               
                        ■■  prompt_options                      
                        ■■  annotation_color                    
                                                                
╰────────────────────────────────────────────────────────────────╯

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

set_theme(newtheme)
╭──── Theme: default ────────────────────────────────────────────╮
                                                                
                        ■■  name                                
                        ■■  docstring                           
                        ■■  string                              
                        ■■  type                                
                        ■■  code                                
                        ■■  multiline_code                      
                        ■■  symbol                              
                        ■■  expression                          
                        ■■  number                              
                        ■■  operator                            
                        ■■  func                                
                        ■■  link                                
                        ■■  text                                
                        ■■  text_accent                         
                        ■■  emphasis                            
                        ■■  emphasis_light                      
                        ■■  line                                
                   ROUNDED  box                                 
                        ■■  info                                
                        ■■  debug                               
                        ■■  warn                                
                        ■■  error                               
                        ■■  logmsg                              
                        ■■  tree_mid                            
                        ■■  tree_terminator                     
                        ■■  tree_skip                           
                        ■■  tree_dash                           
                        ■■  tree_trunc                          
                        ■■  tree_pair                           
                        ■■  tree_keys                           
                        ■■  tree_title                          
                        44  tree_max_leaf_width                 
                        ■■  repr_accent                         
                        ■■  repr_name                           
                        ■■  repr_type                           
                        ■■  repr_values                         
                        ■■  repr_line                           
                        ■■  repr_panel                          
                        ■■  repr_array_panel                    
                        ■■  repr_array_title                    
                        ■■  repr_array_text                     
                        ■■  err_accent                          
                        ■■  er_bt                               
                        ■■  err_btframe_panel                   
                        ■■  err_filepath                        
                        ■■  err_errmsg                          
                        ■■  inspect_highlight                   
                        ■■  inspect_accent                      
                        ■■  progress_accent                     
                        ■■  progress_elapsedcol_default         
                        ■■  progress_etacol_default             
                        ■■  progress_spiner_default             
                        ■■  progress_spinnerdone_default        
                        ■■  dendo_title                         
                        ■■  dendo_pretitle                      
                        ■■  dendo_leaves                        
                        ■■  dendo_lines                         
                        ■■  md_h1                               
                        ■■  md_h2                               
                        ■■  md_h3                               
                        ■■  md_h4                               
                        ■■  md_h5                               
                        ■■  md_h6                               
                        ■■  md_latex                            
                        ■■  md_code                             
                        ■■  md_codeblock_bg                     
                        ■■  md_quote                            
                        ■■  md_footnote                         
                        ■■  md_table_header                     
                        ■■  md_admonition_note                  
                        ■■  md_admonition_info                  
                        ■■  md_admonition_warning               
                        ■■  md_admonition_danger                
                        ■■  md_admonition_tip                   
                        ■■  tb_style                            
                        ■■  tb_header                           
                        ■■  tb_columns                          
                        ■■  tb_footer                           
        MINIMAL_HEAVY_HEAD  tb_box                              
                        ■■  prompt_text                         
                        ■■  prompt_default_option               
                        ■■  prompt_options                      
                        ■■  annotation_color                    
                                                                
╰────────────────────────────────────────────────────────────────╯
╭──── Theme: default ────────────────────────────────────────────╮
                                                                
                        ■■  name                                
                        ■■  docstring                           
                        ■■  string                              
                        ■■  type                                
                        ■■  code                                
                        ■■  multiline_code                      
                        ■■  symbol                              
                        ■■  expression                          
                        ■■  number                              
                        ■■  operator                            
                        ■■  func                                
                        ■■  link                                
                        ■■  text                                
                        ■■  text_accent                         
                        ■■  emphasis                            
                        ■■  emphasis_light                      
                        ■■  line                                
                   ROUNDED  box                                 
                        ■■  info                                
                        ■■  debug                               
                        ■■  warn                                
                        ■■  error                               
                        ■■  logmsg                              
                        ■■  tree_mid                            
                        ■■  tree_terminator                     
                        ■■  tree_skip                           
                        ■■  tree_dash                           
                        ■■  tree_trunc                          
                        ■■  tree_pair                           
                        ■■  tree_keys                           
                        ■■  tree_title                          
                        44  tree_max_leaf_width                 
                        ■■  repr_accent                         
                        ■■  repr_name                           
                        ■■  repr_type                           
                        ■■  repr_values                         
                        ■■  repr_line                           
                        ■■  repr_panel                          
                        ■■  repr_array_panel                    
                        ■■  repr_array_title                    
                        ■■  repr_array_text                     
                        ■■  err_accent                          
                        ■■  er_bt                               
                        ■■  err_btframe_panel                   
                        ■■  err_filepath                        
                        ■■  err_errmsg                          
                        ■■  inspect_highlight                   
                        ■■  inspect_accent                      
                        ■■  progress_accent                     
                        ■■  progress_elapsedcol_default         
                        ■■  progress_etacol_default             
                        ■■  progress_spiner_default             
                        ■■  progress_spinnerdone_default        
                        ■■  dendo_title                         
                        ■■  dendo_pretitle                      
                        ■■  dendo_leaves                        
                        ■■  dendo_lines                         
                        ■■  md_h1                               
                        ■■  md_h2                               
                        ■■  md_h3                               
                        ■■  md_h4                               
                        ■■  md_h5                               
                        ■■  md_h6                               
                        ■■  md_latex                            
                        ■■  md_code                             
                        ■■  md_codeblock_bg                     
                        ■■  md_quote                            
                        ■■  md_footnote                         
                        ■■  md_table_header                     
                        ■■  md_admonition_note                  
                        ■■  md_admonition_info                  
                        ■■  md_admonition_warning               
                        ■■  md_admonition_danger                
                        ■■  md_admonition_tip                   
                        ■■  tb_style                            
                        ■■  tb_header                           
                        ■■  tb_columns                          
                        ■■  tb_footer                           
        MINIMAL_HEAVY_HEAD  tb_box                              
                        ■■  prompt_text                         
                        ■■  prompt_default_option               
                        ■■  prompt_options                      
                        ■■  annotation_color                    
                                                                
╰────────────────────────────────────────────────────────────────╯

The default theme used by Term is tailored for a dark terminal, if you fancy a lighter terminal experience, you might want to:

import Term: set_theme, LightTheme

set_theme(LightTheme)