Initial RuneStone project

This commit is contained in:
Knotty Wyvern
2026-09-26 01:25:42 -07:00
commit bdc15e952d
190 changed files with 25986 additions and 0 deletions
+128
View File
@@ -0,0 +1,128 @@
import { invoke } from "@tauri-apps/api/core";
import { listen, type UnlistenFn } from "@tauri-apps/api/event";
import { open as openDialog } from "@tauri-apps/plugin-dialog";
import type { TreeEntry, WorkspaceEvent, WorkspaceInfo } from "./types";
export async function pickWorkspaceFolder(title = "Open workspace"): Promise<string | null> {
const selected = await openDialog({
directory: true,
multiple: false,
title,
});
if (selected === null || Array.isArray(selected)) {
return null;
}
return selected;
}
export function workspaceOpen(path: string): Promise<WorkspaceInfo> {
return invoke("workspace_open", { path });
}
export function workspaceOpenWindow(path: string): Promise<void> {
return invoke("workspace_open_window", { path });
}
export function workspaceLastPath(): Promise<string | null> {
return invoke("workspace_last_path");
}
export function workspaceRecent(): Promise<string[]> {
return invoke("workspace_recent");
}
export function workspaceNew(parent: string, name: string): Promise<void> {
return invoke("workspace_new", { parent, name });
}
export function workspaceList(rel: string): Promise<TreeEntry[]> {
return invoke("workspace_list", { rel });
}
export function workspaceRead(rel: string): Promise<string> {
return invoke("workspace_read", { rel });
}
export function workspaceWrite(rel: string, contents: string, expected?: string): Promise<void> {
return invoke("workspace_write", { rel, contents, expected });
}
export function workspaceCreate(rel: string, kind: "file" | "folder"): Promise<void> {
return invoke("workspace_create", { rel, kind });
}
export function workspaceRename(from: string, to: string): Promise<void> {
return invoke("workspace_rename", { from, to });
}
export function workspaceDelete(rel: string): Promise<void> {
return invoke("workspace_delete", { rel });
}
export function workspaceReadDataUrl(rel: string): Promise<string> {
return invoke("workspace_read_data_url", { rel });
}
export function workspaceWriteBytes(rel: string, base64: string): Promise<void> {
return invoke("workspace_write_bytes", { rel, base64 });
}
export type CopyResult = {
name: string;
rel_path: string;
kind: "file" | "folder";
};
export function workspaceCopy(rel: string): Promise<CopyResult> {
return invoke("workspace_copy", { rel });
}
export function workspaceAbsPath(rel: string): Promise<string> {
return invoke("workspace_abs_path", { rel });
}
export function workspaceReveal(rel: string): Promise<void> {
return invoke("workspace_reveal", { rel });
}
export type SearchHit = {
rel_path: string;
line: number;
text: string;
};
export function workspaceSearch(query: string): Promise<SearchHit[]> {
return invoke("workspace_search", { query });
}
export function ptyOpen(id: string, cols: number, rows: number, cwd: string, profile?: string, directory?: string): Promise<void> {
return invoke("pty_open", { id, cols, rows, cwd, profile, directory });
}
export function ptyProfiles(): Promise<import("$lib/terminal/model").ShellProfile[]> {
return invoke("pty_profiles");
}
export function ptyNewWindow(): Promise<void> {
return invoke("pty_new_window", { id: crypto.randomUUID() });
}
export function ptyDictation(): Promise<void> { return invoke("pty_dictation"); }
export function ptyWrite(id: string, data: string): Promise<void> {
return invoke("pty_write", { id, data });
}
export function ptyResize(id: string, cols: number, rows: number): Promise<void> {
return invoke("pty_resize", { id, cols, rows });
}
export function ptyClose(id: string): Promise<void> {
return invoke("pty_close", { id });
}
export function onWorkspaceEvent(
handler: (event: WorkspaceEvent) => void,
): Promise<UnlistenFn> {
return listen<WorkspaceEvent>("workspace-event", (event) => {
handler(event.payload);
});
}