ncurses 到外壳并返回弄乱密钥

发布于 2024-07-27 23:08:44 字数 248 浏览 5 评论 0原文

我有这个 ncurses 应用程序正在执行标准配方 暂时退出 ncurses,运行外部 编辑器/shell/无论什么,然后在完成后返回 ncurses。

这几乎可以工作,除了 ncurses 的前几个按键 之后得到的显然是假的; ncurses 认为 ^[ 和 A 被看到 如果我按向上箭头两次。

任何人以前见过这种行为并且知道要修复什么魔法 这是? 如果有帮助的话,这是 Ruby ncurses 库。

I have this ncurses application that is doing the standard recipe for
temporarily dropping out of ncurses, running an external
editor/shell/whatever, and then dropping back to ncurses when it's done.

This ~almost works, except that the first few keypresses that ncurses
gets afterwards are obviously bogus; ncurses thinks ^[ and A are seen
respectively if I press the up arrow twice.

Anyone seen this behavior before and know what the magic incant to fix
this is? If it helps any, this is the Ruby ncurses library.

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

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

发布评论

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

评论(2

送君千里 2024-08-03 23:08:52

是的。 如果没有键盘,ncurses 将无法为您处理转义码。 来自键盘手册页:

   The keypad option enables the keypad of the user's  terminal.   If  en-
   abled (bf is TRUE), the user can press a function key (such as an arrow
   key) and wgetch returns a single value representing the  function  key,
   as in KEY_LEFT.  If disabled (bf is FALSE), curses does not treat func-
   tion keys specially and the program has to  interpret  the  escape  se-
   quences  itself.   If the keypad in the terminal can be turned on (made
   to transmit) and off (made to work locally),  turning  on  this  option
   causes  the terminal keypad to be turned on when wgetch is called.  The
   default value for keypad is false.

通常,我在 ncurses 程序中做的第一件事是调用 keypad(stdscr, true) 来启用良好的键盘映射。

希望有帮助。

Yeah. Without keypad ncurses won't handle escape codes for you. From the keypad man page:

   The keypad option enables the keypad of the user's  terminal.   If  en-
   abled (bf is TRUE), the user can press a function key (such as an arrow
   key) and wgetch returns a single value representing the  function  key,
   as in KEY_LEFT.  If disabled (bf is FALSE), curses does not treat func-
   tion keys specially and the program has to  interpret  the  escape  se-
   quences  itself.   If the keypad in the terminal can be turned on (made
   to transmit) and off (made to work locally),  turning  on  this  option
   causes  the terminal keypad to be turned on when wgetch is called.  The
   default value for keypad is false.

Often, the first thing I do in an ncurses program is call keypad(stdscr, true) to enable nice keyboard mapping.

Hope that helps.

无力看清 2024-08-03 23:08:50

经过一番研究后,我找到了一个货物崇拜解决方案:在 stdscr 上退出 shell 后显式调用 keypad(1) 。 我不知道为什么会这样,但确实如此。 如果其他人能解释原因,我会将其标记为“是”。 当前的工作原理是键盘接触某种内部缓冲区并将其清除。

简单说一下:

NCURSES_EXPORT(int)
keypad(WINDOW *win, bool flag)
{
    T((T_CALLED("keypad(%p,%d)"), win, flag));

    if (win) {
        win->_use_keypad = flag;
        returnCode(_nc_keypad(SP, flag));
    } else
        returnCode(ERR);
}

After rootling around a bit, I found a cargo culting solution: explicitly call keypad(1) after getting out the shell on stdscr. I have no idea why this works, but it does. I'll mark someone else's answer as yes if they can explain why. The current working theory is that keypad touches some sort of internal buffer and clears it.

Scratch that:

NCURSES_EXPORT(int)
keypad(WINDOW *win, bool flag)
{
    T((T_CALLED("keypad(%p,%d)"), win, flag));

    if (win) {
        win->_use_keypad = flag;
        returnCode(_nc_keypad(SP, flag));
    } else
        returnCode(ERR);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文