mirror of
https://github.com/kennethreitz-archive/bpython-gist.git
synced 2026-06-05 15:40:17 +00:00
help() now works just the same as vanilla help()
This commit is contained in:
@@ -1,3 +1,12 @@
|
||||
v0.6.2
|
||||
======
|
||||
The help() now works (as far as I can see) exactly the same
|
||||
as the vanilla help() in the regular interpreter. I copied some
|
||||
code from pydoc.py to make it handle the special cases, e.g.
|
||||
help('keywords')
|
||||
help('modules')
|
||||
etc.
|
||||
|
||||
v0.6.1
|
||||
======
|
||||
Somehow it escaped my attention that the list window was never
|
||||
|
||||
+37
-3
@@ -1,23 +1,57 @@
|
||||
import pydoc
|
||||
import textwrap
|
||||
import sys
|
||||
import cStringIO
|
||||
|
||||
# window has to be a global so that the main bpython.py can load it and
|
||||
# alter its state and share it with the interpreter being used for the
|
||||
# actual user input, I couldn't think of another way of doing this.
|
||||
window = None
|
||||
|
||||
def _help( query ):
|
||||
def _help( obj ):
|
||||
"""Wrapper for the regular help() function but with a ghetto
|
||||
PAGER since curses + less = :(
|
||||
As per the vanilla help(), this function special-cases for str,
|
||||
so you can do help('isinstance') or help(isinstance) and get the
|
||||
same result.
|
||||
"""
|
||||
io = cStringIO.StringIO()
|
||||
doc = pydoc.TextDoc()
|
||||
helper = pydoc.Helper( None, io )
|
||||
|
||||
rows, columns = window.getmaxyx()
|
||||
rows -= 3
|
||||
columns -= 1
|
||||
output = doc.document( query )
|
||||
output = None
|
||||
|
||||
# Copied and pasted from Lib/pydoc.py and fiddled with
|
||||
# so it works fine with bpython. As far as I can tell
|
||||
# the bpython help is no compliant with the vanilla help.
|
||||
# Please let me know if you find this to be untrue.
|
||||
if type(obj) is type(''):
|
||||
if obj == 'help': helper.intro()
|
||||
elif obj == 'keywords': helper.listkeywords()
|
||||
elif obj == 'topics': helper.listtopics()
|
||||
elif obj == 'modules': helper.listmodules()
|
||||
elif obj[:8] == 'modules ':
|
||||
helper.listmodules(split(obj)[1])
|
||||
elif obj in helper.keywords: helper.showtopic(obj)
|
||||
elif obj in helper.topics: helper.showtopic(obj)
|
||||
elif obj: output = doc.document( eval(obj) )
|
||||
#######################
|
||||
|
||||
else:
|
||||
output = doc.document( obj )
|
||||
if not output:
|
||||
output = "No help found for %s" % obj
|
||||
return
|
||||
|
||||
if output is None:
|
||||
output = io.getvalue()
|
||||
io.close()
|
||||
|
||||
if not output:
|
||||
output = "No help found for %s" % query
|
||||
return
|
||||
|
||||
output = output.replace('\t', ' ')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user