MCPcopy Index your code
hub / github.com/bpython/bpython / handle_input

Method handle_input

bpython/urwid.py:1020–1059  ·  view source on GitHub ↗
(self, event)

Source from the content-addressed store, hash-verified

1018 edit.set_edit_markup(list(format_tokens(tokens)))
1019
1020 def handle_input(self, event):
1021 # Since most of the input handling here should be handled in the edit
1022 # instead, we return here early if the edit doesn't have the focus.
1023 if self.frame.get_focus() != "body":
1024 return
1025
1026 if event == "enter":
1027 inp = self.edit.get_edit_text()
1028 self.history.append(inp)
1029 self.edit.make_readonly()
1030 self.stdout_hist += inp
1031 self.stdout_hist += "\n"
1032 self.edit = None
1033 # This may take a while, so force a redraw first:
1034 self.main_loop.draw_screen()
1035 more = self.push(inp)
1036 self.prompt(more)
1037 elif event == "ctrl d":
1038 # ctrl+d on an empty line exits, otherwise deletes
1039 if self.edit is not None:
1040 if not self.edit.get_edit_text():
1041 raise urwid.ExitMainLoop()
1042 else:
1043 self.main_loop.process_input(["delete"])
1044 elif urwid.command_map[event] == "cursor up":
1045 # "back" from bpython.cli
1046 self.rl_history.enter(self.edit.get_edit_text())
1047 self.edit.set_edit_text("")
1048 self.edit.insert_text(self.rl_history.back())
1049 elif urwid.command_map[event] == "cursor down":
1050 # "fwd" from bpython.cli
1051 self.rl_history.enter(self.edit.get_edit_text())
1052 self.edit.set_edit_text("")
1053 self.edit.insert_text(self.rl_history.forward())
1054 elif urwid.command_map[event] == "next selectable":
1055 self.tab()
1056 elif urwid.command_map[event] == "prev selectable":
1057 self.tab(True)
1058 # else:
1059 # self.echo(repr(event))
1060
1061 def tab(self, back=False):
1062 """Process the tab key being hit.

Callers

nothing calls this directly

Calls 8

pushMethod · 0.95
promptMethod · 0.95
tabMethod · 0.95
appendMethod · 0.80
make_readonlyMethod · 0.80
backMethod · 0.80
forwardMethod · 0.80
enterMethod · 0.45

Tested by

no test coverage detected