Ncurses, python and OSX Lion

I am new to the nurse and have tried it on my OSX Lion with some Python code. I came across a strange mistake and I don’t know what I am doing wrong. I use Googled extensively and cannot find a similar problem, even on Linux. I selectively deleted rows to see if one of them is a problem. When I run the code below, I get nothing. There is no menu, and my terminal is corrupted, if I hit enter, you will see what I see in the picture below. I have to enter reset so that it works well again. Can someone give me suggestions or point me in that direction where to look? I would be very grateful. 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:

screenshot

By the way, I use python by default and libs in Lion, without macports. I would like to use native libraries if possible.

+4
source share
1 answer

You have 2 problems.

After adding a line to the screen using addstr, you do not specify it to refresh the screen. Add this after calling addstr:

 screen.refresh() 

You need to call endwin () at the end of your program to reset the terminal. Add this to the end of your program:

 curses.endwin() 

However, after making these two changes at the start of your program, this will do nothing, because after displaying the lines on the screen, the curses end and return the screen to the state before the program starts.

Add this before calling endwin ():

 screen.getch() 

Then it will wait for the key to be pressed until it exits.

+5
source

Source: https://habr.com/ru/post/1391583/


All Articles