MCPcopy Create free account
hub / github.com/bpython/bpython / keypress

Method keypress

bpython/urwid.py:381–425  ·  view source on GitHub ↗
(self, size, key)

Source from the content-addressed store, hash-verified

379 return False
380
381 def keypress(self, size, key):
382 if urwid.command_map[key] in ("cursor up", "cursor down"):
383 # Do not handle up/down arrow, leave them for the repl.
384 return key
385
386 self._bpy_may_move_cursor = True
387 try:
388 if urwid.command_map[key] == "cursor max left":
389 self.edit_pos = 0
390 elif urwid.command_map[key] == "cursor max right":
391 self.edit_pos = len(self.get_edit_text())
392 elif urwid.command_map[key] == "clear word":
393 # ^w
394 if self.edit_pos == 0:
395 return
396 line = self.get_edit_text()
397 # delete any space left of the cursor
398 p = len(line[: self.edit_pos].strip())
399 line = line[:p] + line[self.edit_pos :]
400 # delete a full word
401 np = line.rfind(" ", 0, p)
402 if np == -1:
403 line = line[p:]
404 np = 0
405 else:
406 line = line[:np] + line[p:]
407 self.set_edit_text(line)
408 self.edit_pos = np
409 elif urwid.command_map[key] == "clear line":
410 line = self.get_edit_text()
411 self.set_edit_text(line[self.edit_pos :])
412 self.edit_pos = 0
413 elif key == "backspace":
414 line = self.get_edit_text()
415 cpos = len(line) - self.edit_pos
416 if not (cpos or len(line) % self.tab_length or line.strip()):
417 self.set_edit_text(line[: -self.tab_length])
418 else:
419 return super().keypress(size, key)
420 else:
421 # TODO: Add in specific keypress fetching code here
422 return super().keypress(size, key)
423 return None
424 finally:
425 self._bpy_may_move_cursor = False
426
427 def mouse_event(self, *args):
428 self._bpy_may_move_cursor = True

Callers

nothing calls this directly

Calls 1

keypressMethod · 0.45

Tested by

no test coverage detected