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

Method prompt_undo

bpython/repl.py:1017–1051  ·  view source on GitHub ↗

Returns how many lines to undo, 0 means don't undo

(self)

Source from the content-addressed store, hash-verified

1015 self.interact.notify(f"{e}")
1016
1017 def prompt_undo(self) -> int:
1018 """Returns how many lines to undo, 0 means don't undo"""
1019 if (
1020 self.config.single_undo_time < 0
1021 or self.interp.timer.estimate() < self.config.single_undo_time
1022 ):
1023 return 1
1024 est = self.interp.timer.estimate()
1025 m = self.interact.file_prompt(
1026 _("Undo how many lines? (Undo will take up to ~%.1f seconds) [1]")
1027 % (est,)
1028 )
1029 if m is None:
1030 self.interact.notify(_("Undo canceled"), 0.1)
1031 return 0
1032
1033 try:
1034 if m == "":
1035 m = "1"
1036 n = int(m)
1037 except ValueError:
1038 self.interact.notify(_("Undo canceled"), 0.1)
1039 return 0
1040 else:
1041 if n == 0:
1042 self.interact.notify(_("Undo canceled"), 0.1)
1043 return 0
1044 else:
1045 message = ngettext(
1046 "Undoing %d line... (est. %.1f seconds)",
1047 "Undoing %d lines... (est. %.1f seconds)",
1048 n,
1049 )
1050 self.interact.notify(message % (n, est), 0.1)
1051 return n
1052
1053 def undo(self, n: int = 1) -> None:
1054 """Go back in the undo history n steps and call reevaluate()

Callers

nothing calls this directly

Calls 5

_Function · 0.90
ngettextFunction · 0.90
estimateMethod · 0.80
file_promptMethod · 0.45
notifyMethod · 0.45

Tested by

no test coverage detected