Skip to content

Commit 3c34a5d

Browse files
authored
Merge pull request #10698 from FoamyGuy/terminal_example
Add terminalio.Terminal example usage to docstring.
2 parents 8ec17f8 + 5a4662c commit 3c34a5d

File tree

1 file changed

+50
-3
lines changed

1 file changed

+50
-3
lines changed

shared-bindings/terminalio/Terminal.c

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@
2121
#endif
2222

2323
//| class Terminal:
24-
//| """Display a character stream with a TileGrid
24+
//| """Terminal manages tile indices and cursor position based on VT100 commands. The ``font`` should be
25+
//| a `fontio.BuiltinFont` and the ``scroll_area`` TileGrid's bitmap should match the font's bitmap.
26+
//|
27+
//| Display a character stream with a TileGrid
2528
//|
2629
//| ASCII control:
2730
//|
@@ -75,6 +78,52 @@
7578
//| +--------+------------+------------+
7679
//| | White | 37 | 47 |
7780
//| +--------+------------+------------+
81+
//|
82+
//| Example Usage:
83+
//|
84+
//| .. code-block:: python
85+
//|
86+
//| import time
87+
//| import displayio
88+
//| import supervisor
89+
//| from displayio import Group, TileGrid
90+
//| from terminalio import FONT, Terminal
91+
//|
92+
//| main_group = Group()
93+
//| display = supervisor.runtime.display
94+
//| font_bb = FONT.get_bounding_box()
95+
//| screen_size = (display.width // font_bb[0], display.height // font_bb[1])
96+
//| char_size = FONT.get_bounding_box()
97+
//|
98+
//| palette = displayio.Palette(2)
99+
//| palette[0] = 0x000000
100+
//| palette[1] = 0xffffff
101+
//|
102+
//| tilegrid = TileGrid(
103+
//| bitmap=FONT.bitmap, width=screen_size[0], height=screen_size[1],
104+
//| tile_width=char_size[0], tile_height=char_size[1], pixel_shader=palette)
105+
//|
106+
//| terminal = Terminal(tilegrid, FONT)
107+
//|
108+
//| main_group.append(tilegrid)
109+
//| display.root_group = main_group
110+
//|
111+
//| message = "Hello World\\n"
112+
//| terminal.write(message)
113+
//|
114+
//| print(terminal.cursor_x, terminal.cursor_y)
115+
//| move_cursor = chr(27) + "[10;10H"
116+
//| terminal.write(f"Moving the cursor\\n{move_cursor} To here")
117+
//|
118+
//| cursor_home = chr(27) + f"[{screen_size[1]};0H"
119+
//| terminal.write(cursor_home)
120+
//| i = 1
121+
//| while True:
122+
//| terminal.write(f"Writing again {i}\\n")
123+
//| i = i + 1
124+
//| time.sleep(1)
125+
//|
126+
//|
78127
//| """
79128
//|
80129
//| def __init__(
@@ -84,8 +133,6 @@
84133
//| *,
85134
//| status_bar: Optional[displayio.TileGrid] = None,
86135
//| ) -> None:
87-
//| """Terminal manages tile indices and cursor position based on VT100 commands. The font should be
88-
//| a `fontio.BuiltinFont` and the TileGrid's bitmap should match the font's bitmap."""
89136
//| ...
90137
//|
91138

0 commit comments

Comments
 (0)