在python curses中使用哪个$ TERM同时具有256色和鼠标移动事件? [英] Which $TERM to use to have both 256 colors and mouse move events in python curses?
问题描述
当前,如果我将TERM环境变量设置为'xterm-1003',我可以得到鼠标移动事件,但是却得到cr脚的颜色和诅咒.can_change_color()== False
Currently if I set the TERM environment variable to 'xterm-1003' I can get mouse move events but I get crappy colors and curses.can_change_color() == False
os.environ['TERM'] = 'xterm-1003'
...
curses.mousemask(curses.ALL_MOUSE_EVENTS | curses.REPORT_MOUSE_POSITION)
...
while True:
event = screen.getch()
if event == curses.KEY_MOUSE:
# I get nice events whenever I move the mouse (no click required)
_, mx, my, _, _ = curses.getmouse()
如果我将TERM env var设置为'xterm-256color',我会得到一个不错的调色板加上curses.can_change_color()== True,但是除非单击按钮,否则我不会收到鼠标事件!
and if I set the TERM env var to 'xterm-256color' I get a nice color palette plus curses.can_change_color() == True, however I do not receive mouse events unless I click a button!
>ls /usr/share/terminfo/x/
报告
xfce xterm-256color xterm-hp xterm-r5 xterm-xf86-v32 xterm-xfree86
xterm xterm-88color xterm-new xterm-r6 xterm-xf86-v33 xterm-xi
xterm-1002 xterm-8bit xterm-nic xterm-sco xterm-xf86-v333 xterms
xterm-1003 xterm-basic xterm-noapp xterm-sun xterm-xf86-v40
xterm-16color xterm-bold xterm-old xterm-vt220 xterm-xf86-v43
xterm-24 xterm-color xterm-pcolor xterm-vt52 xterm-xf86-v44
我尝试过的所有方法似乎都不支持curses.can_change_color()== True和鼠标移动事件.有没有一种方法可以通过设置适当的$ TERM值或其他方法来同时获得它们?
None of the ones I tried seem to support both curses.can_change_color() == True and mouse move events. Is there a way I can get both of them via setting an appropriate $TERM value or some other way?
谢谢!
推荐答案
您始终可以使用 infocmp (以显示条目的内容),以及
You can always make your own, using infocmp (to show the contents of an entry), and tic (to compile an entry). If you do not have permission to write in the system area, it goes to $HOME/.terminfo
首先比较 xterm-1003 和 xterm-256color :
> infocmp -x xterm-1003 xterm-256color
comparing xterm-1003 to xterm-256color.
comparing booleans.
ccc: F:T.
comparing numbers.
colors: 8, 256.
pairs: 64, 32767.
comparing strings.
initc: NULL, '\E]4;%p1%d;rgb\:%p2%{255}%*%{1000}%/%2.2X/%p3%{255}%*%{1000}%/%2.2X/%p4%{255}%*%{1000}%/%2.2X\E\\'.
setab: '\E[4%p1%dm', '\E[%?%p1%{8}%<%t4%p1%d%e%p1%{16}%<%t10%p1%{8}%-%d%e48;5;%p1%d%;m'.
setaf: '\E[3%p1%dm', '\E[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;m'.
setb: '\E[4%?%p1%{1}%=%t4%e%p1%{3}%=%t6%e%p1%{4}%=%t1%e%p1%{6}%=%t3%e%p1%d%;m', NULL.
setf: '\E[3%?%p1%{1}%=%t4%e%p1%{3}%=%t6%e%p1%{4}%=%t1%e%p1%{6}%=%t3%e%p1%d%;m', NULL.
XM: '\E[?1003%?%p1%{1}%=%th%el%;', NULL.
基本上,您只需要向xterm-256color
的副本中添加XM
功能即可.
Essentially, all you are interested in is adding the XM
capability to a copy of xterm-256color
.
所以...
-
infocmp -x xterm-256color >foo
- 编辑
foo
,添加XM
字符串 -
tic -x foo
infocmp -x xterm-256color >foo
- edit
foo
, adding theXM
string tic -x foo
tic
需要使用"-x"选项来编译XM
功能,这是扩展(用户定义的)功能,ncurses恰好可以识别注释中指出的功能. 终端数据库.
The "-x" option is needed for tic
to compile the XM
capability, which is an extended (user-defined) capability which ncurses happens to recognize as noted in comments for the terminal database.
这篇关于在python curses中使用哪个$ TERM同时具有256色和鼠标移动事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!