Show More
@@ -33,6 +33,18 b' import time' | |||
|
33 | 33 | import types |
|
34 | 34 | import warnings |
|
35 | 35 | |
|
36 | # Curses and termios are Unix-only modules | |
|
37 | try: | |
|
38 | import curses | |
|
39 | # We need termios as well, so if its import happens to raise, we bail on | |
|
40 | # using curses altogether. | |
|
41 | import termios | |
|
42 | except ImportError: | |
|
43 | USE_CURSES = False | |
|
44 | else: | |
|
45 | # Curses on Solaris may not be complete, so we can't use it there | |
|
46 | USE_CURSES = hasattr(curses,'initscr') | |
|
47 | ||
|
36 | 48 | # Other IPython utilities |
|
37 | 49 | import IPython |
|
38 | 50 | from IPython.Itpl import Itpl,itpl,printpl |
@@ -1548,26 +1560,30 b' def page(strng,start=0,screen_lines=0,pager_cmd = None):' | |||
|
1548 | 1560 | # auto-determine screen size |
|
1549 | 1561 | if screen_lines <= 0: |
|
1550 | 1562 | if TERM=='xterm': |
|
1551 | try: | |
|
1552 | import curses | |
|
1553 | if hasattr(curses,'initscr'): | |
|
1554 | use_curses = 1 | |
|
1555 | else: | |
|
1556 | use_curses = 0 | |
|
1557 | except ImportError: | |
|
1558 | use_curses = 0 | |
|
1563 | use_curses = USE_CURSES | |
|
1559 | 1564 | else: |
|
1560 | 1565 | # curses causes problems on many terminals other than xterm. |
|
1561 |
use_curses = |
|
|
1566 | use_curses = False | |
|
1562 | 1567 | if use_curses: |
|
1563 | scr = curses.initscr() | |
|
1564 | screen_lines_real,screen_cols = scr.getmaxyx() | |
|
1565 | curses.endwin() | |
|
1566 | screen_lines += screen_lines_real | |
|
1567 | #print '***Screen size:',screen_lines_real,'lines x',\ | |
|
1568 | #screen_cols,'columns.' # dbg | |
|
1568 | # There is a bug in curses, where *sometimes* it fails to properly | |
|
1569 | # initialize, and then after the endwin() call is made, the | |
|
1570 | # terminal is left in an unusable state. Rather than trying to | |
|
1571 | # check everytime for this (by requesting and comparing termios | |
|
1572 | # flags each time), we just save the initial terminal state and | |
|
1573 | # unconditionally reset it every time. It's cheaper than making | |
|
1574 | # the checks. | |
|
1575 | term_flags = termios.tcgetattr(sys.stdout) | |
|
1576 | scr = curses.initscr() | |
|
1577 | screen_lines_real,screen_cols = scr.getmaxyx() | |
|
1578 | curses.endwin() | |
|
1579 | # Restore terminal state in case endwin() didn't. | |
|
1580 | termios.tcsetattr(sys.stdout,termios.TCSANOW,term_flags) | |
|
1581 | # Now we have what we needed: the screen size in rows/columns | |
|
1582 | screen_lines += screen_lines_real | |
|
1583 | #print '***Screen size:',screen_lines_real,'lines x',\ | |
|
1584 | #screen_cols,'columns.' # dbg | |
|
1569 | 1585 | else: |
|
1570 |
|
|
|
1586 | screen_lines += screen_lines_def | |
|
1571 | 1587 | |
|
1572 | 1588 | #print 'numlines',numlines,'screenlines',screen_lines # dbg |
|
1573 | 1589 | if numlines <= screen_lines : |
@@ -1,3 +1,8 b'' | |||
|
1 | 2008-04-18 Fernando Perez <Fernando.Perez@berkeley.edu> | |
|
2 | ||
|
3 | * IPython/genutils.py (page): apply workaround to curses bug that | |
|
4 | can leave terminal corrupted after a call to initscr(). | |
|
5 | ||
|
1 | 6 | 2008-04-15 Ville Vainio <vivainio@gmail.com> |
|
2 | 7 | |
|
3 | 8 | * genutils.py: SList.grep supports 'field' argument |
General Comments 0
You need to be logged in to leave comments.
Login now