使用退格与ncurses的 [英] Using backspace with ncurses

查看:123
本文介绍了使用退格与ncurses的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的ncurses程序中设置了读取的人物之一在与残培(),并将它们复制到缓冲区的时候。我遇到的问题是检测退格键的preSS。下面是相关code:

I have a simple ncurses program set up that reads characters one at a time with getch() and copies them into a buffer. The issue I am having is detecting a press of the backspace key. Here is the relevant code:

while((buffer[i] = c = getch()) != EOF) {
    ++i;
    if (c == '\n') {
        break;
    }
    else if (c == KEY_BACKSPACE || c == KEY_DC || c == 127) {
        i--;
        delch();
        buffer[i] = 0;
    }
    refresh();
}

但在尝试运行该code时,这是试图从该行删除字符后,屏幕上显示的内容:这是一个测试:

But when attempting to run this code, this is what appears on the screen after trying to delete characters from the line "this is a test":

this is a test^?^?^?

缓存的内容是:

this is a test

使用gdb的我知道,if语句检查删除/退格被调用,那么还有什么我应该做的事,这样我可以删除字符?

With gdb I know that the if statement checking for a delete/backspace is being called, so what else should I be doing so that I can delete characters?

推荐答案

看起来 ^ 是,当你进入一个DEL性格什么的在屏幕上显示。

It looks like ^? is what's echoed to the screen when you enter a DEL character.

您也许可以称之为 delch()两次,但你必须弄清楚哪些字符作为呼应两个字符(或更多)的序列。

You could probably call delch() twice, but then you'd have to figure out which characters echo as two-character (or more) sequences.

您最好的选择可能是叫 NOECHO(),并明确自己打印的字符。

Your best bet is probably to call noecho() and explicitly print the characters yourself.

这篇关于使用退格与ncurses的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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