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