Skip to content

Commit

Permalink
chore: rename Console to ConsoleAPI because it's just a wrapper a…
Browse files Browse the repository at this point in the history
…nd simplify code
  • Loading branch information
CNSeniorious000 committed Jun 28, 2024
1 parent 7cba7fd commit c529e93
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/lib/components/console/HeadlessConsole.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@
</script>

<script lang="ts">
import type { Console } from "$py/app/console";
import type { ConsoleAPI } from "$py/app/console";
import { getPy } from "$lib/pyodide";
import { onMount } from "svelte";
export let ready = false;
export let status: Status = "complete";
export let log: Item[] = [];
export let pyConsole: Console;
export let pyConsole: ConsoleAPI;
export let complete: AutoComplete | undefined;
let loading = 0;
onMount(async () => {
const py = await getPy();
pyConsole = py.runPython("consoleModule.Console()");
pyConsole = py.runPython("consoleModule.ConsoleAPI()");
complete = pyConsole.complete;
pyConsole.console.stdout_callback = text => pushLog({ type: "out", text });
Expand Down
10 changes: 4 additions & 6 deletions src/python/app/console.d.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import type { PyProxy } from "pyodide/ffi";

export class Result extends PyProxy {
export class Result {
status: "complete" | "incomplete" | "syntax-error";
formatted_error?: string;
async get_repr(): Promise<string | undefined>;
}

class PyodideConsole extends PyProxy {
class EnhancedConsole {
stdout_callback(out: string);
stderr_callback(err: string);
pop(): void;
}

export class Console {
export class ConsoleAPI {
complete(source: string): [string[], number];
console: PyodideConsole;
console: EnhancedConsole;
async push(line: string): Result;
}
3 changes: 1 addition & 2 deletions src/python/app/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def pop(self):
self.fake_file.write_text(source[: source.rindex("\n", None, -1) + 1])


class Console:
class ConsoleAPI:
@cached_property
def builtins_layer(self):
return {"__name__": "__main__", "__builtins__": builtins, "__doc__": None}
Expand Down Expand Up @@ -102,7 +102,6 @@ def __getitem__(self, key: str):
def complete(self, source: str):
return self.console.complete(source)

@js_api
def push(self, line: str):
res = Result(future := self.console.push(line))

Expand Down
4 changes: 2 additions & 2 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import type { AutoComplete, Item, Status } from "$lib/components/console/HeadlessConsole.svelte";
import type { Console } from "$py/app/console";
import type { ConsoleAPI } from "$py/app/console";
import type { ClipboardEventHandler, KeyboardEventHandler } from "svelte/elements";
import { Err, In, Out, Repr } from "$lib/components/console";
Expand All @@ -21,7 +21,7 @@
let input = "";
let inputRef: HTMLInputElement;
let pyConsole: Console;
let pyConsole: ConsoleAPI;
let complete: AutoComplete;
let status: Status;
Expand Down

0 comments on commit c529e93

Please sign in to comment.