Description
This is an issue capturing the discussion @mofux and I had in Prague. We can pull this into individual issues after any discussion.
Split frontend and backend
The idea here is to improve the overall code quality (particularly in Terminal.ts) and also allow monaco or a native UI to be used as a frontend more easily (eventually):
-
We should move everything that touches the DOM into a Frontend object.
-
Frontend owns a backend, this should change how terminals are constructed:
const term = new Terminal(); // Backend const termFrontend = new TerminalDomFrontEnd(term);
-
We could do it this way instead and maintain backwards compatibility, but even if you used a custom frontend you would need to include the code for the default one:
class Terminal { open(elementOrFrontend: HTMLElement | ITerminalFrontEnd); }
Also, the terminal knows about the frontend in this case.
-
An
ITerminalBackend
interface, whichITerminalFrontend
depends on, could look like this:interface ITerminalBackend { write(data: string): void; keyevent(event: ITerminalKeyEvent); mousemove(event: ITerminalMouseEvent); mousedown(event: ITerminalMouseEvent); mouseup(event: ITerminalMouseEvent); resize(cols: number, rows: number); onResize: Event<...>; // No wheel since that's handled entirely in the frontend // The backend should fire events that the frontend can listen to for // things like entering and leaving application/mouse mode (which the // frontend needs to know about for things like wheel/selection handling) }
-
Keyboard events in Terminal should be translated to an xterm event before sending it to
_evaluateKeyEscapeSequence
, theInputHandler
, etc. -
Mouse events should also be translated
-
These steps could be done incrementally as time allows and would eventually allow us to have much higher quality tests that test just the terminal backend, without worrying about the DOM and the complexities that come with testing that.
Web workers
The terminal backend is a good candidate to eventually live in a web worker, as opposed to just the parser that was the thinking before.
Viewport vs full buffer data
If the backend lives in a webworker, there needs to be a decision whether we want to only send viewport data or if the frontend should own the entire buffer.