Skip to main content

interactive terminal in the browser

Project description

pyxterm.js

A fully functional terminal in your browser.

screenshot

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

Clone this repository, enter the pyxtermjs directory, then run:

python3 -m venv venv  # must be python3.6+
venv/bin/pip install -r requirements.txt
venv/bin/python -m pyxtermjs

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


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.2.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

pyxtermjs-0.4.0.2-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file pyxtermjs-0.4.0.2.tar.gz.

File metadata

  • Download URL: pyxtermjs-0.4.0.2.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.6.9

File hashes

Hashes for pyxtermjs-0.4.0.2.tar.gz
Algorithm Hash digest
SHA256 a9482d9085a994f76a7a931babe1f41caa72b08dce84be2366f96cb547b1a1bc
MD5 cb4264a7c0878817a0755844d5d23a9f
BLAKE2b-256 10a881b68990d81a4fb7394e266407c2c069de1ad8f2d34b1cb706cff8d44a0d

See more details on using hashes here.

File details

Details for the file pyxtermjs-0.4.0.2-py3-none-any.whl.

File metadata

  • Download URL: pyxtermjs-0.4.0.2-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.6.9

File hashes

Hashes for pyxtermjs-0.4.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c41c646f9fbb63b88ee767e16e63d74087a4e1caec8779ea134d64ac434892b0
MD5 e6db5d21fb8644e9a0bc21994a4a2a93
BLAKE2b-256 7c7d2b00c7cb957fef270ac96159bc519e01691c6b91d8462a972986b9ad2217

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page