Curses, Terminal Settings

Discussion in 'Python' started by J Turner, Aug 28, 2003.

  1. J Turner

    J Turner Guest

    Hello,

    I'm playing with a python-based shell, which uses (guess what?) python as
    it's scripting language, for iterative invocation, environment
    variables, etc.

    Everything was going well, until I moved beyond sys.readline() into
    curses territory to flesh out the line-editing capabilities. Curses
    always seems to get me.

    The problem I'm having is described here:

    I call the following things to get the terminal into a the state I want,
    and then back out of it:

    def _pysh_cursesInmode():
    curses.noecho()
    curses.raw()
    stdscr.keypad(1)
    stdscr.idlok(1)
    stdscr.scrollok(1)
    curses.nonl()

    def _pysh_cursesOutmode():
    curses.echo()
    curses.noraw()
    stdscr.keypad(0)
    stdscr.idlok(0)
    stdscr.scrollok(0)
    curses.nl()

    Then, if a line, or an `inline command`, is determined to be a program
    invocation, the shell piggybacks onto bash for forking/exec ing, piping,
    and all that jazz, with a 'bash -noprofile -c "cmd"'.

    When I call out to bash, I obviously want the terminal back in a
    non-curses state. I want to undo *all* the changes so that when bash,
    ls, ps, etc, starts up, the terminal is in a sane state when they write
    to stdout.

    Despite calling the Outmode() function listed above, the terminal is not
    in this state. Newlines don't return the output to position 0, though
    they do advance down a line.

    like
    this

    Here's a real example.

    zsh:
    (10:06:38)jamwt/ % ls
    LICENSE Maildir bin doc lists scrib vault
    Mail att devel etc public tmp web
    (10:06:38)jamwt/ % ls

    bash through python curses:
    $ ls
    LICENSE Maildir bin doc lists scrib vault
    Mail att
    devel etc public tmp web
    $

    .... and something like 'top' looks just terrible.

    I really don't know what else to do besides undo the changes I've made!
    That seems to be what I'm doing with the mode functions above.. what am
    I missing?

    This is the end of the problem description. Thanks.

    Here's a look at the pre-curses shell:

    (10:09:41)jamwt/ % pysh
    $ ls
    LICENSE Maildir bin doc lists scrib vault
    Mail att devel etc public tmp web
    $ for item in `ls`.split("\n"): print item[:3]
    >

    LIC
    Mai
    Mai
    att
    bin
    dev
    doc
    etc
    lis
    pub
    scr
    tmp
    vau
    web

    $ FOO = "bar"
    $ import sys
    $ BAR = sys.version
    $ export FOO
    $ export BAR
    $ env
    FTP_PASSIVE_MODE=YES

    .... etc ..

    BAR=2.3 (#1, Jul 31 2003, 00:45:11)
    [GCC 2.95.4 20020320 [FreeBSD]]

    .... etc ..

    FOO=bar


    - Jamie
     
    J Turner, Aug 28, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Leif B. Kristensen

    Curses and Terminal DEC

    Leif B. Kristensen, Feb 17, 2005, in forum: Python
    Replies:
    0
    Views:
    323
    Leif B. Kristensen
    Feb 17, 2005
  2. Jean-Paul Calderone
    Replies:
    2
    Views:
    465
    Joel Hedlund
    Feb 9, 2006
  3. donet programmer
    Replies:
    3
    Views:
    1,642
    Gregory A. Beamer
    Nov 20, 2009
  4. mix
    Replies:
    4
    Views:
    1,054
    Emile van Sebille
    Oct 30, 2010
  5. Kenneth McDonald
    Replies:
    8
    Views:
    282
    James Gray
    Sep 26, 2008
Loading...

Share This Page