diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-22 02:47:32 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-22 02:47:32 +0000 |
| commit | 68d939ad652c7fca7fe7de7b55e51e0f34374f19 (patch) | |
| tree | 6d50a6a5f1dfe45df2e9cedd21b7bd5e35eab243 /bundle | |
| parent | 77098c720639a421f81ee14e47250d167d7af7bd (diff) | |
feat(bundle): run and stop programs with F5 from the Run menu
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'bundle')
| -rw-r--r-- | bundle/AGENTS/DEVELOPMENT.md | 2 | ||||
| -rw-r--r-- | bundle/README.md | 2 | ||||
| -rw-r--r-- | bundle/src-tauri/src/menu.rs | 6 | ||||
| -rw-r--r-- | bundle/src/main.js | 14 |
4 files changed, 12 insertions, 12 deletions
diff --git a/bundle/AGENTS/DEVELOPMENT.md b/bundle/AGENTS/DEVELOPMENT.md index a77e1e8..0995c3a 100644 --- a/bundle/AGENTS/DEVELOPMENT.md +++ b/bundle/AGENTS/DEVELOPMENT.md @@ -30,6 +30,6 @@ The Rust runner launches the packaged compiler directly, using the source direct After building the compiler, run `cargo test --release --manifest-path src-tauri/Cargo.toml`. The two native tests exercise real compilation, prefilled input, EOF, Unicode, diagnostics, output before process exit, stopping, single-run exclusion and restart, including source paths with spaces. CI runs them on all three native platforms. -The native menu is defined once in `src-tauri/src/menu.rs` with Tauri's menu API; macOS shows it in the system menu bar, Windows and Linux at the top of each window. Only the macOS application menu is platform-specific. Edit keeps the predefined clipboard and undo items, which macOS needs in the webview. Other platforms have no Quit item because it exits without unsaved-changes prompts. Custom item ids name commands in `src/main.js`; a click emits a `menu` event with the id to the focused window. Keyboard shortcuts are Monaco `KeyMod.CtrlCmd` keybindings: the editor registers Find and Toggle Line Comment, and the document handler matches the menu's commands with `StandardKeyboardEvent.equals`, so a shortcut runs once whether the webview or the native menu receives the key first. Keep menu accelerators and handler bindings in sync. Never test `ctrlKey`/`metaKey` directly; Monaco resolves CtrlCmd to Cmd on macOS and Ctrl elsewhere. +The native menu is defined once in `src-tauri/src/menu.rs` with Tauri's menu API; macOS shows it in the system menu bar, Windows and Linux at the top of each window. Only the macOS application menu is platform-specific. Edit keeps the predefined clipboard and undo items, which macOS needs in the webview. Other platforms have no Quit item because it exits without unsaved-changes prompts. Custom item ids name commands in `src/main.js`; a click emits a `menu` event with the id to the focused window. Run/Stop (F5) toggles like the Run button; its label is fixed because all windows share the menu. Keyboard shortcuts are Monaco `KeyMod.CtrlCmd` keybindings: the editor registers Find and Toggle Line Comment, and the document handler matches the menu's commands with `StandardKeyboardEvent.equals`, so a shortcut runs once whether the webview or the native menu receives the key first. Keep menu accelerators and handler bindings in sync. Never test `ctrlKey`/`metaKey` directly; Monaco resolves CtrlCmd to Cmd on macOS and Ctrl elsewhere. Use brief English UI labels and messages. Keep one document per window and prefilled stdin. More documents use native OS windows created by the `new_window` command from the configured window; do not add tabs or in-page switching. Before feature commits, run affected plugin tests, build the frontend and check native compilation as appropriate. Do not add a separate UI test framework for routine changes. diff --git a/bundle/README.md b/bundle/README.md index 93b619e..7288463 100644 --- a/bundle/README.md +++ b/bundle/README.md @@ -2,7 +2,7 @@ Open a `.cps` file, enter its input in **Input**, and click **Run**. The file is saved before running. Program output and errors appear in **Output**, with compiler errors colored. Click **Stop** to end a running program. -Shortcuts use Cmd on macOS and Ctrl on Windows: **N** new, **Shift+N** new window, **O** open, **S** save, **F** find, **/** toggle line comment. The menu bar lists these commands with their shortcuts: at the top of the screen on macOS, at the top of each window on Windows. Each window has its own file, Input and Run. +Shortcuts use Cmd on macOS and Ctrl on Windows: **N** new, **Shift+N** new window, **O** open, **S** save, **F** find, **/** toggle line comment. **F5** alone runs or stops the program. The menu bar lists these commands with their shortcuts: at the top of the screen on macOS, at the top of each window on Windows. Each window has its own file, Input and Run. Nightly provides a standalone Windows x64 `.exe` and a macOS Apple Silicon `.tar.xz` containing the `.app`. Windows extracts the included `cpsc.exe` into the current working directory on startup; macOS keeps it inside the `.app`. Windows uses the system WebView2 runtime. diff --git a/bundle/src-tauri/src/menu.rs b/bundle/src-tauri/src/menu.rs index 83ba7e3..ab2dd32 100644 --- a/bundle/src-tauri/src/menu.rs +++ b/bundle/src-tauri/src/menu.rs @@ -30,6 +30,10 @@ pub fn build<R: Runtime>(app: &AppHandle<R>) -> tauri::Result<Menu<R>> { .item(&item("find", "Find", "CmdOrCtrl+F")?) .item(&item("comment", "Toggle Line Comment", "CmdOrCtrl+/")?) .build()?; + // Windows share the menu but run independently, so the label covers both states. + let run = SubmenuBuilder::new(app, "Run") + .item(&item("run", "Run/Stop", "F5")?) + .build()?; let window = SubmenuBuilder::new(app, "Window") .minimize() .maximize() @@ -51,5 +55,5 @@ pub fn build<R: Runtime>(app: &AppHandle<R>) -> tauri::Result<Menu<R>> { .quit() .build()?, ); - menu.items(&[&file, &edit, &window]).build() + menu.items(&[&file, &edit, &run, &window]).build() } diff --git a/bundle/src/main.js b/bundle/src/main.js index 9a78ae7..e36b743 100644 --- a/bundle/src/main.js +++ b/bundle/src/main.js @@ -145,7 +145,8 @@ const commands = { open: () => action(openFile), save: () => action(saveFile), find: () => editorAction('actions.find'), - comment: () => editorAction('editor.action.commentLine') + comment: () => editorAction('editor.action.commentLine'), + run: () => running ? invoke('stop_run').catch(report) : action(runFile) }; // CtrlCmd is Cmd on macOS and Ctrl elsewhere, matching Monaco's own keybindings and the menu. const shortcuts = [ @@ -154,19 +155,14 @@ const shortcuts = [ [KeyMod.CtrlCmd | KeyCode.KeyO, 'open'], [KeyMod.CtrlCmd | KeyCode.KeyS, 'save'], [KeyMod.CtrlCmd | KeyCode.KeyF, 'find'], - [KeyMod.CtrlCmd | KeyCode.Slash, 'comment'] + [KeyMod.CtrlCmd | KeyCode.Slash, 'comment'], + [KeyCode.F5, 'run'] ]; try { editor = await createEditor(document.querySelector('#editor')); editor.onDidChangeModelContent(refreshTitle); - runButton.onclick = () => { - if (running) { - invoke('stop_run').catch(report); - } else { - action(runFile); - } - }; + runButton.onclick = commands.run; document.querySelector('#save').onclick = () => action(saveFile); document.querySelector('#new').onclick = () => action(newFile); document.querySelector('#open').onclick = () => action(openFile); |
