Add readline capability to existing interactive program

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jacob Rael

    #1

    Add readline capability to existing interactive program

    Hello,

    I use an interactive simulator/data plotter called ocean. I get really
    frustrated using it because it does not have basic readline
    capabilities like ctrl-a for beginning of line and ctrl-k to kill the
    rest of the line.

    I was thinking this might be easy to add with Python. Do something
    like start python and then kick off the ocean job and then use
    something like pexpect to interact with it. I think this would work
    but there may be an even easier way to do it, maybe directly with
    popen2.

    A quick google search lead me to:



    and shows code:

    import os
    f=os.popen('gnu plot', 'w')
    print >>f, "set yrange[-300:+300]"
    for n in range(300):
    print >>f, "plot %i*cos(x)+%i*lo g(x+10)" % (n,150-n)
    f.flush()


    this kind of works but not quite. Windows don't pop open and results
    of calculations (3+3) don't echo back.

    Before I started coding, I thought I would ask if a module or examples
    already exits that do what I want.

    jr

  • Kushal Kumaran

    #2
    Re: Add readline capability to existing interactive program [OT]


    Jacob Rael wrote:
    Hello,
    >
    I use an interactive simulator/data plotter called ocean. I get really
    frustrated using it because it does not have basic readline
    capabilities like ctrl-a for beginning of line and ctrl-k to kill the
    rest of the line.
    >
    I guess the easiest way would be this: http://freshmeat.net/projects/rlwrap/.
    If you use Microsoft Windows, a cygwin version is available too,
    apparently.
    <snipped>
    --
    Kushal Kumaran

    Comment

    Working...