哪个$ TERM用于在python curses中同时拥有256种颜色和鼠标移动事件?

时间:2015-03-12 21:34:15

标签: python ncurses curses xterm python-curses

目前,如果我将TERM环境变量设置为' xterm-1003'我可以获得鼠标移动事件,但我得到糟糕的颜色和curses.can_change_color()==错误

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()==是的,但是除非我点击一个按钮,否则我不会收到鼠标事件!

>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值或其他方式来获取它们?

谢谢!

1 个答案:

答案 0 :(得分:6)

您可以使用infocmp(显示条目的内容)和tic(编译条目)自行创建。如果您没有在系统区域中写入的权限,则会转到$ HOME / .terminfo

首先比较xterm-1003xterm-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.

基本上,您感兴趣的是将XM功能添加到xterm-256color的副本。

因此...

  1. infocmp -x xterm-256color >foo
  2. 修改foo,添加XM字符串
  3. tic -x foo
  4. tic需要使用“-x”选项来编译XM功能,这是扩展(用户定义)功能,ncurses恰好识别为在terminal database的评论中注明。