Show More
@@ -141,9 +141,29 b' def page(strng, start=0, screen_lines=0, pager_cmd=None):' | |||
|
141 | 141 | # unconditionally reset it every time. It's cheaper than making |
|
142 | 142 | # the checks. |
|
143 | 143 | term_flags = termios.tcgetattr(sys.stdout) |
|
144 | ||
|
145 | # Curses modifies the stdout buffer size by default, which messes | |
|
146 | # up Python's normal stdout buffering. This would manifest itself | |
|
147 | # to IPython users as delayed printing on stdout after having used | |
|
148 | # the pager. | |
|
149 | # | |
|
150 | # We can prevent this by manually setting the NCURSES_NO_SETBUF | |
|
151 | # environment variable. For more details, see: | |
|
152 | # http://bugs.python.org/issue10144 | |
|
153 | NCURSES_NO_SETBUF = os.environ.get('NCURSES_NO_SETBUF', None) | |
|
154 | os.environ['NCURSES_NO_SETBUF'] = '' | |
|
155 | ||
|
156 | # Proceed with curses initialization | |
|
144 | 157 | scr = curses.initscr() |
|
145 | 158 | screen_lines_real,screen_cols = scr.getmaxyx() |
|
146 | 159 | curses.endwin() |
|
160 | ||
|
161 | # Restore environment | |
|
162 | if NCURSES_NO_SETBUF is None: | |
|
163 | del os.environ['NCURSES_NO_SETBUF'] | |
|
164 | else: | |
|
165 | os.environ['NCURSES_NO_SETBUF'] = NCURSES_NO_SETBUF | |
|
166 | ||
|
147 | 167 | # Restore terminal state in case endwin() didn't. |
|
148 | 168 | termios.tcsetattr(sys.stdout,termios.TCSANOW,term_flags) |
|
149 | 169 | # Now we have what we needed: the screen size in rows/columns |
General Comments 0
You need to be logged in to leave comments.
Login now