Render colored text to a ncurses window in python -


is possible to/how rendered pre-terminal-formatted colored text curses.window in python?

basically, i'm trying add simple curses-based ui stuff on top of existing console application renders colored log output, i'm trying redirect curses window.

however, seems curses somehow turns off various control codes control color.

here's minimal script, using colorama stand-in text-source:

import colorama import curses  def run_gui():     stdscr = curses.initscr()     curses.start_color()     curses.use_default_colors()      stdscr.insertln()     stdscr.insertln()     stdscr.insstr(colorama.fore.red+'wattt'+colorama.style.reset_all)     stdscr.insertln()     stdscr.insstr(colorama.fore.green+'wattt'+colorama.style.reset_all)     stdscr.insertln()     stdscr.insstr(colorama.fore.yellow+'wattt'+colorama.style.reset_all)     stdscr.insertln()     stdscr.refresh()  if __name__ == '__main__':      run_gui() 

this renders:

^[[33mwattt^[[0m ^[[32mwattt^[[0m ^[[31mwattt^[[0m 

is there way can tell curses allow normal control codes, or going have rework existing color functionality?

short: latter ("rework").

long:

the "normal control codes" happen device-dependent; curses provides device-independent interface terminals. quoting manual page:

the ncurses library routines give user terminal-independent method of updating character screens reasonable optimization.

actually curses implementations provide low-level interface via terminfo-based functions let special tweaks, but

  • python's binding doesn't include (it covers part of ncurses), and
  • for sort of thing suggested, not useful, since manipulating information curses designed know how manage more efficiently program do. preventing knowing what's on screen interfere curses does.

the python documentation mentions attributes, e.g., in window.insstr(str[, attr])

your example like

stdscr.insstr("wattt", color_pair(color_red)) 

what you're asking has been asked before. example:


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -