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
There are a few ways to install and run.
Clone & Run Locally
Clone this repository, enter the pyxtermjs directory.