为什么 irb 将控制字符插入到我的反向交互搜索缓冲区中?

发布于 2024-10-11 13:01:46 字数 415 浏览 2 评论 0原文

如果我在 irb 中进行反向交互式搜索,然后输入控制字符(箭头键是我实际上见过的唯一的)。所以我从这个会话开始:

$ irb
>> print "hello"
hello

然后输入 ^r, h

$ irb
>> print "hello"
hello
(reverse-i-search)`he': print "hello"

到目前为止一切顺利。然后我点击向左箭头,最终得到以下结果:

$ irb
>> print "hello"
hello
>> print "[Dhello"

随后使用箭头将正常移动光标。

If I do a reverse interactive search in irb and then enter a control character (arrow keys are the only ones I've seen this with actually). So I start with this session:

$ irb
>> print "hello"
hello

then enter ^r, h

$ irb
>> print "hello"
hello
(reverse-i-search)`he': print "hello"

So far so good. Then I hit the left arrow, and I end up with this:

$ irb
>> print "hello"
hello
>> print "[Dhello"

Subsequent use of the arrows moves the cursor around normally.

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

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

发布评论

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

评论(2

橪书 2024-10-18 13:01:46

这不会解决您的问题,但至少我可以回答您提出的问题(原因):

左箭头以三个字符 ESC、[ 和 D 的形式输入终端。(您可以通过键入 < 来测试这一点) code>read 并按向左箭头,这会显示 ^[[D,其中 ^[ 是转义字符的呈现方式。)

不知何故 irb 在不应该的情况下拾取了 ESC 字符;因此 ESC 结束历史搜索,并且 [D 按字面意思输入。查看使用 readline 的其他程序,Bash 和 Python 的行为正确,但是 ledit (是的,晦涩难懂 - 抱歉 ^^)也遇到了这个问题。

除非有人知道这个问题的解决方案,否则我能想到的唯一解决方法是按 ESC 而不是箭头键退出历史搜索。当然,如果您不需要进一步编辑,也可以按 Enter 键。

This won't solve your problem, but at least I can answer the question you asked (the Why):

The left arrow gets entered into the terminal as three characters, ESC, [, and D. (You can test this by typing read and pressing the left arrow, which displays ^[[D, where ^[ is how the escape character gets rendered.)

Somehow irb picks up the ESC character when it shouldn't; so ESC ends the history search, and [D gets entered literally. Looking at other programs using readline, Bash and Python behave correctly, but ledit (yeah, obscure -- sorry ^^) is having this problem as well.

Unless someone knows a solution for this, the only workaround I can think of is pressing ESC instead of an arrow key to exit history search. Or hitting enter if you don't need to edit further, of course.

半仙 2024-10-18 13:01:46

您是否启用了 vi 编辑模式?

~  $ irb
1.9.3p392 :001 > Readline.vi_editing_mode?
  => true

我通过 set editor-mode vi 在我的 $HOME/.inputrc 文件中打开了它。禁用它“修复”了我的箭头键。

正如 @JoLiss 提到的,其他 readline 程序(bash 等)也可以正常工作;所以 AFAICT,这是一个 Ruby 问题。请参阅:http://bugs.ruby-lang.org/issues/7859#change -36333

Do you have vi editing mode enabled?

~  $ irb
1.9.3p392 :001 > Readline.vi_editing_mode?
  => true

I had it turned on in my $HOME/.inputrc file via set editing-mode vi. Disabling it "fixed" my arrow-keys.

As mentioned by @JoLiss, other readline programs (bash, etc.) were also working correctly; so AFAICT, it's a Ruby problem. See: http://bugs.ruby-lang.org/issues/7859#change-36333

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