【问题标题】:ncurses and key codes after forkfork 后的 ncurses 和关键代码
【发布时间】:2022-12-03 09:47:04
【问题描述】:

我不明白为什么在 WINDOW 中分叉后箭头键代码会发生变化。 向上箭头返回 259,但在分叉之后返回 65。 如果我在 stdscr 上运行相同的程序,它会在开头返回 65。 感谢您的帮助,对英语(由谷歌翻译)感到抱歉。

`

#include <curses.h>
#include <sys/ioctl.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdlib.h>

void openVim() {
pid_t pid = fork();
    if (pid < 0) {}
    else if (pid == 0) {
        execl("/usr/bin/vim", "/usr/bin/vim", NULL);
        exit(0);
    }
    else {
        wait(NULL);
    }

}

int main() {
    initscr();
    noecho();
    int ch = 0;
    WINDOW* mainWin = newwin(10,10,0,0);
    keypad(mainWin, TRUE);
    while ((ch = wgetch(mainWin)) != 'q') {
        wclear(mainWin);
        if (ch == 'V') openVim();
        else
        mvwprintw(mainWin, 0, 0, "%i - %c", ch, ch);
        wrefresh(mainWin);
    }
    delwin(mainWin);
    endwin();
    return 0;
}

`

我注意到如果我在 fork 中放置一个简单的 for 循环,它就不会发生。它可能与execl有关?

【问题讨论】:

    标签: ncurses execl


    【解决方案1】:

    vim 重置终端 I/O 模式;您的程序没有考虑到这一点(请参阅reset_prog_modereset_shell_mode)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-03
      • 1970-01-01
      • 2016-07-19
      • 1970-01-01
      相关资源
      最近更新 更多