Fixed the pager and help so the full help is displayed

Also added a 'q' option to the pager to cancel out of huge help pages.
This commit is contained in:
Bob Farrell
2008-06-24 17:33:32 +01:00
parent ad410584c9
commit 93ad83025b
3 changed files with 61 additions and 68 deletions
-49
View File
@@ -1,49 +0,0 @@
import pydoc
import textwrap
import sys
window = None
def _help( query ):
"""Wrapper for the regular help() function but with a ghetto
PAGER since curses + less = :(
query : the actual search thing
window : a curses window instance to use getch() on
and for extrapolating the window size to work it all out"""
rows, columns = window.getmaxyx()
rows -= 3
columns -= 1
output = pydoc.getdoc( query )
if '\n' in output:
output = output.replace('\n\n', '\n')
output = output.split('\n')
else:
output = [output]
paragraphs = []
for o in output:
paragraphs.append( textwrap.wrap( o, columns ) )
i = 0
for j, paragraph in enumerate( paragraphs ):
for line in paragraph:
sys.stdout.write( line + '\n' )
i += 1
if not i % rows:
wait_for_key( window )
if j + 1 < len( paragraphs ):
sys.stdout.write('\n ')
def wait_for_key( window ):
"""Block until a key is pressed for the ghetto paging."""
window.addstr("Press any key...")
while True:
c = window.getch()
if c:
break
y = window.getyx()[0]
window.move(y-1, 0)
window.clrtoeol()