Skip to main content

Module fmt

Module fmt 

Source
Expand description

Source text formatter with span highlights and notes.

Here are the kind of things you can produce with the Formatter (without colors):

 1 | /     pub fn fibonacci(n: i32) -> u64 {
   | |                     ^______^        ^
   | |  __________________________|________|
   | | |                          |
   | | |                          this is a pair of parenthesis
 2 | | |       if n < 0 {
   | | |  ______________^
 3 | | | |         panic!("{} is negative!", n);
   | | | |               ^"^^             "   ^ this is a pair of parenthesis
   | | | |               ||_|_____________|   |
   | | | |               |__|_____________|___|
   | | | |                  |             |
   | | | |                  |             this is a string
   | | | |                  |
   | | | |                  this is a pair of braces
 4 | | | |     } else if n == 0 {
   | | | |_____^                ^
   | | |  _____|________________|
   | | | |     |
   | | | |     this is a pair of braces
 5 | | | |         panic!("zero is not a right argument to fibonacci()!");
   | | | |               ^"                                         ^^ "^ parentheses
   | | | |               ||__________________________________________|_||
   | | | |               |___________________________________________|_||
   | | | |                                                           | |
   | | | |                                                           | this is a string
   | | | |                                                           |
   | | | |                                                           parentheses
 6 | | | |     } else if n == 1 {
   | | | |_____^                ^
   | | |       |                |
   | | |  _____|________________|
   | | | |     |
   | | | |     this is a pair of braces
 7 | | | |         return 1;
 8 | | | |     }
   | | | |_____^ this is a pair of braces
 9 | | |
10 | | |       let mut sum = 0;
11 | | |       let mut last = 0;
12 | | |       let mut curr = 1;
13 | | |       for _i in 1..n {
   | | |  ____________________^
14 | | | |         sum = last + curr;
15 | | | |         last = curr;
16 | | | |         curr = sum;
17 | | | |     }
   | | | |_____^ this is a pair of braces
18 | | |       sum
19 | | |   }
   | | |___^^ this is the whole program
   | |_____|| what a nice program!
   |       |
   |       this is a pair of braces
20 |

Structs§

Formatted
Formatted text.
Formatter
Text formatter with span highlights.
Highlight
Text highlight.

Enums§

Char
Character with style information.
Color
Colors used to render the text.
ImportantLines
A set of important lines to render.
Style
Highlight format description.