print(str(StyleCode('blue', 34, 'fg')) + 'hello' + str(StyleCode('default', 39, 'fg')) + ' world')
hello world
Styled outputs don’t show in Quarto documentation. Please use a notebook editor to correctly view this page.
StyleCode (name, code, typ)
An escape sequence for styling terminal text.
The primary building block of the S
API.
hello world
Style (codes=None)
A minimal terminal text styler.
The main way to use it is via the exported S
object.
We start with an empty style:
Define a new style by chaining attributes:
You can see a full list of available styles with auto-complete by typing S . Tab.
Apply a style by calling it with a string:
That’s a raw string with the underlying escape sequences that tell the terminal how to format text. To see the styled version we have to print it:
You can also nest styles:
print(S.bold(S.blue('key') + ' = value ') + S.light_gray(' ' + S.underline('# With a comment')) + ' and unstyled text')
key = value # With a comment and unstyled text
demo ()
Demonstrate all available styles and their codes.
30 black
31 red
32 green
33 yellow
34 blue
35 magenta
36 cyan
37 light_gray
39 default
90 dark_gray
91 light_red
92 light_green
93 light_yellow
94 light_blue
95 light_magenta
96 light_cyan
97 white
40 black_bg
41 red_bg
42 green_bg
43 yellow_bg
44 blue_bg
45 magenta_bg
46 cyan_bg
47 light_gray_bg
49 default_bg
100 dark_gray_bg
101 light_red_bg
102 light_green_bg
103 light_yellow_bg
104 light_blue_bg
105 light_magenta_bg
106 light_cyan_bg
107 white_bg
1 bold
2 dim
3 italic
4 underline
5 blink
7 invert
8 hidden
9 strikethrough
22 reset_bold
22 reset_dim
23 reset_italic
24 reset_underline
25 reset_blink
27 reset_invert
28 reset_hidden
29 reset_strikethrough
0 reset