I'm writing a terminal sharing web application using XTerm.js. The app uses WebSockets handled by a custom server written in PHP to send input from the browser to the host terminal. The input is received by curl
and curl
also sends the output back to the server which then pushes it to the browser. No SSH client library is involved, so the answer to this question unfortunately doesn't help me.
The issue is that applications that rely on knowing the terminal size aren't scaled properly and default to 24 rows by 80 columns. When I run some columns typically used to report terminal size I get the following results:
> stty size
0 0
> tput lines
24
> tput cols
80
I use xterm-addon-fit to resize the terminal, but it only works with the output of commands that don't rely on terminal size, for instance ls -l
. Commands that do rely on it, for instance ls
(no arguments) or more importantly vim
only render their results assuming 24x80 terminal size.
I tried using the SIGWINCH signal from the previously mentioned question because I thought it might work when there's no SSH client in the middle. So I sent something like this in the browser:
echo -e "\e[8;30;120t"
but it didn't work.
I could try sending something like this as the first command:
stty rows 48 cols 160
but that can't be repeated in case the window size changes, so the terminal size will be fixed after starting it.
Is there a way to dynamically control the terminal size with XTerm.js? You can see the app in question here terminalmirror.com if you want to see the issue in action.