Difference between Rex and TMux
With the latest release of Rex , I wanted to think through how it and T-Mux were different. For this we first need to understand how T-Mux works. T-Mux is essentially a service that has two parts -
- The main background service that holds the various child processes and the final visual state
- The client application which runs in the user’s terminal application and sends keystrokes from the user to the main service and renders the final screen for the user.
Since these two parts are separate, your programs outlast your client being alive. The server is also responsible for remembering the state of the screen including the scrollback buffer for each program.
T-Mux itself is just a terminal program which creates virtual panes for all its visible programs. In addition, to managing the child processes which run the individual applications, it also needs to manage the visuals of the screen. This means the service needs to build a composition of what the screen looks like for the user based on the child programs’ outputs, and the various borders and other visual elements.
This forces is T-Mux to do two passes to show the final output:
- The first pass receives the output from the PTY of the actual program. In this first pass T-Mux is essentially building a copy of the output and storing the programs state.
- The second pass takes all the various outputs from all its visible programs and figures out exactly which character gets inserted for each available spot in the terminal window.
This has been an extremely common setup for developers for decades. The main issues with this are speed (since it’s managing a virtual layout at all times) and fighting the client terminal when it comes to things like selecting text (since the client terminal has no idea about physical borders between different program outputs).
Rex takes a slightly different approach. It owns both the service that manages the various programs and the client that renders the output. Its client renders each visible program in a real libghostty backed terminal. So there is no virtual windows to manage. Because of this, it gets directly send bytes after the first pass to the client terminal. This results in performance gains and getting all client terminal benefits for free since the output is being rendered in its own dedicated window inside the Rex client.
Additionally, having control over the client also means it can pioneer new protocols between its service and its client and the target programs can opt in to these protocols if needed. (They’re already doing it with protocols like session restore).