问题
在终端模拟器中,是否可以在发生 mosue 事件时运行命令?
我尝试过什么
我想我已经完成了一半 - 使用echo -e "e[?1003h"
(有关详细信息,请参阅此处(并在终端上挥动鼠标会产生打印一堆与发生的鼠标事件相关的字符的理想效果。(注意: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
以查看所有鼠标事件。
正确的鼠标应用程序会在从终端读取和解码转义序列之前禁用本地回显和终端缓冲。