【问题标题】:VT Terminal - Disable local editing and echoVT 终端 - 禁用本地编辑和回显
【发布时间】:2011-02-10 22:21:52
【问题描述】:

我正在编写一个应该在 VT 兼容的数据收集器中运行的控制台应用程序。 在尝试了一些模拟器后,我发现它们有不同的标准行为。

我担心的是大多数模拟器都有本地数据缓冲区,并在我按下返回时将其发送到服务器。它允许我编辑输入文本。

这个功能对我不好,因为用户可能会弄​​乱屏幕布局。

哪些转义码可以禁用字符的本地回显(让服务器将它们发送回来),并设置终端立即向服务器发送数据而不等待RETURN键?

谢谢

【问题讨论】:

    标签: console ansi vt100


    【解决方案1】:

    在本地缓存数据的特性称为规范化。要禁用它(以及回声),请执行以下操作:

    #include <string.h> /* for memcpy() */
    #include <termios.h>
    
    struct termios term_stored;
    struct termios term_new;
    tcgetattr(0,&term_old);
    memcpy(&term_new,&term_stored,sizeof(struct termios));
    term_new.c_lflag &= ~(ECHO|ICANON); /* disable echo and canonization */
    tcsetattr(0,TCSANOW,&term_new);
    
    /* your code */
    
    tcsetattr(0,TCSANOW,&term_stored); /* restore the original state */
    

    或者,考虑使用libeditncurses 或 readline。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-10
      • 1970-01-01
      • 1970-01-01
      • 2012-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多