Search code examples
web-applicationsterminalterminal-emulatorxtermjs

Web terminal emulator with control over i/o


We are looking at building a web-based ssh for teaching linux for newbies.

However, we want to be able to read input before it gets executed on the backend terminal, and read output before it gets displayed on the browser so as to make decisions in the web application based on these.

I looked into xterm.js, but don't know how to enable this sort of control, with any of the present open source web based terminal emulators.

Any idea how to get started?


Solution

  • What you have to do is to create an xterm.js add-on similar to the attach addon, but a bit more interventional.

    In a few points, you will have to:

    1. Connect xterm.js and your back-end via a WebSocket
    2. Listen to the xterm.js data event and after processing it, send the data to the socket
    3. Listen to the message WebSocket event and process the message, before writing it to the terminal, using #write

    A quick look to the attach addon source code could also be enlightening