Set cygwin terminal window size

I have a small perl script that runs on a cygwin terminal and prints a formatted table. In the Window Size window, by default, cygwin inserts a line break if the text is too long and thereby destroys the format of my table. Is there any way from my perl script to set the cygwin window to a larger size to avoid such a problem?

+4
source share
3 answers

If you use mintty as a terminal emulator (it has been the default terminal emulator for Cygwin for the past few years), you can use ANSI escape codes to control the terminal.

You can verify this by running the following Perl code snippet to resize the terminal emulator window:

# If terminal supports ANSI escape sequences
$lines = 80;
$columns = 100;
print "\e[8;$lines;${columns}t";

Note. This does not work if you run it in a window screenand I do not know why. According to the screenman page , this escape sequence must be supported.

Description

The ANSI escape sequence syntax is not the easiest to read, but the documentation that provides the basis for the above sequence.

\e Escape, escape- ANSI. Control Sequence Introduction (CSI).

, t, xterm

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.
+4

, mintty, . , , .

$ /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 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.
+3

Perl, Bash:

echo -en "\e[8;35;100t";

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";

, * nixes ttysize.

+2

All Articles