Ncurses 在第 94 列之后不报告鼠标移动

Ncurses not reporting mouse movements after columns 94

通过以下示例,我可以获取终端内的鼠标位置,直到第 94 列。限制在哪里?

#include <curses.h>

int main()
{
    initscr();
    cbreak();
    noecho();

    keypad(stdscr, TRUE);
    mousemask(ALL_MOUSE_EVENTS, NULL);

    MEVENT event;
    for (;;)
        if (wgetch(stdscr) == KEY_MOUSE && getmouse(&event) == OK)
            mvprintw(0, 0, "Mouse at row=%03d and column=%03d", event.y, event.x);
}

测试时间:

但它正在工作:

我错过了什么?

在所有终端中,通过 echo -e "\e[?1000;1006;1015h" 手动启用鼠标报告,我得到了相同的结果。所以 Ncurses 似乎在使用其他东西...

ncurses 使用终端描述来判断终端是否支持 xterm 的 1006 mouse-mode. It looks at the XM flag (see user_caps(5)):

The XM capability has a single parameter. If nonzero, the mouse protocol should be enabled. If zero, the mouse protocol should be disabled. ncurses inspects this capability if it is present, to see whether the 1006 protocol is used. If so, it expects the responses to use the SGR 1006 xterm mouse protocol.

要查看该标志,您可以使用 infocmp,例如,

infocmp -1x |grep XM,

看看有没有定义。对于 mintty,您可能会看到:

$ infocmp -1x mintty | grep XM
        XM=\E[?1006;1000%?%p1%{1}%=%th%el%;,

对于其他人,了解 TERM 设置的内容会有所帮助(还有 ncurses 的版本,因为它 could 太旧了)。

问题中的 1015 带有注释:这是一个 rxvt-unicode 功能,Windows 终端无法识别。 Windows cmd 的文档中也没有提到它。它是在 PuTTY 中实现的(也是 xterm,尽管 PuTTY 的实现与 xterm 不同)。在两个 PuTTY/xterm 中,1006echo 命令中位于 1015 之前将导致这些终端使用 xterm 的 1006(“SGR 模式”),它由 Windows 终端实现。如果您省略了 1006,那么它将不适用于 ncurses,因为协议不同——并且 ncurses 不支持 1015编码.