Skip to content

Commit 2afccdd

Browse files
committed
Use pager for help browser (fixes #294)
Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
1 parent ee91bf1 commit 2afccdd

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

bpython/curtsies.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,18 @@ def after_suspend():
105105
after_suspend=after_suspend) as repl:
106106
repl.height, repl.width = window.t.height, window.t.width
107107

108+
if interactive:
109+
# Add custom help command
110+
# TODO: add methods to run the code
111+
repl.coderunner.interp.locals['_repl'] = repl
112+
113+
repl.coderunner.interp.runsource(
114+
'from bpython.curtsiesfrontend._internal import _Helper')
115+
repl.coderunner.interp.runsource('help = _Helper(_repl)\n')
116+
117+
del repl.coderunner.interp.locals['_repl']
118+
del repl.coderunner.interp.locals['_Helper']
119+
108120
def process_event(e):
109121
"""If None is passed in, just paint the screen"""
110122
try:

bpython/curtsiesfrontend/_internal.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# The MIT License
2+
#
3+
# Copyright (c) 2015 the bpython authors.
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in
13+
# all copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
# THE SOFTWARE.
22+
23+
import sys
24+
import pydoc
25+
26+
import bpython._internal
27+
28+
class _Helper(bpython._internal._Helper):
29+
30+
def __init__(self, repl=None):
31+
self._repl = repl
32+
pydoc.pager = self.pager
33+
34+
super(_Helper, self).__init__()
35+
36+
def pager(self, output):
37+
self._repl.pager(output)
38+
39+
# vim: sw=4 ts=4 sts=4 ai et

0 commit comments

Comments
 (0)