You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/user-guide/terminal.md
+65
Original file line number
Diff line number
Diff line change
@@ -74,3 +74,68 @@ that object:
74
74
constmyterm=document.querySelector("#my_script");
75
75
awaitmyterm.process('print("Hello world!")');
76
76
```
77
+
78
+
## XTerm reference
79
+
80
+
Each *terminal* has a reachable reference to the [Terminal](https://xtermjs.org/docs/api/terminal/classes/terminal/) instance used to bootstrap the current terminal.
81
+
82
+
On the *JS* side, it's a `script.terminal` property while on the *Python* side, it's a `__terminal__` special reference that guarantees to provide the very same `script.terminal`:
As part of the API, it's very simple to clear a PyTerminal:
100
+
101
+
```html title="Clearing the terminal"
102
+
<scripttype="mpy"terminalworker>
103
+
print("before")
104
+
__terminal__.clear()
105
+
print("after")
106
+
# only "after" is on the terminal
107
+
</script>
108
+
```
109
+
110
+
### Terminal colors
111
+
112
+
Not just colors, most special characters combination would work similarly to **bold** the text or make it **green**, or you can use `print('\033[2J')` to clear it, instead of using the exposed `clear()` method:
113
+
114
+
```html title="Terminal colors"
115
+
<scripttype="mpy"terminalworker>
116
+
print("This is \033[1mbold\033[0m")
117
+
print("This is \033[32mgreen\033[0m")
118
+
print("This is \033[1m\033[35mbold and purple\033[0m")
119
+
</script>
120
+
```
121
+
122
+
### Terminal addons
123
+
124
+
Because there is always a reference to the terminal, it's also possible to add any addon to it:
Although it's worth mentioning that the `WebLinksAddon` is already part of the default terminal distribution in *PyScript*, but that's basically what we do behind the scene to enable it and [any other addon](https://github.com/xtermjs/xterm.js/tree/master/addons/) could work the same.
0 commit comments