gpt4 book ai didi

ncurses - 如何在终端/terminfo 条目中实现适当的鼠标支持?

转载 作者:行者123 更新时间:2023-12-02 04:09:15 30 4
gpt4 key购买 nike

我已经实现了一个终端模拟器和相应的 terminfo 条目,它允许我运行 ncurses 程序,例如 emacsmc(午夜指挥官) ) 或 tig (git 浏览器)。我想向终端添加鼠标支持,最值得注意的是通过单击窗口将光标定位在emacs中。经过大量谷歌搜索和 stackoverflow 上的一些帮助后,我了解了所需的 terminfo 字段(最著名的是 kmous)和控制(例如 \E[?1000h)和“key” (\E[M...) 在我的终端中排序并实现鼠标按钮事件。我编写了一个小型 ncurses 程序,其内容如下:

initscr ();
clear ();
noecho ();
cbreak ();

keypad (stdscr, TRUE);

mousemask (ALL_MOUSE_EVENT, NULL);

if (has_mouse ())
{
while (1)
{
switch (getch ())
{
case KEY_MOUSE:
if (getmouse (&event) == OK)
{
printf ("mouse event 0x%x at %i,%i\n", event.bstate, event.x, event.y);

这个程序在xterm和我的终端上运行良好,所以我的终端及其terminfo条目不可能完全错误。

但是,mc 似乎无法识别我的终端中的鼠标支持,甚至没有发出任何 \E[?1000h 序列来激活它,因此完全被我的终端发送的鼠标按钮事件(即使没有 \E[?1000h 激活)。

我错过了什么?

最佳答案

最近有人指出了这个问题(虽然没有提到这个问题):

20181124

    + modify the initialization checks for mouse so that the xterm+sm+1006
block will work with terminal descriptions not mentioning xterm
(report by Tomas Janousek).

问题在于,如果 TERM 具有“xterm”,代码将使用 kmous 功能,否则将默认使用原始的 xterm 鼠标协议(protocol)(该协议(protocol)没有具有“任何事件”能力)。由于惯性(人们将“xterm”终端描述与其他终端一起使用),这一点可能被忽视了很长一段时间。

ncurses manual page确实说出了意图:

Because there are no standard terminal responses that would serve to identify terminals which support the xterm mouse protocol, ncurses assumes that if your $TERM environment variable contains "xterm", or kmous is defined in the terminal description, then the terminal may send mouse events.

关于ncurses - 如何在终端/terminfo 条目中实现适当的鼠标支持?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20105402/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com