'normal' shell with curses

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michael Goerz

    'normal' shell with curses

    Hi,

    I'm trying to print out text in color. As far as I know, curses is the
    only way to do that (or not?). So, what I ultimately want is a curses
    terminal that behaves as closely as possible as a normal terminal, i.e.
    it breaks lines and scrolls automatically, so that I can implement a
    function myprint(color, text) that does what print() does, only in color.

    So, my first tests brought up some problems:

    #!/usr/bin/python

    from time import sleep
    import curses
    import sys

    stdscr = curses.initscr( )
    stdscr.addstr(" Initialized\n")
    stdscr.refresh( )
    (maxlines, maxcolumns) = stdscr.getmaxyx ()
    try:
    for counter in xrange(24):
    stdscr.addstr(" Hello world %s\n" % counter)
    stdscr.refresh( )
    if counter >= maxlines:
    stdscr.scroll()
    stdscr.refresh( )
    except Exception, data:
    sys.stderr.writ e("Exception: \n");
    sys.stderr.writ e(str(data));
    finally:
    sleep(5)
    curses.endwin()

    Instead of scrolling, the program throws an exception. Any hints?

    Also, is there a way leave the curses output on the screen after
    curses.endwin() , instead of returning to the normal terminal without a
    trace of curses.

    Thanks,
    Michael
  • Miki

    #2
    Re: 'normal' shell with curses

    Hello Michael,
    I'm trying to print out text in color. As far as I know, curses is the
    only way to do that (or not?).
    On unix, every XTerm compatible terminal will be able to display color
    using escape sequence.
    (Like the one you see in the output of 'grep --color')

    See the shameless plug in http://pythonwise.blogspot.com/2008/03/ansiprint.html

    HTH,
    --
    Miki <miki.tebeka@gm ail.com>
    If it won't be simple, it simply won't be. [Hire me, source code]



    Comment

    Working...