mirror of
https://github.com/kennethreitz-archive/bpython-gist.git
synced 2026-06-05 23:50:18 +00:00
help() fixed up so it's internalised
A few people pointed out that help() can cause problems, specifically when the help string is really big, so I've internalised it and injected my own help() function into the interpreter which pages the output, but it's pretty ghetto so I'm open to suggestions for improvement. That said, it's pretty obvious that scrolling up and down (like less) would be the main requested improvement so I should get to work on that at some point.
This commit is contained in:
@@ -1,3 +1,28 @@
|
||||
v0.5.0
|
||||
======
|
||||
A few people have commented that the help() built-in function
|
||||
doesn't work so well with bpython, since Python will try to output
|
||||
the help string to PAGER (usually "less") which obviously makes
|
||||
everything go wrong when curses is involved. With a bit of hackery
|
||||
I've written my own ghetto pager and injected my own help function
|
||||
into the interpreter when it initialises in an attempt to rectify this.
|
||||
As such, it's pretty untested but it seems to be working okay for me.
|
||||
Suggestions/bug reports/patches are welcome regarding this.
|
||||
|
||||
v0.4.2
|
||||
======
|
||||
Well, hopefully we're one step closer to making the list sizing
|
||||
stuff work. I really hate doing code for that kind of thing as I
|
||||
never get it quite right, but with perseverence it should end up
|
||||
being completely stable; it's not the hardest thing in the world.
|
||||
|
||||
Various cosmetic fixes have been put in at the request of a bunch
|
||||
of people who were kind enough to send me emails regarding their
|
||||
experiences.
|
||||
|
||||
PYTHONSTARTUP is now dealt with and used properly, as per the vanilla
|
||||
interpreter.
|
||||
|
||||
v0.4.1
|
||||
======
|
||||
It looks like the last release was actually pretty bug-free, aside
|
||||
|
||||
+18
-2
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env python
|
||||
# bpython 0.4.2::fancy curses interface to the Python repl::Bob Farrell 2008
|
||||
# bpython 0.5.0::fancy curses interface to the Python repl::Bob Farrell 2008
|
||||
#
|
||||
# The MIT License
|
||||
#
|
||||
@@ -64,11 +64,20 @@ try:
|
||||
except ImportError:
|
||||
OPTS.argspec = False
|
||||
else:
|
||||
import pydoc
|
||||
OPTS.argspec = True
|
||||
|
||||
import pydoc
|
||||
|
||||
# TODO:
|
||||
#
|
||||
#
|
||||
# No config file yet. This will allow things like "indent depth" for requiring
|
||||
# the user to hit return n times to signify the end of a code block.
|
||||
#
|
||||
# C-l doesn't repaint the screen yet.
|
||||
#
|
||||
# Tab completion does not work if not at the end of the line.
|
||||
#
|
||||
# Triple-quoted strings over multiple lines are not colourised correctly.
|
||||
#
|
||||
# Numerous optimisations can be made but it seems to do all the lookup stuff
|
||||
@@ -719,6 +728,13 @@ class Repl( object ):
|
||||
self.push( line )
|
||||
self.push( '\n' )
|
||||
|
||||
# The regular help() function uses PAGER to display the help, which
|
||||
# screws with bpython.
|
||||
from bpython import internal
|
||||
internal.window = self.scr
|
||||
self.push('from bpython import internal\n')
|
||||
self.push('help = internal._help')
|
||||
|
||||
self.iy, self.ix = self.scr.getyx()
|
||||
more = False
|
||||
while not self.do_exit:
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
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()
|
||||
@@ -31,7 +31,7 @@ PYTHONLIB = os.path.join(get_python_lib(standard_lib=1, prefix=""),
|
||||
"site-packages")
|
||||
|
||||
setup(name="bpython",
|
||||
version = "0.3.1",
|
||||
version = "0.5.0",
|
||||
description = "Fancy Interface to the Python Interpreter",
|
||||
author = "Robert Anthony Farrell",
|
||||
author_email = "robertanthonyfarrell@gmail.com",
|
||||
|
||||
Reference in New Issue
Block a user