开发者

VT Terminal - Disable local editing and echo

开发者 https://www.devze.com 2023-02-09 16:36 出处:网络
开发者_运维知识库I am writing a console application that should run in VT compatible data collectors.
开发者_运维知识库

I am writing a console application that should run in VT compatible data collectors. After trying some emulators i found they have a different standard behavior.

My concern is that most of the emulators has local buffer of data and sends it to the server when i press return. It allows me to edit the inputing text.

This feature isn't good for me because the user could mess the screen layout.

What are the escape codes to disable local echoing of characters (let the server send them back), and to set terminal to send data imediately to the server without waiting for RETURN key?

Thank you


The feature of buffering data locally is called canonization. To disable it (as well as echo) do:

#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 */

Or, consider using libedit, ncurses or readline.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号