Skip to content

Terminal

A read-only view that understands ANSI colors and stays scrolled to the end. Feed it the output of a process you run (for example with subprocess in a thread and pz.post). It also accepts lines of (text, color) segments; ui.ansi(text) converts ANSI text into those segments.

ui.terminal · Category: Code and tools · Full reference →

TerminalTerminal
  • To show build output, test runs, server logs or any command’s output.
import pyzed as pz
from pyzed import ui
out = ("$ pytest -q\n\x1b[32m........................\x1b[0m\n\x1b[32m24 passed\x1b[0m in 1.21s\n"
"$ maturin develop --release\n\x1b[2m Compiling pyzed v0.4.0\x1b[0m\n"
"\x1b[32m✓\x1b[0m Installed pyzed-0.4.0\n$ ")
pz.container(ui.terminal(out), width=560, height=190)
Terminal: Plain textTerminal: Plain text
Plain text
Code
pz.container(ui.terminal("$ ls\nmain.py notes.md pyproject.toml\n$ "), width=380, height=80)
Terminal: ANSI colorsTerminal: ANSI colors
ANSI colors
Code
pz.container(ui.terminal("\x1b[32m✓\x1b[0m 24 passed \x1b[33m!\x1b[0m 1 warning \x1b[31m✗\x1b[0m 0 failed"),
width=380, height=50)
Terminal: font_size=16Terminal: font_size=16
font_size=16
Code
pz.container(ui.terminal("$ python main.py\nHello", font_size=16), width=380, height=70)
Terminal: (text, color) segmentsTerminal: (text, color) segments
(text, color) segments
Code
pz.container(ui.terminal([[("ok ", "#a1c181"), ("build", None)], [("err ", "#d07277"), ("lint", None)]]),
width=380, height=60)

Terminal has no events of its own: it shows what you give it. Like every widget it also has the 18 common events (click, double_click, right_click, mouse_enter, drag, key_down, resize…), attached with .on(...): see Events and Events of every component.

terminal(lines, *, font_size=13, id=None, theme=None)

A read-only terminal view with ANSI colors. It stays scrolled to the end.

Property Default Description
lines required Text with ANSI escapes, or a list of lines of (text, color) segments.
font_size 13 Font size.
id None Stable identifier used to focus or scroll it with a Command.
theme None Theme to use instead of the current one (pyzed.theme.current()).

Full reference →

ansi(text)

Converts text with ANSI colors into lines of (text, color_name) segments.

Property Default Description
text required Text with ANSI escapes.

Full reference →