Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xterm.js Option #1317

Merged
merged 48 commits into from May 29, 2023
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
3436bdf
Add 'xterm' attribute in py-config
JeffersGlass Mar 21, 2023
9c9529f
Factor out PyTerminalBaseClass
JeffersGlass Mar 21, 2023
abc8873
Split out xterm class
JeffersGlass Mar 21, 2023
207a0ba
Basic working xterminal
JeffersGlass Mar 21, 2023
30678c5
Add xterm to node modules and use types
JeffersGlass Mar 22, 2023
5d668d3
Add dummy test for terminal libraries
JeffersGlass Mar 22, 2023
15c1b35
Add fit, weblinks addons, fix bug
JeffersGlass Mar 23, 2023
75cb29d
More
JeffersGlass Mar 23, 2023
d8c3a99
Improve typing
JeffersGlass Mar 25, 2023
1038368
Add screen reader mode
JeffersGlass Mar 27, 2023
2142a8f
adjust typing
JeffersGlass Mar 27, 2023
2f80c48
Begin actual test
JeffersGlass Mar 28, 2023
f3f8219
Fix module name, remove validation
JeffersGlass Mar 28, 2023
6ba2b69
Add dummy test files for conveninence
JeffersGlass Mar 30, 2023
257223c
Remove fitter
JeffersGlass Mar 30, 2023
025a096
Remove weblinks, strengthen tests
JeffersGlass Apr 10, 2023
30678b8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 10, 2023
cc86bc5
Wait for xterm to be visible before asserts
JeffersGlass Apr 13, 2023
235da77
Fix some imports
JeffersGlass Apr 13, 2023
7f97249
Use new validation for xterm param
JeffersGlass Apr 21, 2023
3d8ebb0
merge from main
JeffersGlass Apr 21, 2023
18b8ef0
Merge branch 'main' into xterm
JeffersGlass Apr 22, 2023
2a4367b
Adjust comment
JeffersGlass Apr 25, 2023
93e8947
Change what we wait for to confirm text is on page
JeffersGlass Apr 25, 2023
861f9a7
Add docstring
JeffersGlass Apr 25, 2023
5c8f94b
Begin docs
JeffersGlass Apr 25, 2023
5d37bea
Actually remove weblinks addon
JeffersGlass Apr 26, 2023
d18de75
Add promise interface, docs
JeffersGlass Apr 26, 2023
258ec03
Add delay and comment
JeffersGlass Apr 27, 2023
33656fb
Changelog
JeffersGlass Apr 27, 2023
aef5d07
Fix
JeffersGlass Apr 28, 2023
628ab3c
Add note on terminal formatting packages
JeffersGlass Apr 28, 2023
b55d67a
Update note on package specifics
JeffersGlass Apr 28, 2023
09b6841
Remove testing files
JeffersGlass Apr 28, 2023
c0f7d89
Address some of Andrea's comments
JeffersGlass May 2, 2023
60b1bfc
Merge from main
JeffersGlass May 2, 2023
a04f243
Merge from main
JeffersGlass May 3, 2023
7e12b2e
Remove unused dependencies
JeffersGlass May 3, 2023
b6f4c45
Change class= to classList.add
JeffersGlass May 3, 2023
ad4ad3d
Guard against initializing a tag twice
JeffersGlass May 10, 2023
38bd056
Rename _moduleResolved, add comment
JeffersGlass May 10, 2023
72c5d31
Merge branch 'main' into xterm
JeffersGlass May 15, 2023
b907474
Address some comments
JeffersGlass May 16, 2023
38946f7
Add test for multiple xterms
JeffersGlass May 21, 2023
5192d9a
Rememeber known tag earlier
JeffersGlass May 23, 2023
774cc44
Don't log all xterm writes to console
JeffersGlass May 25, 2023
0b0a7ba
Merge branch 'main' into xterm
JeffersGlass May 27, 2023
40961ab
xtermReadyPromise -> xtermReady
JeffersGlass May 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog.md
Expand Up @@ -7,6 +7,7 @@
Features
--------

- Added the `xterm` attribute to `py-config`. When set to `True` or `xterm`, an (output-only) [xterm.js](http://xtermjs.org/) terminal will be used in place of the default py-terminal.
- Added the `@when` decorator for attaching Python functions as event handlers
- The `py-mount` attribute on HTML elements has been deprecated, and will be removed in a future release.

Expand Down
27 changes: 26 additions & 1 deletion docs/reference/plugins/py-terminal.md
Expand Up @@ -4,7 +4,7 @@ This is one of the core plugins in PyScript, which is active by default. With it

## Configuration

You can control how `<py-terminal>` behaves by setting the value of the `terminal` configuration in your `<py-config>`, together with the `docked` one.
You can control how `<py-terminal>` behaves by setting the values of the `terminal`, `docked`, and `xterm` fields in your configuration in your `<py-config>`.

For the **terminal** field, these are the values:

Expand All @@ -26,6 +26,31 @@ Please note that **docked** mode is currently used as default only when `termina

In all other cases it's up to the user decide if a terminal should be docked or not.

For the **xterm** field, these are the values:

| value | description |
|-------|-------------|
| `false` | This is the default. The `<py-terminal>` is a simple `<pre>` tag with some CSS styling. |
| `true` or `xterm` | The [xtermjs](http://xtermjs.org/) library is loaded and its Terminal object is used as the `<py-terminal>`. It's visibility and position are determined by the `docked` and `auto` keys in the same way as the default `<py-terminal>` |

The xterm.js [Terminal object](http://xtermjs.org/docs/api/terminal/classes/terminal/) can be accessed directly if you want to adjust its properties, add [custom parser hooks](http://xtermjs.org/docs/guides/hooks/), introduce [xterm.js addons](http://xtermjs.org/docs/guides/using-addons/), etc. Access is best achieved by awaiting the `xtermReadyPromise` attribute of the `<py-terminal>` HTML element itself:
JeffersGlass marked this conversation as resolved.
Show resolved Hide resolved

```python
import js
import asyncio

async def adjust_term_size(columns, rows):
xterm = await js.document.querySelector('py-terminal').xtermReadyPromise
JeffersGlass marked this conversation as resolved.
Show resolved Hide resolved
xterm.resize(columns, rows)

asyncio.ensure_future(adjust_term_size(40,10))
```

Some terminal-formatting packages read from specific environment variables to determine whether they should emit formatted output; PyScript does not set these variables explicitly - you may need to set them yourself, or force your terminal-formatting package into a state where it outputs correctly formatted output.

A couple of specific examples:
- the [rich](https://github.com/Textualize/rich) will not, by default, output colorful text, but passing `256` or `truecolor` as an argument as the `color_system` parameter to the [Console constructor](https://rich.readthedocs.io/en/stable/reference/console.html#rich.console.Console) will force it to do so. (As of rich v13)
- [termcolor](https://github.com/termcolor/termcolor) will not, by default, output colorful text, but setting `os.environ["FORCE_COLOR"] = "True"` or by passing `force_color=True` to the `colored()` function will force it to do so. (As of termcolor v2.3)

### Examples

Expand Down
51 changes: 50 additions & 1 deletion pyscriptjs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pyscriptjs/package.json
Expand Up @@ -37,7 +37,8 @@
"pyodide": "0.22.1",
"synclink": "0.2.4",
"ts-jest": "29.0.3",
"typescript": "5.0.4"
"typescript": "5.0.4",
"xterm": "^5.1.0"
},
"dependencies": {
"basic-devtools": "^0.1.6",
Expand Down