我用这个小编辑器作为我正在做的项目的基础:https://github.com/antirez/kilo
编辑器使用rawmode中的终端并使用VT100转义序列进行写入,但是当退出程序时,显示的内容将保持显示状态.在退出之前......

正如您所看到的那样,提示再次出现,但编辑器剩下的内容一直保留到那里直到写完为止.
// Low level terminal handling
void disable_raw_mode(int fd)
{
// dont bother checking the return value as its too late
if (Editor.rawmode) {
tcsetattr(fd, TCSAFLUSH, &orig_termios);
Editor.rawmode = 0;
}
}
void editor_at_exit(void)
{
disable_raw_mode(STDIN_FILENO);
}
int enable_raw_mode(int fd)
{
struct termios raw;
if(Editor.rawmode) return 0; //already enabled
if(!isatty(STDIN_FILENO)) goto fatal;
atexit(editor_at_exit);
if(tcgetattr(fd, &orig_termios) == -1) goto fatal;
raw = orig_termios; // modify the original mode
/* input modes: no break, no CR …Run Code Online (Sandbox Code Playgroud)