Search code examples
pythonpython-cursescolorama

Use curses with colorama


Is it possible to use curses with colorama? Here is my code, it prints the escape sequences:

from curses import wrapper
import colorama

STYLE = colorama.Fore.GREEN + colorama.Back.BLUE
TITLE = STYLE + 'Current terminal size:'
HEIGHT_STRING = STYLE + 'Screen height: {}\n'
WIDTH_STRING = STYLE + 'Screen width:  {}\n'
STR_LEN = 18


def main(stdscr):

    colorama.init()
    stdscr.clear()

    height, width = stdscr.getmaxyx()
    y = height//2 - 2
    x = width//2 - STR_LEN//2

    stdscr.addstr(y - 2, x, TITLE)
    stdscr.addstr(y, x, HEIGHT_STRING.format(height))
    stdscr.addstr(y + 1, x, WIDTH_STRING.format(width))

    stdscr.refresh()
    stdscr.getkey(y + 2, x)

if __name__ == '__main__':
    wrapper(main)

I know that curses can't be used on Windows, just wondering if this is possible


Solution

  • Given the description of colorama, no (it uses hardcoded escape sequences), doesn't have a method for output in other forms.

    According to the Python documentation, UniCurses should work (on Windows). That's using PDCurses. ncurses itself works for Windows well enough, there being packages for it in MSYS2 and Cygwin.