我用這個小編輯我的項目的基礎上,我做的:https://github.com/antirez/kilo當退出終端rawmode我的內容停留在屏幕
編輯器使用的終端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 to NL, no parity check, no strip char,
* * no start/stop output control. */
raw.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
// output modes - disable post processing
raw.c_oflag &= ~(OPOST);
//control modes - set 8 bit chars
raw.c_cflag |= (CS8);
//local modes, choing off, canonical off, no extended functions, no signal chars (, etc)
raw.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);
//control chars - set return condition: min number of bytes and a timer
raw.c_cc[VMIN] = 0; // return each byte, or zero for a timeout
raw.c_cc[VTIME] = 1; //100ms timeout
//put terminal in raw mode after flushing
if(tcsetattr(fd, TCSAFLUSH, &raw) < 0) goto fatal;
Editor.rawmode = 1;
return 0;
fatal:
errno = ENOTTY;
return -1;
}
據我瞭解,當程序退出atexit(editor_at_exit)
函數被調用,並在該函數的原始模式被禁用。我錯過了將終端打掃回到編輯器打開之前的狀態。我不是隻看整個終端的clear
。
這也許https://www.gnu.org/software/screen /manual/screen.html#Copy –
除了清除屏幕外,還有什麼不重新設置?你正在用原始終端設置做一個'tcsetattr' - 這是行不通的嗎? –
@ChrisTurner讓編輯器的全屏模式在退出後保持不變,即使我使用'tcsetattr'和'&orig_termios'。 –