ncurses到外部外壳,并弄乱了按键 [英] ncurses to external shell and back messing with keys

查看:80
本文介绍了ncurses到外部外壳,并弄乱了按键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个ncurses应用程序,它正在为 暂时退出ncurses,运行外部 编辑器/shell/任何东西,然后在完成后返回到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.

除了ncurses的前几个按键外,这几乎可以正常工作 事后显然是假的; ncurses认为^ [和A被看见 如果我按两次向上箭头分别.

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.

任何人以前都曾见过这种行为,并且知道要解决什么魔咒 这是?如果有帮助,那就是Ruby ncurses库.

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.

推荐答案

经过一番摸索,我找到了一种货神教徒的解决方案:脱掉stdscr上的外壳后,显式调用keyboard(1).我不知道为什么这行得通,但是行得通.如果其他人可以解释原因,我会标记为是". 当前的工作原理是键盘触摸某种内部缓冲区并清除它.

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.

从头开始:

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);
}

这篇关于ncurses到外部外壳,并弄乱了按键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆