Skip to content

Commit 5a19864

Browse files
More help message, more keys in config
1 parent 4ecdd88 commit 5a19864

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

bpython/config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ def loadini(struct, configfile):
7474
'down_one_line': 'C-n',
7575
'exit': '',
7676
'external_editor': 'F7',
77+
'edit_current_block': 'C-x',
78+
'help': 'F1',
7779
'last_output': 'F9',
7880
'pastebin': 'F8',
7981
'save': 'C-s',
@@ -130,7 +132,9 @@ def loadini(struct, configfile):
130132
struct.delete_key = config.get('keyboard', 'delete')
131133
struct.exit_key = config.get('keyboard', 'exit')
132134
struct.last_output_key = config.get('keyboard', 'last_output')
135+
struct.edit_current_block_key = config.get('keyboard', 'edit_current_block')
133136
struct.external_editor_key = config.get('keyboard', 'external_editor')
137+
struct.help_key = config.get('keyboard', 'help')
134138

135139
struct.pastebin_confirm = config.getboolean('general', 'pastebin_confirm')
136140
struct.pastebin_private = config.getboolean('general', 'pastebin_private')

bpython/curtsiesfrontend/repl.py

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@
2424
translations.init()
2525
from bpython.translations import _
2626
from bpython._py3compat import py3
27+
import bpython
2728

2829
from curtsies import FSArray, fmtstr, FmtStr, Termmode
2930
from curtsies.bpythonparse import parse as bpythonparse
3031
from curtsies.bpythonparse import func_for_letter, color_for_letter
3132
from curtsies import fmtfuncs
3233
from curtsies import events
34+
import curtsies
3335

3436
from bpython.curtsiesfrontend.manual_readline import char_sequences as rl_char_sequences
3537
from bpython.curtsiesfrontend.manual_readline import get_updated_char_sequences
@@ -44,6 +46,24 @@
4446

4547
logger = logging.getLogger(__name__)
4648

49+
HELP_MESSAGE = """Thanks for using bpython!
50+
51+
See http://bpython-interpreter.org/ for info, http://docs.bpython-interpreter.org/ for docs, and https://github.com/bpython/bpython for source.
52+
Please report issues at https://github.com/bpython/bpython/issues
53+
54+
Try using undo ({config.undo_key})!
55+
Edit the current line ({config.edit_current_block_key}) or the entire session ({config.external_editor_key}) in an external editor! (currently {config.editor})
56+
Save sessions ({config.save_key}) or post them to pastebins ({config.pastebin_key})! Current pastebin helper: {config.pastebin_helper}
57+
Re-execute the current session and reload all modules to test out changes to a module!
58+
Toggle auto-reload mode to re-execute the current session when a module you've imported is modified!
59+
60+
Use bpython-curtsies -i your_script.py to run a file in interactive mode (interpreter in namespace of script).
61+
Use bpython-curtsies -t your_script.py to paste in the contents of a file, as though you typed them.
62+
63+
Use a config file at {config_file_location} to customize keys and behavior of bpython.
64+
See {example_config_url} for an example config file.
65+
"""
66+
4767
class FakeStdin(object):
4868
"""Stdin object user code references so sys.stdin.read() asked user for interactive input"""
4969
def __init__(self, coderunner, repl):
@@ -189,7 +209,7 @@ def __init__(self, locals_=None, config=None,
189209
if interp is None:
190210
interp = code.InteractiveInterpreter(locals=locals_)
191211
if banner is None:
192-
banner = _('welcome to bpython')
212+
banner = _('Welcome to bpython! Press <%s> for help.') % config.help_key
193213
config.autocomplete_mode = autocomplete.SIMPLE # only one implemented currently
194214
if config.cli_suggestion_width <= 0 or config.cli_suggestion_width > 1:
195215
config.cli_suggestion_width = 1
@@ -205,7 +225,7 @@ def smarter_request_refresh():
205225
self.get_term_hw = get_term_hw
206226
self.get_cursor_vertical_diff = get_cursor_vertical_diff
207227

208-
self.status_bar = StatusBar(banner if config.curtsies_fill_terminal else '', _(
228+
self.status_bar = StatusBar(banner, _(
209229
" <%s> Rewind <%s> Save <%s> Pastebin <%s> Editor"
210230
) % (config.undo_key, config.save_key, config.pastebin_key, config.external_editor_key),
211231
refresh_request=self.request_refresh
@@ -389,7 +409,7 @@ def process_event(self, e):
389409
if self.config.highlight_show_source:
390410
source = format(PythonLexer().get_tokens(source), TerminalFormatter())
391411
self.pager(source)
392-
elif e in ('KEY_F(1)',):
412+
elif e in key_dispatch[self.config.help_key]:
393413
self.pager(self.help_text())
394414
elif e in key_dispatch[self.config.suspend_key]:
395415
raise SystemExit()
@@ -416,7 +436,7 @@ def process_event(self, e):
416436
elif e in key_dispatch[self.config.external_editor_key]:
417437
self.send_session_to_external_editor()
418438
#TODO add PAD keys hack as in bpython.cli
419-
elif e in ["\x18"]:
439+
elif e in key_dispatch[self.config.edit_current_block_key]:
420440
self.send_current_block_to_external_editor()
421441
elif e in ["\x1b"]: #ESC
422442
pass
@@ -1000,12 +1020,26 @@ def pager(self, text):
10001020
self.focus_on_subprocess(command + [tmp.name])
10011021

10021022
def help_text(self):
1023+
return self.version_help_text() + '\n' + self.key_help_text()
1024+
1025+
def version_help_text(self):
1026+
return (('bpython-curtsies version %s' % bpython.__version__) + ' ' +
1027+
('using curtsies version %s' % curtsies.__version__) + '\n' +
1028+
HELP_MESSAGE.format(config_file_location=default_config_path(),
1029+
example_config_url='https://raw.githubusercontent.com/bpython/bpython/master/sample-config',
1030+
config=self.config)
1031+
)
1032+
1033+
def key_help_text(self):
10031034
NOT_IMPLEMENTED = ['suspend', 'cut to buffer', 'search', 'last output', 'yank from buffer', 'cut to buffer']
10041035
pairs = []
1036+
pairs.append(['complete history suggestion', 'right arrow at end of line'])
1037+
pairs.append(['previous match with current line', 'up arrow'])
10051038
for functionality, key in [(attr[:-4].replace('_', ' '), getattr(self.config, attr))
10061039
for attr in self.config.__dict__
10071040
if attr.endswith('key')]:
10081041
if functionality in NOT_IMPLEMENTED: key = "Not Implemented"
1042+
if key == '': key = 'Disabled'
10091043

10101044
pairs.append([functionality, key])
10111045

0 commit comments

Comments
 (0)