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 capabilities sgr, sgr0, smso, rmso, rev
  • tparm format parameters sgr if use that
  • putp write strings read/formatted via tigetstr , 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:

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

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -