设置cygwin终端窗口的大小



我有一个小的perl脚本,它在cygwin终端中执行,并打印出一个格式化的表。在默认窗口大小下,如果文本过长,cygwin将插入换行符,从而破坏我的表的格式。我的perl脚本有没有办法将cygwin窗口设置为更大的大小来避免这种问题?

如果您碰巧从可以向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'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.

您甚至不需要Perl,您可以在Bash:中执行同样的操作

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

或者为什么不编写脚本:

#!/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";

请注意,在其他*nixe上有可用的ttysize

如果您使用mintty作为终端模拟器(它是默认的过去几年Cygwin的终端模拟器),您可以使用ANSI操纵终端的转义码。

您可以通过运行以下Perl代码片段来更改终端模拟器窗口的大小来测试这一点:

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

注意:如果在screen窗口中运行,这将不起作用,我不知道为什么。根据screen手册页,应该支持此转义序列。

解释

ANSI转义序列的语法不是最容易阅读的,但以下是提供上述序列基础的文档。

e打印一个转义符,该转义符开始ANSI转义序列。这也被称为对照序列导入器(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.

最新更新