@@ -67,34 +67,55 @@ Colors
6767The colors for syntax highlighting are defined by a
6868:class: `~prompt_toolkit.styles.Style ` instance. By default, a neutral built-in
6969style is used, but any style instance can be passed to the
70- :func: `~prompt_toolkit.shortcuts.prompt ` function. All Pygments style classes
71- can be used as well, when they are wrapped in a
72- :class: `~prompt_toolkit.styles.PygmentsStyle `.
70+ :func: `~prompt_toolkit.shortcuts.prompt ` function. A simple way to create a
71+ style, is by using the :class: `~prompt_toolkit.styles.style_from_dict `
72+ function:
73+
74+ .. code :: python
75+
76+ from prompt_toolkit.shortcuts import prompt
77+ from prompt_toolkit.styles import style_from_dict
78+
79+ our_style = style_from_dict({
80+ Token.Comment: ' #888888 bold' ,
81+ Token.Keyword: ' #ff88ff bold' ,
82+ })
83+
84+ text = prompt(' Enter HTML: ' , lexer = PygmentsLexer(HtmlLexer),
85+ style = our_style)
86+
87+
88+ The style dictionary is very similar to the Pygments ``styles `` dictionary,
89+ with a few differences:
90+
91+ - The `roman `, `sans `, `mono ` and `border ` options are not ignored.
92+ - The style has a few additions: `blink `, `noblink `, `reverse ` and `noreverse `.
93+ - Colors can be in the `#ff0000 ` format, but they can be one of the built-in
94+ ANSI color names as well. In that case, they map directly to the 16 color
95+ palette of the terminal.
96+
97+ Using a Pygments style
98+ ^^^^^^^^^^^^^^^^^^^^^^
99+
100+ All Pygments style classes can be used as well, when they are wrapped through
101+ :func: `~prompt_toolkit.styles.style_from_pygments `.
73102
74103Suppose we'd like to use a Pygments style, for instance
75- ``pygments.styles.tango.TangoStyle ``. That works when we wrap it inside
76- :class: `~prompt_toolkit.styles.PygmentsStyle `, but we would still miss some
77- ``prompt_toolkit `` specific styling, like the highlighting of selected text and
78- the styling of the completion menus. Because of that, we recommend to use the
79- :meth: `~prompt_toolkit.styles.PygmentsStyle.from_defaults ` method to generate a
80- a :class: `~prompt_toolkit.styles.Style ` instance.
104+ ``pygments.styles.tango.TangoStyle ``, that is possible like this:
81105
82106Creating a custom style could be done like this:
83107
84108.. code :: python
85109
86110 from prompt_toolkit.shortcuts import prompt
87- from prompt_toolkit.styles import PygmentsStyle
111+ from prompt_toolkit.styles import style_from_pygments
88112
89- from pygments.style import Style
90113 from pygments.styles.tango import TangoStyle
91114
92- our_style = PygmentsStyle.from_defaults(
93- pygments_style_cls = TangoStyle,
94- style_dict = {
95- Token.Comment: ' #888888 bold' ,
96- Token.Keyword: ' #ff88ff bold' ,
97- })
115+ our_style = style_from_pygments(TangoStyle, {
116+ Token.Comment: ' #888888 bold' ,
117+ Token.Keyword: ' #ff88ff bold' ,
118+ })
98119
99120 text = prompt(' Enter HTML: ' , lexer = PygmentsLexer(HtmlLexer),
100121 style = our_style)
@@ -112,10 +133,9 @@ Each token is a Pygments token and can be styled individually.
112133.. code :: python
113134
114135 from prompt_toolkit.shortcuts import prompt
115- from pygments.style import Style
116- from prompt_toolkit.styles import PygmentsStyle
136+ from prompt_toolkit.styles import style_from_dict
117137
118- example_style = PygmentsStyle.from_defaults ({
138+ example_style = style_from_dict ({
119139 # User input.
120140 Token: ' #ff0066' ,
121141
@@ -159,7 +179,7 @@ is simple with the :func:`~prompt_toolkit.shortcuts.print_tokens` function.
159179.. code :: python
160180
161181 # Create a stylesheet.
162- style = PygmentsStyle.from_defaults( style_dict = {
182+ style = style_from_dict( {
163183 Token.Hello: ' #ff0066' ,
164184 Token.World: ' #44ff44 italic' ,
165185 })
0 commit comments