Skip to content

Commit

Permalink
feat: handle console pop when backspacing
Browse files Browse the repository at this point in the history
  • Loading branch information
CNSeniorious000 committed Jun 28, 2024
1 parent 2625e1e commit e922124
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
6 changes: 2 additions & 4 deletions src/python/app/console.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PyProxy, PyProxyWithLength } from "pyodide/ffi";
import type { PyProxy } from "pyodide/ffi";

export class Result extends PyProxy {
status: "complete" | "incomplete" | "syntax-error";
Expand All @@ -9,9 +9,7 @@ export class Result extends PyProxy {
class PyodideConsole extends PyProxy {
stdout_callback(out: string);
stderr_callback(err: string);
buffer: PyProxyWithLength & {
pop: (index = -1) => string;
};
pop(): void;
}

export class Console {
Expand Down
8 changes: 8 additions & 0 deletions src/python/app/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ def runsource(self, source: str, filename="<console>"):
self._append_source_file(source)
return super().runsource(fake_source, filename)

def pop(self):
assert self.buffer
self.buffer.pop()
self.line_offset -= 1

source = self.fake_file.read_text()
self.fake_file.write_text(source[: source.rindex("\n", None, -1) + 1])


class Console:
@cached_property
Expand Down
2 changes: 1 addition & 1 deletion src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
if (inputRef.selectionStart === 0 && inputRef.selectionEnd === 0 && status === "incomplete") {
const item = log.at(-1)!;
const lines = item.text.split("\n");
pyConsole.console.buffer.pop();
pyConsole.console.pop();
if (lines.length === 1) {
log = [...log.slice(0, -1)];
input = lines[0] + input;
Expand Down

0 comments on commit e922124

Please sign in to comment.