Instead of inline styling, you can attach class names to UI controls using the class: prefix and define a global Style object passed to the Application.
Key Concepts:
- Multiple Classes: Use a comma-separated list (
class:left,bottom) or repeat the prefix (class:left class:bottom). - Dot Notation:
class:a.b.c expands to class:a class:a.b class:a.b.c. This is useful for hierarchical styling or Pygments tokens. - Combining Styles: You can combine class names and inline styles. The order determines priority (right-most/later items override earlier ones).
- Complex Selectors: A style rule can target multiple classes simultaneously (e.g.,
('header left', 'underline') targets elements with both header and left classes).
from prompt_toolkit.layout import VSplit, Window
from prompt_toolkit.styles import Style
layout = VSplit([
Window(BufferControl(...), style='class:left'),
HSplit([
Window(BufferControl(...), style='class:top'),
Window(BufferControl(...), style='class:bottom'),
], style='class:right')
])
style = Style([
('left', 'bg:ansired'),
('top', 'fg:#00aaaa'),
('bottom', 'underline bold'),
]),
# To use it, pass it to the Application
app = Application(layout=layout, style=style)