interactive terminal in the browser
Project description
pyxterm.js
A fully functional terminal in your browser.
How does this work?
On the backend:
- A Flask server is running
- The Flask server uses flask-socketio, a websocket library for Flask and socketio
- A pty ("pseudo-terminal") is spawned that runs bash.
- You can think of a pty as a way to serialize/deserialize a terminal session. The Python docs describe it as "starting another process and being able to write to and read from its controlling terminal programmatically".
On the frontend:
- Xterm.js is used to render Xterm output data in the browser.
- This means escape codes used by terminals to control the cursor location, color, and other options can be passed directly to Xterm.js and Xterm.js will faithfully render them as a terminal would.
- Output from the pty process on the backend is fed into it.
- Input from the browser is passed via websocket to the pty's input
Why?
The real purpose of this is to show a basic proof of concept on how to bring Xterm.js, Python, Flask, and Websockets together to run a pty in the browser.
This is a
- starting point to build your own web app with a terminal
- learning tool to understand what a
pty
is, and how to use one in Python - way to see Flask and Flask-SocketIO in action
- way to play around with Xterm.js in a meaningful environment
Installation
Option 1
Run pyxtermjs with no commitment in an ephemeral environment with pipx
pipx run pyxtermjs # install and run in ephemeral environment
Option 2
Clone this repository, enter the pyxtermjs
directory, create a virtual environment (python3 -m venv venv
), activate it (source venv/bin/activate
) then run
pip install -e .
Documentation
>> pyxtermjs --help
usage: pyxtermjs [-h] [-p PORT] [--debug] [--version] [--command COMMAND]
[--cmd-args CMD_ARGS]
A fully functional terminal in your browser.
https://github.com/cs01/pyxterm.js
optional arguments:
-h, --help show this help message and exit
-p PORT, --port PORT port to run server on (default: 5000)
--debug debug the server (default: False)
--version print version and exit (default: False)
--command COMMAND Command to run in the terminal (default: bash)
--cmd-args CMD_ARGS arguments to pass to command (i.e. --cmd-args='arg1
arg2 --flag') (default: )
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
pyxtermjs-0.4.0.0.tar.gz
(5.3 kB
view details)
Built Distribution
File details
Details for the file pyxtermjs-0.4.0.0.tar.gz
.
File metadata
- Download URL: pyxtermjs-0.4.0.0.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9468e4a7f602b22eb0d673ffa1863137df7ecfea96126e27fcea0717c5053060 |
|
MD5 | e92fd992f96e8fe515bd632d97fe7ee6 |
|
BLAKE2b-256 | 9d319a452f927714267c21c0650da5a4ef98833e709d72eb72aff1af8c4466ac |
File details
Details for the file pyxtermjs-0.4.0.0-py3-none-any.whl
.
File metadata
- Download URL: pyxtermjs-0.4.0.0-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c094791e893679712d78b1abb6a2ec02ad98c9be5a003a3a8d13f1bc99b55c32 |
|
MD5 | 43e379d9191e28e3b5759cbca904d63f |
|
BLAKE2b-256 | 8b8a5b08c1007b45e1b24b30154d94ebfa74871dbf30b2a28f98f6860495baae |