Terminal

Interactive terminal emulator running your login shell.

📄 Docs only

Tags: devtools

Demonstrates PTY-backed ShellNode + TerminalEmulator widget with MSDF font rendering. Text draws in the font the engine ships with. Powerline arrows, git icons and the other private-use glyphs that Powerlevel10k and similar zsh themes emit are not in it: install a Nerd Font (e.g. Hack Nerd Font Mono) and the glyph fallback chain picks them up automatically.

Controls:

  • Click terminal to focus

  • Type normally for text input

  • Ctrl+key combinations work (Ctrl+C, Ctrl+X, etc.)

  • Scroll wheel for scrollback history

  • Try: nano, htop, ls –color, etc.

Run: uv run python examples/features/devtools/terminal.py

Source

 1"""Terminal: Interactive terminal emulator running your login shell.
 2
 3Demonstrates PTY-backed ShellNode + TerminalEmulator widget with MSDF font
 4rendering. Text draws in the font the engine ships with. Powerline arrows, git
 5icons and the other private-use glyphs that Powerlevel10k and similar zsh themes
 6emit are not in it: install a Nerd Font (e.g. Hack Nerd Font Mono) and the glyph
 7fallback chain picks them up automatically.
 8
 9Controls:
10  - Click terminal to focus
11  - Type normally for text input
12  - Ctrl+key combinations work (Ctrl+C, Ctrl+X, etc.)
13  - Scroll wheel for scrollback history
14  - Try: nano, htop, ls --color, etc.
15
16Run: uv run python examples/features/devtools/terminal.py
17
18# /// simvx
19# [web]
20# disabled = true
21# reason = "Spawns a real OS shell via a PTY: no subprocess or pty devices exist in the browser sandbox."
22# ///
23"""
24
25import os
26
27from simvx.core import AnchorPreset, Node, ShellNode, Vec2
28from simvx.core.ui import Label, TerminalEmulator
29from simvx.graphics import App
30
31COLS, ROWS = 100, 30
32
33
34class TerminalDemo(Node):
35    def on_ready(self):
36        # Title
37        title = Label("SimVX Terminal: click to focus, type to interact")
38        title.text_colour = (0.6, 0.8, 1.0, 1.0)
39        title.font_size = 14.0
40        title.set_anchor_preset(AnchorPreset.TOP_LEFT)
41        title.margin_left = 10
42        title.margin_top = 5
43        title.size = Vec2(800, 20)
44        self.add_child(title)
45
46        # Terminal widget (sized via constructor)
47        self.term = TerminalEmulator(cols=COLS, rows=ROWS)
48        self.term.set_anchor_preset(AnchorPreset.TOP_LEFT)
49        self.term.margin_left = 10
50        self.term.margin_top = 30
51        self.add_child(self.term)
52
53        # PTY-backed process
54        shell = os.environ.get("SHELL", "/bin/bash")
55        self.proc = ShellNode(shell, use_pty=True)
56        self.add_child(self.proc)
57
58        # Wire terminal ↔ process, start, and set PTY size
59        self.term.attach(self.proc)
60        self.proc.start()
61        self.proc.resize(COLS, ROWS)
62
63        # Auto-focus the terminal
64        self.term.set_focus()
65
66        # Close app when shell exits
67        self.proc.process_exited.connect(self._on_exit)
68
69    def _on_exit(self, _code):
70        if self.app is not None:
71            self.app.quit()
72
73
74if __name__ == "__main__":
75    app = App(title="SimVX Terminal", width=880, height=650)
76    app.run(TerminalDemo())