curses - Display inverse video text with python on terminal -
python has curses
module. there simple way use module display inverse video text? don't want full-blown curses application, want text bring inverse (or in color).
if use filter
function (before initscr
), curses application update current line of screen (and not clear whole screen). minimal use of curses library.
if want lower-level (no optimization, yourself), have use terminfo level of library, i.e., these functions:
initscr
filter
(since python curses apparently has no interface newterm)tigetstr
read capabilitiessgr
,sgr0
,smso
,rmso
,rev
tparm
format parameterssgr
if use thatputp
write strings read/formatted viatigetstr
,tparm
the page python curses.tigetstr examples has (mostly incomplete) examples using tigetstr
, , reminds me use setupterm
alternative newterm
. if visit page searching "curses.filter", asserts there examples of use, reading, found nothing report.
further reading:
- complete as-you-type on command line python (shows
filter
in use)
a demo reverse-video:
import curses curses.filter() stdscr = curses.initscr() stdscr.addstr("normal-") stdscr.addstr("hello world!", curses.a_reverse) stdscr.addstr("-normal") stdscr.refresh() curses.endwin() print
or
import curses curses.setupterm() curses.putp("normal-") curses.putp(curses.tigetstr("rev")) curses.putp("hello world!") curses.putp(curses.tigetstr("sgr0")) curses.putp("-normal")
illustrates point: text written curses.putp
bypasses curses library optimization. use initscr
or newterm
use curses screen-optimization, setupterm
not use it, using low-level capability- , output-functions.
Comments
Post a Comment