Skip to content

Commit 7018553

Browse files
F1 brings up keys help in curtsies
1 parent bebff69 commit 7018553

1 file changed

Lines changed: 22 additions & 4 deletions

File tree

bpython/curtsiesfrontend/repl.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,10 +388,9 @@ def process_event(self, e):
388388
else:
389389
if self.config.highlight_show_source:
390390
source = format(PythonLexer().get_tokens(source), TerminalFormatter())
391-
with tempfile.NamedTemporaryFile() as tmp:
392-
tmp.write(source)
393-
tmp.flush()
394-
self.focus_on_subprocess(['less', '-R', tmp.name])
391+
self.pager(source)
392+
elif e in ('KEY_F(1)',):
393+
self.pager(self.help_text())
395394
elif e in key_dispatch[self.config.suspend_key]:
396395
raise SystemExit()
397396
elif e in ("",) + key_dispatch[self.config.exit_key]:
@@ -993,6 +992,25 @@ def focus_on_subprocess(self, args):
993992
finally:
994993
signal.signal(signal.SIGWINCH, prev_sigwinch_handler)
995994

995+
def pager(self, text):
996+
with tempfile.NamedTemporaryFile() as tmp:
997+
tmp.write(text)
998+
tmp.flush()
999+
self.focus_on_subprocess(['less', '-R', tmp.name])
1000+
1001+
def help_text(self):
1002+
NOT_IMPLEMENTED = ['suspend', 'cut to buffer', 'search', 'last output', 'yank from buffer', 'cut to buffer']
1003+
pairs = []
1004+
for functionality, key in [(attr[:-4].replace('_', ' '), getattr(self.config, attr))
1005+
for attr in self.config.__dict__
1006+
if attr.endswith('key')]:
1007+
if functionality in NOT_IMPLEMENTED: key = "Not Implemented"
1008+
1009+
pairs.append([functionality, key])
1010+
1011+
max_func = max(len(func) for func, key in pairs)
1012+
return '\n'.join('%s : %s' % (func.rjust(max_func), key) for func, key in pairs)
1013+
9961014
def is_nop(char):
9971015
return unicodedata.category(unicode(char)) == 'Cc'
9981016

0 commit comments

Comments
 (0)