##// END OF EJS Templates
Fix long-standing and elusive terminal bug, where sometimes after issuing foo?, the terminal would get badly corrupted
Fernando Perez -
Show More
@@ -33,6 +33,18 b' import time'
33 import types
33 import types
34 import warnings
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 # Other IPython utilities
48 # Other IPython utilities
37 import IPython
49 import IPython
38 from IPython.Itpl import Itpl,itpl,printpl
50 from IPython.Itpl import Itpl,itpl,printpl
@@ -1548,21 +1560,25 b' def page(strng,start=0,screen_lines=0,pager_cmd = None):'
1548 # auto-determine screen size
1560 # auto-determine screen size
1549 if screen_lines <= 0:
1561 if screen_lines <= 0:
1550 if TERM=='xterm':
1562 if TERM=='xterm':
1551 try:
1563 use_curses = USE_CURSES
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
1559 else:
1564 else:
1560 # curses causes problems on many terminals other than xterm.
1565 # curses causes problems on many terminals other than xterm.
1561 use_curses = 0
1566 use_curses = False
1562 if use_curses:
1567 if use_curses:
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)
1563 scr = curses.initscr()
1576 scr = curses.initscr()
1564 screen_lines_real,screen_cols = scr.getmaxyx()
1577 screen_lines_real,screen_cols = scr.getmaxyx()
1565 curses.endwin()
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
1566 screen_lines += screen_lines_real
1582 screen_lines += screen_lines_real
1567 #print '***Screen size:',screen_lines_real,'lines x',\
1583 #print '***Screen size:',screen_lines_real,'lines x',\
1568 #screen_cols,'columns.' # dbg
1584 #screen_cols,'columns.' # dbg
@@ -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 2008-04-15 Ville Vainio <vivainio@gmail.com>
6 2008-04-15 Ville Vainio <vivainio@gmail.com>
2
7
3 * genutils.py: SList.grep supports 'field' argument
8 * genutils.py: SList.grep supports 'field' argument
General Comments 0
You need to be logged in to leave comments. Login now