问题
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()
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/
reports
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
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?
Thank you!
回答1:
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
Start by comparing xterm-1003 and 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.
Essentially, all you are interested in is adding the XM
capability to a copy of xterm-256color
.
So...
infocmp -x xterm-256color >foo
- edit
foo
, adding theXM
string tic -x foo
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.
来源:https://stackoverflow.com/questions/29020638/which-term-to-use-to-have-both-256-colors-and-mouse-move-events-in-python-curse