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

Class SimpleRepl

doc/sphinx/source/simplerepl.py:42–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40
41
42class SimpleRepl(BaseRepl):
43 def __init__(self, config):
44 self.requested_events = []
45 BaseRepl.__init__(self, config, window=None)
46
47 def _request_refresh(self):
48 self.requested_events.append(bpythonevents.RefreshRequestEvent())
49
50 def _schedule_refresh(self, when="now"):
51 if when == "now":
52 self.request_refresh()
53 else:
54 dt = round(when - time.time(), 1)
55 self.out(f"please refresh in {dt} seconds")
56
57 def _request_reload(self, files_modified=("?",)):
58 e = bpythonevents.ReloadEvent()
59 e.files_modified = files_modified
60 self.requested_events.append(e)
61 self.out("please hit enter to trigger a refresh")
62
63 def request_undo(self, n=1):
64 self.requested_events.append(bpythonevents.UndoEvent(n=n))
65
66 def out(self, msg):
67 if hasattr(self, "orig_stdout"):
68 self.orig_stdout.write(f"{msg}\n")
69 self.orig_stdout.flush()
70 else:
71 print(msg)
72
73 def on_suspend(self):
74 pass
75
76 def after_suspend(self):
77 self.out("please hit enter to trigger a refresh")
78
79 def print_output(self):
80 arr, cpos = self.paint()
81 arr[cpos[0] : cpos[0] + 1, cpos[1] : cpos[1] + 1] = ["~"]
82
83 def print_padded(s):
84 return self.out(s.center(self.width + 8, "X"))
85
86 print_padded("")
87 print_padded(' enter -> "/", rewind -> "\\", ')
88 print_padded(' reload -> "|", pastebin -> "$", ')
89 print_padded(' "~" is the cursor ')
90 print_padded("")
91 self.out("X``" + ("`" * (self.width + 2)) + "``X")
92 for line in arr:
93 self.out("X```" + line.ljust(self.width) + "```X")
94 logger.debug("line:")
95 logger.debug(repr(line))
96 self.out("X``" + ("`" * (self.width + 2)) + "``X")
97 self.out("X" * (self.width + 8))
98 return max(len(arr) - self.height, 0)
99

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected