如何使用 ANSI 转义码保存 GNOME 终端内容?

l0b*_*0b0 9 bash gnome-terminal screenshot xterm

VT100 终端有一种相对简单的方法可以使用-将带有转义码的终端内容保存到文件中:Metap

XTerm.VT100.printAttributes: 2
XTerm.VT100.printerCommand: cat - > file
XTerm.VT100.translations: #override Meta <KeyPress> P: print() \n
Run Code Online (Sandbox Code Playgroud)

我环顾四周,找不到在默认的 GNOME 终端 + XTerm + Bash 中工作的解决方案。

想要一个包含窗口内容的图像。

看起来 GNOME 终端最终可能会对此进行修复,但是没有关于它将包含在哪个版本中的信息,并且距离上次更新已经快三年了......

小智 4

不幸的是,l0b0 开箱即用的答案是:这是不可能的。

在我的另一个答案中,我列出了如何使用脚本来执行此操作,尽管正如您指出的那样存在一些差异。另一种方法是编译源代码或使用不稳定的版本。

Gnome 终端源 tarball

Raring中的版本是3.6.1,所以你可以看看这个源码。Terminal-window.c 内部第 115 行:

/*
 * We don't want to enable content saving until vte supports it async.
 * So we disable this code for stable versions.
 */

#include "terminal-version.h"

#if (TERMINAL_MINOR_VERSION & 1) != 0
#define ENABLE_SAVE
#else
#undef ENABLE_SAVE
#endif
#endif
Run Code Online (Sandbox Code Playgroud)

选项:

  1. 在其下添加#define ENABLE_SAVE。
  2. 修改版本为unstable。
  3. 下载不稳定版本的 .DEB。

希望这可以帮助。