curses

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

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

為{幸葍}努か 提交于 2020-04-06 08:09:18
问题 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

stdscr.getstr() ignore keys, just string

血红的双手。 提交于 2020-03-06 09:20:47
问题 I just need convert entered text(bytes) to string. But if i on cyrillic press Backspace and some character, python throw me this error: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd0 in position 10: invalid continuation byte What i can do? # -*- coding: utf-8 -*- from re import sub import curses chatting = True cols = 0 lines = 0 def get_msg(stdscr): str_text = "" while chatting: inpwin = curses.newwin(2, 30, 1, 0) text = inpwin.getstr() str_text = str(text, "utf-8") # this string

stdscr.getstr() ignore keys, just string

廉价感情. 提交于 2020-03-06 09:20:46
问题 I just need convert entered text(bytes) to string. But if i on cyrillic press Backspace and some character, python throw me this error: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd0 in position 10: invalid continuation byte What i can do? # -*- coding: utf-8 -*- from re import sub import curses chatting = True cols = 0 lines = 0 def get_msg(stdscr): str_text = "" while chatting: inpwin = curses.newwin(2, 30, 1, 0) text = inpwin.getstr() str_text = str(text, "utf-8") # this string

python标准库简介

不羁的心 提交于 2020-02-14 20:45:26
python标准库简介 文本 string:通用字符串操作 re:正则表达式操作 difflib:差异计算工具 textwrap:文本填充 unicodedata:Unicode字符数据库 stringprep:互联网字符串准备工具 readline:GNU按行读取接口 rlcompleter:GNU按行读取的实现函数 二进制数据 struct:将字节解析为打包的二进制数据 codecs:注册表与基类的编解码器 数据类型 datetime:基于日期与时间工具 calendar:通用月份函数 collections:容器数据类型 collections.abc:容器虚基类 heapq:堆队列算法 bisect:数组二分算法 array:高效数值数组 weakref:弱引用 types:内置类型的动态创建与命名 copy:浅拷贝与深拷贝 pprint:格式化输出 reprlib:交替repr() 的实现 数学 numbers:数值的虚基类 math:数学函数 cmath:复数的数学函数 decimal:定点数与浮点数计算 fractions:有理数 random:生成伪随机数 函数式编程 itertools:为高效循环生成迭代器 functools:可调用对象上的高阶函数与操作 operator:针对函数的标准操作 文件与目录 os.path:通用路径名控制 fileinput

pdCURSES and addstr compatibility with strings problems

无人久伴 提交于 2020-01-25 18:50:49
问题 Hey so i'm trying to get addstr() in pdCurses to work (windows curses) with the preferred string class so I made the function the following string_to_80char() function, which is supposed to take a string and return an 80 character long char array (the number of characters fit on one line in the console) since this is the only parameter addstr seems to accept... However when running the following code i do get the "Just a string" printed but with a random character like an '@' or '4' like 50