Show More
@@ -37,7 +37,6 b' from io import UnsupportedOperation' | |||||
37 |
|
37 | |||
38 | from IPython.core import ipapi |
|
38 | from IPython.core import ipapi | |
39 | from IPython.core.error import TryNext |
|
39 | from IPython.core.error import TryNext | |
40 | from IPython.utils.cursesimport import use_curses |
|
|||
41 | from IPython.utils.data import chop |
|
40 | from IPython.utils.data import chop | |
42 | from IPython.utils import io |
|
41 | from IPython.utils import io | |
43 | from IPython.utils.process import system |
|
42 | from IPython.utils.process import system | |
@@ -73,22 +72,24 b' def page_dumb(strng, start=0, screen_lines=25):' | |||||
73 | last_escape = esc_list[-1] |
|
72 | last_escape = esc_list[-1] | |
74 | print(last_escape + os.linesep.join(screens[-1]), file=io.stdout) |
|
73 | print(last_escape + os.linesep.join(screens[-1]), file=io.stdout) | |
75 |
|
74 | |||
76 |
def _detect_screen_size( |
|
75 | def _detect_screen_size(screen_lines_def): | |
77 | """Attempt to work out the number of lines on the screen. |
|
76 | """Attempt to work out the number of lines on the screen. | |
78 |
|
77 | |||
79 | This is called by page(). It can raise an error (e.g. when run in the |
|
78 | This is called by page(). It can raise an error (e.g. when run in the | |
80 | test suite), so it's separated out so it can easily be called in a try block. |
|
79 | test suite), so it's separated out so it can easily be called in a try block. | |
81 | """ |
|
80 | """ | |
82 | TERM = os.environ.get('TERM',None) |
|
81 | TERM = os.environ.get('TERM',None) | |
83 | if (TERM=='xterm' or TERM=='xterm-color') and sys.platform != 'sunos5': |
|
82 | if not((TERM=='xterm' or TERM=='xterm-color') and sys.platform != 'sunos5'): | |
84 | local_use_curses = use_curses |
|
|||
85 | else: |
|
|||
86 | # curses causes problems on many terminals other than xterm, and |
|
83 | # curses causes problems on many terminals other than xterm, and | |
87 | # some termios calls lock up on Sun OS5. |
|
84 | # some termios calls lock up on Sun OS5. | |
88 | local_use_curses = False |
|
85 | return screen_lines_def | |
89 | if local_use_curses: |
|
86 | ||
|
87 | try: | |||
90 | import termios |
|
88 | import termios | |
91 | import curses |
|
89 | import curses | |
|
90 | except ImportError: | |||
|
91 | return screen_lines_def | |||
|
92 | ||||
92 |
|
|
93 | # There is a bug in curses, where *sometimes* it fails to properly | |
93 |
|
|
94 | # initialize, and then after the endwin() call is made, the | |
94 |
|
|
95 | # terminal is left in an unusable state. Rather than trying to | |
@@ -110,7 +111,12 b' def _detect_screen_size(use_curses, screen_lines_def):' | |||||
110 |
|
|
111 | os.environ['NCURSES_NO_SETBUF'] = '' | |
111 |
|
112 | |||
112 |
|
|
113 | # Proceed with curses initialization | |
|
114 | try: | |||
113 | scr = curses.initscr() |
|
115 | scr = curses.initscr() | |
|
116 | except AttributeError: | |||
|
117 | # Curses on Solaris may not be complete, so we can't use it there | |||
|
118 | return screen_lines_def | |||
|
119 | ||||
114 |
|
|
120 | screen_lines_real,screen_cols = scr.getmaxyx() | |
115 |
|
|
121 | curses.endwin() | |
116 |
|
122 | |||
@@ -126,8 +132,6 b' def _detect_screen_size(use_curses, screen_lines_def):' | |||||
126 |
|
|
132 | return screen_lines_real | |
127 |
|
|
133 | #print '***Screen size:',screen_lines_real,'lines x',\ | |
128 |
|
|
134 | #screen_cols,'columns.' # dbg | |
129 | else: |
|
|||
130 | return screen_lines_def |
|
|||
131 |
|
135 | |||
132 | def page(strng, start=0, screen_lines=0, pager_cmd=None): |
|
136 | def page(strng, start=0, screen_lines=0, pager_cmd=None): | |
133 | """Print a string, piping through a pager after a certain length. |
|
137 | """Print a string, piping through a pager after a certain length. | |
@@ -184,7 +188,7 b' def page(strng, start=0, screen_lines=0, pager_cmd=None):' | |||||
184 | # auto-determine screen size |
|
188 | # auto-determine screen size | |
185 | if screen_lines <= 0: |
|
189 | if screen_lines <= 0: | |
186 | try: |
|
190 | try: | |
187 |
screen_lines += _detect_screen_size( |
|
191 | screen_lines += _detect_screen_size(screen_lines_def) | |
188 | except (TypeError, UnsupportedOperation): |
|
192 | except (TypeError, UnsupportedOperation): | |
189 | print(str_toprint, file=io.stdout) |
|
193 | print(str_toprint, file=io.stdout) | |
190 | return |
|
194 | return |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now