设置Cygwin终端窗口的大小

7

我有一个小的Perl脚本,在Cygwin终端中执行并打印出格式化的表格。 在默认窗口大小下,如果文本过长,Cygwin会插入一个换行符,从而破坏我的表格格式。 是否有一种方法可以从我的Perl脚本中设置Cygwin窗口的大小,以避免这种问题?

3个回答

9
如果您是从快捷方式运行此命令,可以在 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.

6

您甚至不需要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";

请注意,在其他*nix系统中,也有可用的ttysize

5
如果您使用mintty作为终端仿真器(过去几年来一直是Cygwin的默认终端仿真器),则可以使用ANSI转义码来操纵终端。您可以通过运行以下Perl代码片段来测试此功能,以更改终端仿真器窗口的大小:
# If terminal supports ANSI escape sequences
$lines = 80;
$columns = 100;
print "\e[8;$lines;${columns}t";

注意:如果在 screen 窗口中运行,此方法将无法工作,我不知道为什么。根据 screen 手册,应支持此转义序列。
解释
ANSI 转义序列的语法并不容易阅读,但这里提供了上述序列的基础文档。 \e 打印 Escape 字符,它开始 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.

我本以为这是不可能的,但它在我的Cygwin中运行了。哇。 - Daniel Böhmer
在我尝试之前,我不确定mintty支持哪些xterm的控制序列。无论如何,我相当确定调整大小不会与cmd.exe一起工作 - 而它确实没有。 - Anthony Geoghegan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接