I'm new to nurses, and trying it out on my OSX Lion with some python code. I've ran across a weird bug, and I don't know what I'm doing wrong. I've Googled extensively, and can't find a similar issue, even in linux. I've selectively removed lines to see if one of them is an issue, also. When I run the code below, I get nothing. No menu, and my terminal is messed up, if I hit enter, you see what I get in the picture below. I have to type a reset
to make it work well again. Can anyone give me suggestions, or point me in the direction where to look? I would really appreciate it. Thanks.
Script:
import curses
screen = curses.initscr() # Init curses
curses.noecho() # Suppress key output to screen
curses.curs_set(0) # remove cursor from screen
screen.keypad(1) # set mode when capturing keypresses
top_pos = 12
left_pos = 12
screen.addstr(top_pos, left_pos, "This is a String")
Result:
BTW, I'm using the default python and libs in Lion, no macports. I'd like to use the native libraries, if possible.
You have 2 problems.
After adding the string to the screen with addstr you don't tell it to refresh the screen. Add this after the call to addstr:
screen.refresh()
You need to call endwin() at the end of you program to reset the terminal. Add this to the end of your program:
curses.endwin()
That said, after making those 2 changes when you run your program it will appear to do nothing because after displaying the string on the screen curses exits and returns the screen to the state before you ran the program.
Add this before the call to endwin():
screen.getch()
Then it will wait for you press a key before exiting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With