终端仿真器中的鼠标事件

Mouse events in terminal emulator

问题

是否可以在终端仿真器中,在鼠标事件发生时 运行 命令?

我试过的

我想我已经完成了一半 - 使用 echo -e "\e[?1003h"(有关详细信息,请参阅 here)并在终端上挥动鼠标会产生打印一堆字符的理想效果,与发生的鼠标事件。 (注意:echo -e "\e[?1003l" 关闭此功能)

echo -e "\e[?1003h"
# move mouse over terminal window, in the character input line, NOT to stdout:
> CF*CC+C@,C;.C:/C8/C8/C8/C8/C9/C9/C9/C90C90C80C81C81C81C81C81C90C:/C;/C;.C<.C<.

# After deleting that, I enter:
> echo -e "\e[?1003l"
# mouse move, all is quiet

我也试过将它连接起来输出到一个文件。这是为了看看我是否可以根据该文件和 运行 命令查看文件。过程如下:

> echo -e "\e[?1003h" >> file.txt 
# elevator music whilst I move the mouse about

> echo -e "\e[?1003l"
# move mouse a bit, nothing

> cat file.txt


# nothing but blank lines, fair enough. But, mouse moves and in the terminal input is printed...

> CF*CC+C@,C;.C:/C8/C8/C8/C8/C9/C9/C9/C90C90C8 ...

#  Delete that output, and then I type:
> echo -e "\e[?1003l"
# mouse moves, no output

我想要的

我如何才能捕获此输出以便将其传送到 stdout 或文件,以便我可以使用不断变化的输出来触发 运行 命令?如果那不可能,是否有其他方法可以在终端仿真器中使用事件坐标捕获鼠标单击事件?

不是输出,是输入。

bash 中有多种读取输入的方法。这是一个读取所有内容直到停止的方法:

echo -e "\e[?1003h"    
echo "Press enter and then ctrl-d to stop reading"
cat > myfile

完成并使用 Enter 和 Ctrl+D 正确退出后,您可以检查 myfile 以查看所有鼠标事件。

正确的鼠标应用程序会在从终端读取和解码转义序列之前禁用本地回显和终端缓冲。