python-curses

Is there a list of ANSI color escape codes somewhere in the standard libraries?

寵の児 提交于 2021-01-27 17:50:35
问题 I write a lot of little helper scripts, and often these print coloured text in the terminal. For the simplicity of their packaging and distribution, I often want these little scripts to be without any dependencies. Hence I'm duplicating data like this a lot in scripts: ansi_colors = { None: '\x1b[0m', # actually black but whatevs 'red': '\x1b[31m', 'green' : '\x1b[32m', ... } Does this data exist anywhere in the core libraries? I dug around and found that curses has some COLOR_* constants,

N-curses within Python : how to catch and print non ascii character?

妖精的绣舞 提交于 2020-07-09 19:56:07
问题 I want to make a small program with ncurses/python and to be able to use/type in french and japanese. I understand that I should set the locale and use unicode standard. But how to deal with the result from screen.getch() ? I would like to display the typed character within the ncurses window regardless of the language. I understand that some unicode conversion is necessary but can't find what to do (and i've searched quite a bit : this character conversion bussiness isnt easy to understand

N-curses within Python : how to catch and print non ascii character?

我的未来我决定 提交于 2020-07-09 19:54:23
问题 I want to make a small program with ncurses/python and to be able to use/type in french and japanese. I understand that I should set the locale and use unicode standard. But how to deal with the result from screen.getch() ? I would like to display the typed character within the ncurses window regardless of the language. I understand that some unicode conversion is necessary but can't find what to do (and i've searched quite a bit : this character conversion bussiness isnt easy to understand

How to display pre-colored string with curses?

人走茶凉 提交于 2020-05-27 05:09:41
问题 I'm writing a curses program in Python. I'm a beginner of curses but I've used terminal control sequences for colored output. Now there's some code snippets to print inside the window, I'd like them be syntax highlighted, and it's better done with libraries like pygments, which outputs highlighted code with control sequences. Initially I feed pygments output directly to window.addstr() , but it is turned out that the control sequences is escaped and the whole highlighted string is printed on

How to display pre-colored string with curses?

廉价感情. 提交于 2020-05-27 05:08:22
问题 I'm writing a curses program in Python. I'm a beginner of curses but I've used terminal control sequences for colored output. Now there's some code snippets to print inside the window, I'd like them be syntax highlighted, and it's better done with libraries like pygments, which outputs highlighted code with control sequences. Initially I feed pygments output directly to window.addstr() , but it is turned out that the control sequences is escaped and the whole highlighted string is printed on

How to display pre-colored string with curses?

廉价感情. 提交于 2020-05-27 05:08:11
问题 I'm writing a curses program in Python. I'm a beginner of curses but I've used terminal control sequences for colored output. Now there's some code snippets to print inside the window, I'd like them be syntax highlighted, and it's better done with libraries like pygments, which outputs highlighted code with control sequences. Initially I feed pygments output directly to window.addstr() , but it is turned out that the control sequences is escaped and the whole highlighted string is printed on

Why doesn't the window update in curses?

折月煮酒 提交于 2020-05-17 07:45:10
问题 I took this nice example of a simple curses application with a list. I wanted to make it scrollable, so I changed the part of the list that gets shown. However, I can scroll down and back up, but the contents shown doesn't change (only the highlighted line, not the lines shown). What am I doing wrong? MVCE #!/usr/bin/env python import curses from curses import panel class Menu(object): def __init__(self, items, stdscreen): self.window = stdscreen.subwin(0, 0) self.window.keypad(1) self.panel

Why doesn't the window update in curses?

主宰稳场 提交于 2020-05-17 07:45:06
问题 I took this nice example of a simple curses application with a list. I wanted to make it scrollable, so I changed the part of the list that gets shown. However, I can scroll down and back up, but the contents shown doesn't change (only the highlighted line, not the lines shown). What am I doing wrong? MVCE #!/usr/bin/env python import curses from curses import panel class Menu(object): def __init__(self, items, stdscreen): self.window = stdscreen.subwin(0, 0) self.window.keypad(1) self.panel

Which $TERM to use to have both 256 colors and mouse move events in python curses?

烂漫一生 提交于 2020-04-06 08:09:19
问题 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