Skip to content

Commit

Permalink
Add input method for runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
klntsky committed Nov 22, 2024
1 parent 30d185c commit 4393c8d
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions python/src/runtimes/cli_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,24 @@ def __init__(self):
self.status_left = BLUE
self.status_right = RESET

def set_status(self, status: str):
# normalize the status line
status = status.replace("\n", " ").replace("\r", "")

old_status = self.status
self.status = status
def print_status(self, old_status=""):
print(
"\r" +
self.status_left +
status +
self.status +
self.status_right +
self.padding_for(old_status, status),
end=""
self.padding_for(old_status, self.status),
end="",
flush=True
)

def set_status(self, status: str):
# normalize the status line
status = status.replace("\n", " ").replace("\r", "")
old_status = self.status
self.status = status
self.print_status(old_status)

def load_module(self, module_name: str):
if module_name.startswith("./") or module_name.startswith("../"):
file_path = os.path.abspath(
Expand Down Expand Up @@ -75,21 +78,17 @@ def print_chunk(self, chunk: str):
print(line, flush=True)
# save the last line into the accumulator
self.last_line = lines[-1]
# restore the status line
print(
self.status_left + self.status + self.status_right,
end="",
flush=True
)
else:
self.last_line += chunk
# restore the status line
print(
"\r" +
self.status_left + self.status + self.status_right,
end="",
flush=True
)
# restore the status line
self.print_status()

def input(self, prompt):
print("\r", end="", flush=True)
res = input(prompt)
self.print_status()
return res


def finalize(self):
print("\r", end="", flush=True)
Expand Down

0 comments on commit 4393c8d

Please sign in to comment.