See pyxterm for the original idea that this is based on.
In summary:
- 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
uwsgi --http :4555 --gevent 1000 --http-websockets --master --wsgi-file wsgi.py --callable app --stats 127.0.0.1:9191
uWSGI options --http :4555 Tell uWSGI to run a http server with the callable wsgi application --wsgi-file Relative/absolute path to the wsgi file that imports the callable FLASK application --callable Callable Flask application --http-websockets Enable web socket communication
Please make use of the pyxterm.ini file for uWSGI configuration and the nginx.conf file for NGINX configuration.
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 -r requirements.txt
python -m pyxtermjs
>> pyxtermjs --help
usage: pyxtermjs [-h] [-p PORT] [--debug] [--version] [--command COMMAND]
[--cmd-args CMD_ARGS]
A fully functional terminal in your browser.
http://gitsrv/algerchen/pyxtermjs
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: )