Results 1 to 5 of 5

Thread: [Curses][Python] Typed text in terminal is invisible _after running program_

  1. #1
    Join Date
    Jun 2008
    Location
    Narnia
    Beans
    784
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    [Curses][Python] Typed text in terminal is invisible _after running program_

    Hello,
    Today I learned about curses--and found this tutorial.
    To make sure I was doing things right, I made a simple Hello World! script:
    PHP Code:
    import curses as c
    stdscr 
    c.initscr()
    c.noecho()
    c.cbreak()
    stdscr.keypad(1)
    stdscr.addstr("Hello World!\n")
    stdscr.refresh()

    c.nocbreak(); stdscr.keypad(0); c.echo() #To return terminal back to normal 
    Which outputs:
    Code:
    Hello World!
    timmy@Stanway01:~$
    And then I can use my terminal like normal--except I can't see anything I type in. For example:
    Code:
    Hello World!
    timmy@Stanway01:~$ Python 2.5.2 (r252:60911, Oct  5 2008, 19:24:49) 
                                                                        [GCC 4.3.2] on linux2
             Type "help", "copyright", "credits" or "license" for more information.
                                                                                   >>> timmy@Stanway01:~$
    I typed in python, and then exit(). And yes, it did that spacing.

    How do I solve this? Thank you.
    Last edited by fiddler616; March 6th, 2009 at 02:47 AM. Reason: Terminal output doesn't mix well with [PHP] tags
    Blog
    #!
    Chan eil mi a Gàidhlig agam...pero si hablo español: soy catracho.
    Proud to be a Browncoat!

  2. #2
    Join Date
    Mar 2005
    Beans
    947
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: [Curses][Python] Typed text in terminal is invisible _after running program_

    You need to call endwin() when you're done, before exiting the program. Your last line is nonsense; replace it with "c.endwin()".

    Of course, this will clear the screen. To avoid that, insert a getch() before the endwin(). The screen will still be cleared, but at least you'll get a chance to read it. If you want to put up output that will remain when you exit the program, then curses isn't really what you want.

    Meanwhile, if your program does exit without calling endwin(), you can run "reset" on the command line to restore the terminal state.
    Last edited by wmcbrine; March 6th, 2009 at 05:14 AM.

  3. #3
    Join Date
    Jun 2008
    Location
    Narnia
    Beans
    784
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: [Curses][Python] Typed text in terminal is invisible _after running program_

    Hmm...getch() and curses.getch() both raise error. curses.endwin() works though--thanks! (Although you're right--it does whizz by the screen)
    Blog
    #!
    Chan eil mi a Gàidhlig agam...pero si hablo español: soy catracho.
    Proud to be a Browncoat!

  4. #4
    Join Date
    Mar 2005
    Beans
    947
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: [Curses][Python] Typed text in terminal is invisible _after running program_

    In Python, getch() is a window method: stdscr.getch()

  5. #5
    Join Date
    Jun 2008
    Location
    Narnia
    Beans
    784
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: [Curses][Python] Typed text in terminal is invisible _after running program_

    Quote Originally Posted by wmcbrine View Post
    In Python, getch() is a window method: stdscr.getch()
    Ah, that'll do it.

    Thanks a lot!

    *Solved*
    Blog
    #!
    Chan eil mi a Gàidhlig agam...pero si hablo español: soy catracho.
    Proud to be a Browncoat!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •