xterm.js console doesnt set terminal size correctly

red_book

New Member
Oct 27, 2020
4
0
1
26
Hi,

The xterm.js terminal doesnt set the terminal size correctly causing the text to not wrap and overwrite the text on the current line

1625761658145.png

The xterm.js console tries to set the tty size by sending "1:<cols>:<rows>:" over the websocket, however, this doesnt work
Example:

1625761781820.png

The actual tty size:

1625761887133.png

The Fix:

1625762042473.png


The proxmox API doesnt handle setting the xterm.js size correctly. Please could someone send me a patch, or update the API to resolve this issue. Or tell me where the source code is for how proxmox handles the xterm.js websocket requests.

Thanks
 

Attachments

  • 1625761829753.png
    1625761829753.png
    5.5 KB · Views: 9
  • 1625761993565.png
    1625761993565.png
    24.3 KB · Views: 9
Last edited:
Just to understand the setup and potential issue correctly, here you're using yterm.js on a VM with a serial socket, not a container?
(guessing from the hostname in the screenshot)
 
since the terminal runs over a serial socket, there is no way to signal the vm a console size change
(iow. you cannot send a SIGWINCH or similar to the vm)
or is there a possiblity that i miss ?
 
since the terminal runs over a serial socket, there is no way to signal the vm a console size change
(iow. you cannot send a SIGWINCH or similar to the vm)
or is there a possiblity that i miss ?
Im not sure how the proxmox works on the backend of this but I saw it opens a websocket to send/receive messages.
It sends 1:208:81: to the VM, from what I can tell those numbers relate to the cols/rows of the terminal. Im not sure what proxmox does with those numbers on the backend or what commands it tries to run to set those values.

The terminal size on the serial socket can be changed by running `stty cols <cols> rows <rows>` manually.
Proxmox might try to set the terminal size without running commands on the VM tho. Could you share the code for the websocket?
The related endpoint is:
/api2/json/nodes/{node}/qemu/{vmid}/vncwebsocket - https://pve.proxmox.com/pve-docs/api-viewer/#/nodes/{node}/vncwebsocket
 
The xterm.js is used not only for the VMs but also for the Container, where we actually can control that.

A "dumb" serial socket just does not support this from the outside, so you need to explicitly set it to correct values in the tty itself.

The front-end send the size requests both times, but in one case (VMs) the backend cannot really do anything about it.

Proxmox might try to set the terminal size without running commands on the VM tho. Could you share the code for the websocket?
All source code is at https://git.proxmox.com/?o=age

For example, xtrerm.js including the rust wrapper for the websocket is in the pve-xtermjs git repo:
https://git.proxmox.com/?p=pve-xtermjs.git;a=summary
 
I know this thread is a bit old, but I was looking for a resize solution and found something that works for me and thought I would post it here.

From https://unix.stackexchange.com/questions/16578/resizable-serial-console-window/19265#19265

The function res() which is noted can check the size of the window upon login, so it's resized at that point. This does not require installation of any package. I have added it to my /etc/profile (on an Ubuntu vm) like this:

Code:
res() {

  old=$(stty -g)
  stty raw -echo min 0 time 5

  printf '\0337\033[r\033[999;999H\033[6n\0338' > /dev/tty
  IFS='[;R' read -r _ rows cols _ < /dev/tty

  stty "$old"

  # echo "cols:$cols"
  # echo "rows:$rows"
  stty cols "$cols" rows "$rows"
}

[ $(tty) = /dev/ttyS0 ] && res

In practice, when I open a Proxmox xterm.js terminal window I then resize the window to where I want it and click Enter in the terminal and proceed to login. Resizes automatically upon login.

As it is above, to resize again exactly to window size, a logout/login sequence would need to occur.

There was an additional idea floated in the thread to resize after every command, but that was more than I needed, and it was reported to sometimes conflict with the commands.
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!