I have a small perl script, which is executed in a cygwin terminal and prints out a formatted table. On Default window size, cygwin will insert an line break if the text gets too long and thereby destroy the format of my table. Is there a way from my perl script to set the cygwin window to a bigger size to avoid that kind of problem?
If you are using mintty as your terminal emulator (it has been the default terminal emulator for Cygwin for the past couple of years), you can use ANSI escape codes to manipulate the terminal.
You can test this by running the following snippet of Perl code to change the size of your terminal emulator window:
# If terminal supports ANSI escape sequences
$lines = 80;
$columns = 100;
print "\e[8;$lines;${columns}t";
Note: This doesn't work if run while in a screen
window and I don't know why. According to the screen
man page, this escape sequence should be supported.
Explanation
The syntax of ANSI escape sequences isn’t the easiest to read but here’s the documentation that provides the basis of the above sequence.
The \e
prints an Escape character which begins the ANSI escape sequence.
This is also known as the Control Sequence Introducer (CSI).
The specific sequence ending with t
comes from this List of xterm control
sequences
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 = 8 ; height ; width -> Resize the text area to given
height and width in characters. Omitted parameters reuse the
current height or width. Zero parameters use the display's
height or width.
cmd.exe
-- and it didn't. –
Bourges If you happen to be running this from a shortcut where you could add flags to the mintty
command, you can set the size then. The benefit is that it looks smoother without the twitchy resize.
$ /cygdrive/c/tools/cygwin/bin/mintty.exe --help
Usage: mintty [OPTION]... [ PROGRAM [ARG]... | - ]
Start a new terminal session running the specified program or the user's shell.
If a dash is given instead of a program, invoke the shell as a login shell.
Options:
-c, --config FILE Load specified config file (cf. -C or -o ThemeFile)
-e, --exec ... Treat remaining arguments as the command to execute
-h, --hold never|start|error|always Keep window open after command finishes
-p, --position X,Y Open window at specified coordinates
-p, --position center|left|right|top|bottom Open window at special position
-p, --position @N Open window on monitor N
-s, --size COLS,ROWS Set screen size in characters (also COLSxROWS)
-s, --size maxwidth|maxheight Set max screen size in given dimension
-t, --title TITLE Set window title (default: the invoked command) (cf. -T)
-w, --window normal|min|max|full|hide Set initial window state
-i, --icon FILE[,IX] Load window icon from file, optionally with index
-l, --log FILE|- Log output to file or stdout
--nobidi|--nortl Disable bidi (right-to-left support)
-o, --option OPT=VAL Set/Override config file option with given value
-B, --Border frame|void Use thin/no window border
-R, --Reportpos s|o Report window position (short/long) after exit
--nopin Make this instance not pinnable to taskbar
-D, --daemon Start new instance with Windows shortcut key
-H, --help Display help and exit
-V, --version Print version information and exit
See manual page for further command line options and configuration.
You don't even need Perl, you can do the same in Bash:
echo -en "\e[8;35;100t";
Or why not a script:
#!/bin/bash
# minsize - A TTY re-size escape sequence for use with mintty Cygwin
# Usage: minsize <width> <height>
WIDTH=$1
HEIGHT=$2
echo -en "\e[8;${HEIGHT};${WIDTH}t";
Note, that on other *nixes there is ttysize
available.
If you are using mintty as your terminal emulator (it has been the default terminal emulator for Cygwin for the past couple of years), you can use ANSI escape codes to manipulate the terminal.
You can test this by running the following snippet of Perl code to change the size of your terminal emulator window:
# If terminal supports ANSI escape sequences
$lines = 80;
$columns = 100;
print "\e[8;$lines;${columns}t";
Note: This doesn't work if run while in a screen
window and I don't know why. According to the screen
man page, this escape sequence should be supported.
Explanation
The syntax of ANSI escape sequences isn’t the easiest to read but here’s the documentation that provides the basis of the above sequence.
The \e
prints an Escape character which begins the ANSI escape sequence.
This is also known as the Control Sequence Introducer (CSI).
The specific sequence ending with t
comes from this List of xterm control
sequences
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 = 8 ; height ; width -> Resize the text area to given
height and width in characters. Omitted parameters reuse the
current height or width. Zero parameters use the display's
height or width.
cmd.exe
-- and it didn't. –
Bourges © 2022 - 2024 — McMap. All rights reserved.