A cross-platform PTY/ConPTY terminal for Jupyter with bundled xterm.js
Project description
Notebook Terminal 0.3.1
A cross-platform PTY/ConPTY terminal embedded directly in Jupyter with bundled xterm.js.
Author: Robert Zawadzki
GitHub: ZawadzkiR
Repository: github.com/ZawadzkiR/notebook-terminal
Key features
- real Bash/Zsh/CMD/PowerShell prompt from the current user account;
- Linux PTY and Windows ConPTY support;
- bundled xterm.js, FitAddon and WebLinksAddon;
- no
anywidget, custom JupyterLab extension, administrator installation, CDN, HTTP server, iframe or WebSocket required in Jupyter; - offline operation after wheel installation;
- ordered and batched byte transport preserving ANSI sequences and split UTF-8 characters;
- automatic repair after scrolling away from the terminal, switching tabs, resizing panels or restoring the browser window;
- standard
ipywidgetstransport compatible with JupyterLab environments where ordinary widgets already work; - optional rich tabs for DataFrames, HTML, images, Matplotlib and Plotly;
- Flask and Django adapters.
Installation
python -m pip install notebook\_terminal-0.3.1-py3-none-any.whl
Restart the kernel after replacing an older version.
Basic usage
from notebook\_terminal import terminal
term = terminal(
height=450,
interactive=True,
scrollback=10000,
)
The prompt, username, host and working directory are produced by the actual shell process. No account name or path is hardcoded.
term.run("ls -la") # Linux/macOS
term.run("Get-ChildItem") # PowerShell
term.run("python --version")
term.interrupt()
term.clear()
term.focus()
Python execution
term.run\_python("print('hello from Python')")
term.run\_python\_file("script.py", args=\["--verbose"])
Rich output:
term.run\_python("""
import pandas as pd
import matplotlib.pyplot as plt
df = pd.DataFrame({"x": \[1, 2, 3], "y": \[2, 4, 8]})
display(df)
plt.plot(df\["x"], df\["y"])
plt.show()
""", rich\_output=True)
Terminal resizing and notebook scrolling
Version 0.3.1 protects xterm.js from fitting while its notebook output is hidden or temporarily measured at a near-zero width. It observes:
- container size changes;
- return to the browser viewport;
- Jupyter panel and tab visibility changes;
- browser resize, page restore and visibility changes;
- notebook scrolling.
When the terminal becomes visible again, it performs a debounced multi-pass refit, refreshes the renderer, restores the viewport width and sends the corrected rows and columns to PTY/ConPTY. This prevents the terminal from collapsing into a narrow strip after scrolling away and returning.
Linux newlines
convertEol is enabled so output containing LF (\\n) starts from the first column of the next line rather than drifting to the right.
Requirements
- Python 3.9 or newer;
- IPython 8 or newer;
- ipywidgets 8.1 or newer;
- a trusted notebook that permits JavaScript output;
- on Windows:
pywinpty>=3.0.0.
Compatibility target
- JupyterLab 4.x with working standard ipywidgets;
- classic Notebook environments supporting ipywidgets;
- Linux PTY;
- Windows ConPTY through pywinpty.
Development
python -m pip install -e ".\[dev]"
pytest
python -m build
python -m twine check dist/\*
License
MIT. See LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file notebook_terminal-0.3.2.tar.gz.
File metadata
- Download URL: notebook_terminal-0.3.2.tar.gz
- Upload date:
- Size: 3.1 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a561493bf6ddab6370031ad46c13979323a4c402cfcf07c8dcd94c74cab6442
|
|
| MD5 |
480211968211479a0a0cda8419a24068
|
|
| BLAKE2b-256 |
eb18f5984bdd2544cfbe56f818367fcff44abe31c16f83050265b72c34fa7e75
|
File details
Details for the file notebook_terminal-0.3.2-py3-none-any.whl.
File metadata
- Download URL: notebook_terminal-0.3.2-py3-none-any.whl
- Upload date:
- Size: 1.6 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fc5ccb0414ec488ce28bfbb89f104c182e6f699efedacc0ab4a659a2509c4512
|
|
| MD5 |
ac7b057676dc985f3831581f11a8c977
|
|
| BLAKE2b-256 |
d165ff53f5cba6d4cfa95b3c5bb88dbe8d06ed048148b89fb3651449649bc522
|