Is there a way to change the size of the terminal window when executing a program from the command line? I tried using IO#winsize= but it does not seem to be doing anything.
There are Xterm Control Sequences for window manipulation:
CSI Ps ; Ps ; Ps t
Window manipulation (from dtterm, as well as extensions).
These controls may be disabled using the allowWindowOps
resource. Valid values for the first (and any additional
parameters) are:
Ps = 1 -> De-iconify window.
Ps = 2 -> Iconify window.
Ps = 3 ; x ; y -> Move window to [x, y].
Ps = 4 ; height ; width -> Resize the xterm window to
height and width in pixels.
Ps = 5 -> Raise the xterm window to the front of the stack-
ing order.
Ps = 6 -> Lower the xterm window to the bottom of the
stacking order.
Ps = 7 -> Refresh the xterm window.
Ps = 8 ; height ; width -> Resize the text area to
[height;width] in characters.
Ps = 9 ; 0 -> Restore maximized window.
Ps = 9 ; 1 -> Maximize window (i.e., resize to screen
size).
Ps = 1 1 -> Report xterm window state. If the xterm window
is open (non-iconified), it returns CSI 1 t . If the xterm
window is iconified, it returns CSI 2 t .
Ps = 1 3 -> Report xterm window position as CSI 3 ; x; yt
Ps = 1 4 -> Report xterm window in pixels as CSI 4 ;
height ; width t
Ps = 1 8 -> Report the size of the text area in characters
as CSI 8 ; height ; width t
Ps = 1 9 -> Report the size of the screen in characters as
CSI 9 ; height ; width t
Ps = 2 0 -> Report xterm window's icon label as OSC L
label ST
Ps = 2 1 -> Report xterm window's title as OSC l title ST
Ps >= 2 4 -> Resize to Ps lines (DECSLPP)
To invoke them from Ruby you could use: ("\e[" is the code for CSI)
print "\e[8;40;80t" # resizes terminal window to 40x80 characters
This only works if your terminal supports the control sequence.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With