ctrl + 的终端转义序列是什么? TERM=linux 中的箭头(左、右、...)

发布于 2024-12-09 17:43:55 字数 755 浏览 0 评论 0原文

我正在浏览器中构建一个终端窗口(比如 ajaxterm),并且不知道将哪个转义序列发送到 ssh 隧道(通过 paramiko.SSHClient().invoke_shell(term='linux') 打开)。

我找到了 键盘记录器< /a> 并在终端中使用 $TERM == 'linux' 进行尝试,但它为 ctrl+leftleft 返回相同的序列 (27,91,68 )。

如果我在另一个终端中尝试键盘记录器(使用 $TERM == 'xterm'),我会得到代码(27,91,49,59,53,68)。但这些代码不会从 SSH 通道生成预期的输出(这会将光标在正常的 Linux shell 上向左移动一个字)。即使我用 term='xterm' 启动 paramiko 也是如此。

知道我应该使用什么顺序吗?或者为什么上面的顺序不起作用?

更新:我很乐意使用另一种终端类型(不是“linux”),但不幸的是pyte仅适用于 VTxxx 终端(我相信“linux”是类似 vt220 的终端 - 无论如何,它可以工作),因此 xterm 无法正常工作。

I am building a terminal window in a browser (sth. like ajaxterm) and don't know which escape sequence to send to ssh tunnel (opened via paramiko.SSHClient().invoke_shell(term='linux')).

I have found a key logger and tried it in a terminal with $TERM == 'linux', but it returns the same sequence for ctrl+left and left (27,91,68).

If I try keylogger in another terminal (with $TERM == 'xterm') I get the codes (27,91,49,59,53,68). But these codes do not move generate the expected output from SSH channel (which would move cursor one word left on a normal linux shell). That is true even if I start paramiko with term='xterm'.

Any idea what sequence I should use? Or why the above sequence doesn't work?

UPDATE: I would be happy to use another terminal type (not "linux"), but unfortunately pyte works with VTxxx terminals only (I believe "linux" is vt220-like terminal - anyway, it works), so xterm doesn't work properly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

つ可否回来 2024-12-16 17:43:55

终端是由键盘和输出设备(最初是硬拷贝打印机,后来是 CRT 显示器)组成的硬件设备。一台大型计算机可以连接多个远程终端。每个终端都有一个用于与计算机有效通信的协议,对于基于 CRT 的终端,这包括具有特殊的“控制序列”来更改光标位置、擦除当前行/屏幕的部分、切换到备用全屏模式等。 ..

终端模拟器是模拟那些旧终端之一的应用程序。它允许执行诸如光标定位、设置前景色和背景色等功能……终端仿真器尝试模拟某些特定的终端协议,但每个协议都有自己的一组怪癖和偏差。

Unix 系统具有描述终端和终端仿真器的数据库,因此应用程序是从使用的特定终端(或终端仿真器)中抽象出来的。较旧的数据库是 termcap(5),而 terminfo(5) 是较新的数据库。这些数据库允许应用程序查询正在使用的终端的功能。功能可以是布尔值、数字功能,甚至是字符串功能,例如:如果特定终端类型具有/支持 F12 键,则它将具有功能“key_f12”(长期信息名称)、“kf12”(短期信息名称)、 “F2”(术语名称)描述键生成的字符串。尝试使用:tput kf12 | od-tx1。

由于直接使用功能进行编程可能会很麻烦,因此应用程序通常使用更高级别的库,例如curses/ncurses、slang等...

有一个名为TERM的特殊环境变量,它告诉应用程序它们的终端类型正在交谈。如果数据库中存在该变量,则应将该变量设置为确切的终端类型,以获得最佳结果。这只是告诉应用程序终端理解哪些精确协议和协议偏差。更改TERM变量不会更改终端类型,它只是更改应用程序认为正在与之通信的终端类型。

尽管如此,Ctrl+arrow 是一种 xterm 行为(取决于配置选项),根本没有反映在 terminfo/termcap 数据库中,因此大多数应用程序对此一无所知。无论哪种方式,您的终端模拟器(在您的情况下pyte)要么支持它,要么不支持。

假设您的主应用程序是 bash 或其他使用 readline 库的应用程序,您可以使用 readline 的 backward-word (Meta- b/Alt-b/ESC b 默认情况下,可在 inputrc 中配置)。

Terminals were hardware devices that consisted of a keyboard and an output device (initially a hardcopy printer, later a CRT monitor). A large computer could have several remote terminals connected to it. Each terminal would have a protocol for communicating efficiently with the computer, for CRT-based terminals this includes having special "control sequences" to change cursor position, erase parts of the current line/screen, switch to an alternate full-screen mode, ...

A terminal emulator is an application emulating one of those older terminals. It allows to do functions like cursor positioning, setting foreground and background colors, ... Terminal emulators try to emulate some specific terminal protocol, but each has its own set of quirks and deviations.

Unix systems have databases describing terminals and terminal emulators, so applications are abstracted away from the particular terminal (or terminal emulator) in use. An older database is termcap(5), while terminfo(5) is a newer database. These databases allow applications to query for the capabilities of the terminal in use. Capabilities can be booleans, numeric capabilities, or even string capabilities, e.g.: if a specific terminal type has/supports a F12 key, it will have a capability "key_f12" (long terminfo name), "kf12" (short terminfo name), "F2" (termcap name) describing the string that key produces. Try it with: tput kf12 | od -tx1.

Since programming directly with capabilities can be cumbersome, applications typically use a higher-level library like curses/ncurses, slang, etc...

There is a special environment variable called TERM that tells applications what terminal type they are talking to. This variable should be set to the exact terminal type if it exists in the database, for best results. This just tells the application which precise protocol and protocol deviations does the terminal understand. Changing the TERM variable does not change the terminal type, it just changes the terminal type the application thinks it is talking to.

All that said, Ctrl+arrow is a xterm behaviour (dependent on a configuration option) that is not reflected at all in the terminfo/termcap databases, so most applications will have no knowledge of it. Either way, either your terminal emulator (in your case pyte) supports it or it doesn't.

Assuming your main application is bash or some other application that uses the readline library, you may get away with using readline's backward-word (Meta-b/Alt-b/ESC b by default, configurable in inputrc) instead.

南城旧梦 2024-12-16 17:43:55

使用 od -c 进行快速检查可以发现 gnome-terminal 生成了这些值:

左箭头生成 ESC-[-D< /代码>。

Control-left-array 生成 ESC-[-1-;-5 -D

A quick check with od -c reveals that gnome-termainal generates these values:

Left-arrow generates ESC-[-D.

Control-left-array geneates ESC-[-1-;-5-D

睫毛上残留的泪 2024-12-16 17:43:55

Ctrl+箭头键码是由 xterm 引入的,Gnome Terminal 和 KDE Konsole 等都尝试与 xterm 兼容。实际的 VT100 和 VT220 终端没有针对此类组合的单独键码。据我所知,Linux 控制台的目标是与 VT100 兼容,并添加了一些内容,而 xterm 则模拟 VT220,并添加了很多内容。

The Ctrl+arrow keycodes were introduced by xterm, and the likes of Gnome Terminal and KDE Konsole try to be compatible with xterm. Actual VT100 and VT220 terminals did not have separate keycodes for such combinations. As far as I know, the Linux console aims to be compatible with the VT100, with some additions, whereas xterm emulates the VT220, with lots of additions.

苏璃陌 2024-12-16 17:43:55

只是为了澄清 Rob 的答案(并注意 Thomas Dickey 对错误问题的观察):使用 od -c 虽然是一个非常方便的工具,但仅在控制序列引入器 (CSI) 时给出结果,其中是 ; [,有效,并且光标键未处于应用程序模式(或者就此而言,可能是其他键),并且正在使用 G3 字符集 (SS3) 的单移选择(即介绍符是O)。而且,即使在应用程序模式下,某些键(例如 PgUp、PgDn、Ins、Del、某些功能键)始终使用 CSI,而不是 SS3。要获得真正好的“概述”(比这多一点!),请查看 Thomas Dickey 的页面 XTerm 控制序列
(并且,为了进一步澄清一点,除了光标键切换到应用程序模式(通过 CSI ? 1 h)之外,数字键盘也可以切换到应用程序模式(通过 CSI =))。

Just to clarify Rob's answer (and noting Thomas Dickey's observation against the question about errors): using od -c, whilst being a very handy tool, only gives results when the Control Sequence Introducer (CSI), which is <esc> [, is in effect and the Cursor Keys are not in Application mode (or, for that matter, potentially other keys) and the Single Shift Select of G3 Character Set (SS3) is in use (that is, the introducer is <esc> O). And, even in application mode, some keys (e.g. PgUp, PgDn, Ins, Del, some function keys) always use the CSI, not SS3. For a really good 'overview' (it's a bit more than that!), check out Thomas Dickey's page on XTerm Control Sequences.
(And, just to clarify a little further, in addition to the Cursor Keys switching to Application Mode (via CSI ? 1 h), the numeric keypad can also be switched to Application mode (via CSI =)).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文