def _detect_screen_size(use_curses, screen_lines_def):
TERM = os.environ.get('<STR_LIT>',None)<EOL>if (TERM=='<STR_LIT>' or TERM=='<STR_LIT>') and sys.platform != '<STR_LIT>':<EOL><INDENT>local_use_curses = use_curses<EOL><DEDENT>else:<EOL><INDENT>local_use_curses = False<EOL><DEDENT>if local_use_curses:<EOL><INDENT>import termios<EOL>import curses<EOL>term_flags = termios.tcgetattr(sys.stdout)<EOL>NCURSES_NO_SETBUF = os.environ.get('<STR_LIT>', None)<EOL>os.environ['<STR_LIT>'] = '<STR_LIT>'<EOL>scr = curses.initscr()<EOL>screen_lines_real,screen_cols = scr.getmaxyx()<EOL>curses.endwin()<EOL>if NCURSES_NO_SETBUF is None:<EOL><INDENT>del os.environ['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>os.environ['<STR_LIT>'] = NCURSES_NO_SETBUF<EOL><DEDENT>termios.tcsetattr(sys.stdout,termios.TCSANOW,term_flags)<EOL>return screen_lines_real<EOL><DEDENT>else:<EOL><INDENT>return screen_lines_def<EOL><DEDENT>
Attempt to work out the number of lines on the screen.

    This is called by page(). It can raise an error (e.g. when run in the
    test suite), so it's separated out so it can easily be called in a try block.