From ed77d1d34a1cc24bb3b1f90af83b7f853f523074 Mon Sep 17 00:00:00 2001 From: tmhglnd Date: Wed, 17 Jul 2024 22:12:06 +0200 Subject: [PATCH 1/3] added dummy repl, no syntax, sends code to port 3001 /flok, updated docs --- README.md | 27 ++++++++++++++++++++++++++ packages/repl/lib/index.ts | 2 ++ packages/web/src/components/editor.tsx | 6 ++++-- packages/web/src/settings.json | 9 ++++++--- 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 76d781d7..fbc44128 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,15 @@ Web-based P2P collaborative editor for live coding music and graphics ## Usage +### Shortkeys + +| Keymap | Function | +| - | - | +| `Alt/Option` `Enter` | Evaluate all | +| `Ctrl/Cmd` `Enter` | Evaluate block, Evaluate selection | +| `Shift` `Enter` | Evaluate line | +| `Ctrl/Cmd/Option/Alt` `.` | Silence (output depends on language) | + ### Public server **WARNING - Please Read**: Using a public server can be dangerous as *anyone* @@ -138,6 +147,14 @@ connect to your local server, because of their own network configuration. ### Supported REPL targets +#### Dummy + +The Dummy target as a REPL target that does not have any syntax-highlighting and can be used for any purpose you like (for example if you like to use a language that is not yet supported in flok). + +Use `flok-repl` with the `-t dummy` parameter. + +You can now receive the code you evaluate on port `3001`. The code is send as a string (including all the linebreaks, whitespaces, etc) on the osc-address `/flok`. If you use the `panic` shortkey you will receive the osc-message `/flok silence`. You can use this to stop all your audio/visual processes. + #### TidalCycles Use `flok-repl` with the `-t tidal` parameter. @@ -261,6 +278,16 @@ To run production build: npm start ``` +To run the repl while developing go to: + +```sh +cd packages/repl/ +``` + +```sh +npm exec -- flok-repl -H ws://localhost:3000 -s -t -T user: +``` + ### Packages overview This repository is a monorepo, with multiple modular packages. Each package diff --git a/packages/repl/lib/index.ts b/packages/repl/lib/index.ts index 0134b4b6..5a872b53 100644 --- a/packages/repl/lib/index.ts +++ b/packages/repl/lib/index.ts @@ -10,6 +10,7 @@ import FoxDotREPL from "./repl/foxdot.js"; import RenardoREPL from "./repl/renardo.js"; import MercuryREPL from "./repl/mercury.js"; import SardineREPL from "./repl/sardine.js"; +import DummyREPL from "./repl/dummy.js"; import path from "path"; import fs from "fs"; @@ -23,6 +24,7 @@ const replClasses = { renardo: RenardoREPL, mercury: MercuryREPL, sardine: SardineREPL, + dummy: DummyREPL }; function createREPLFor(repl: string, ctx: CommandREPLContext) { diff --git a/packages/web/src/components/editor.tsx b/packages/web/src/components/editor.tsx index 8b67ed46..2ed1880f 100644 --- a/packages/web/src/components/editor.tsx +++ b/packages/web/src/components/editor.tsx @@ -164,12 +164,14 @@ export const Editor = React.forwardRef( const readOnly = !!query.get("readOnly"); const language: string = langByTarget[document.target] || defaultLanguage; - const languageExtension = langExtensionsByLanguage[language] || javascript; + // if language is not defined choose null (no syntax highlighting is added) + const languageExtension = langExtensionsByLanguage[language] || null; const extensions = [ baseTheme, flokSetup(document, { readOnly }), - languageExtension(), + // only add languageExtension if a function + languageExtension ? languageExtension() : [], highlightExtension, readOnly ? EditorState.readOnly.of(true) : [], toggleWith("shift-ctrl-l", lineNumbers()), // toggle linenumbers on/off diff --git a/packages/web/src/settings.json b/packages/web/src/settings.json index 4d44a158..cac0c220 100644 --- a/packages/web/src/settings.json +++ b/packages/web/src/settings.json @@ -8,7 +8,8 @@ "sardine", "sclang", "strudel", - "tidal" + "tidal", + "dummy" ], "defaultTarget": "hydra", "langByTarget": { @@ -20,7 +21,8 @@ "sardine": "python", "sclang": "javascript", "strudel": "javascript", - "tidal": "tidal" + "tidal": "tidal", + "dummy": "none" }, "targetsWithDocumentEvalMode": ["mercury", "mercury-web", "strudel"], "panicCodes": { @@ -33,7 +35,8 @@ "mercury-web": "silence", "hydra": "hush()", "strudel": "silence", - "sardine": "panic()" + "sardine": "panic()", + "dummy" : "silence" }, "webTargets": ["hydra", "strudel", "mercury-web"], "repoUrl": "https://github.com/munshkr/flok", From f4143fa50d3af66319285c68e105d4b983357b17 Mon Sep 17 00:00:00 2001 From: tmhglnd Date: Wed, 17 Jul 2024 22:46:43 +0200 Subject: [PATCH 2/3] updated doc --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index fbc44128..d79ba90b 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,8 @@ Web-based P2P collaborative editor for live coding music and graphics ### Shortkeys +*Some shortkeys may differ depending on the language/target you choose* + | Keymap | Function | | - | - | | `Alt/Option` `Enter` | Evaluate all | From a9a14cf6dd34591de8d78ae63e3f2a60d9fa1f84 Mon Sep 17 00:00:00 2001 From: tmhglnd Date: Wed, 17 Jul 2024 23:12:25 +0200 Subject: [PATCH 3/3] added some more shortkeys found by trial/error --- README.md | 37 ++++++++++++--- packages/repl/lib/repl/dummy.ts | 81 +++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+), 7 deletions(-) create mode 100644 packages/repl/lib/repl/dummy.ts diff --git a/README.md b/README.md index d79ba90b..083c78e3 100644 --- a/README.md +++ b/README.md @@ -25,16 +25,39 @@ Web-based P2P collaborative editor for live coding music and graphics ## Usage -### Shortkeys +### Keybindings -*Some shortkeys may differ depending on the language/target you choose* +*Some keybindings may differ depending on the language/target you choose* -| Keymap | Function | +| Keybinding | Function | | - | - | -| `Alt/Option` `Enter` | Evaluate all | -| `Ctrl/Cmd` `Enter` | Evaluate block, Evaluate selection | -| `Shift` `Enter` | Evaluate line | -| `Ctrl/Cmd/Option/Alt` `.` | Silence (output depends on language) | +| `alt/option` `enter` | Evaluate all | +| `ctrl/cmd` `enter` | Evaluate block, Evaluate selection | +| `shift` `enter` | Evaluate line | +| `ctrl/cmd/option/alt` `.` | Silence (output depends on language) | +| `cmd/ctrl` `shift` `h` | Show/Hide editor panels | +| `cmd/ctrl` `x` | Cut selected text | +| `cmd/ctrl` `c` | Copy selected text | +| `cmd/ctrl` `v` | Paste cut/copied text | +| `cmd/ctrl` `z/u` | Undo edit | +| `cmd/ctrl` `shift` `z/u` | Redo edit | +| `cmd/ctrl` `}` | add indentation | +| `cmd/ctrl` `{` | remove indentation | +| `cmd/ctrl` `f` | search and replace | + + ### Public server diff --git a/packages/repl/lib/repl/dummy.ts b/packages/repl/lib/repl/dummy.ts new file mode 100644 index 00000000..d0849858 --- /dev/null +++ b/packages/repl/lib/repl/dummy.ts @@ -0,0 +1,81 @@ +import { BaseREPL, BaseREPLContext } from "../repl.js"; +import osc from "osc"; +import debugModule from "debug"; + +const debug = debugModule("flok:repl:dummy"); + +const { UDPPort } = osc; + +// A dummy/free/open REPL +// The repl doesn't have any specific language, it just forwards the +// text to an assigned OSC port 3001 +// The address used is /flok + +// $ flok-repl -t free +// +// Sends the code over OSC to port 3001 on localhost +// Port can be assigned by choice +// +class DummyREPL extends BaseREPL { + udpPort: typeof UDPPort; + port: number; + started: boolean; + portReady: boolean; + + constructor(ctx: BaseREPLContext) { + super(ctx); + + this.port = 3001; + this.started = false; + this.portReady = false; + } + + start() { + super.start(); + + this.udpPort = new UDPPort({ + metadata: true, + }); + + // Listen for incoming OSC messages. + this.udpPort.on("message", function (oscMsg, timeTag, info) { + debug("An OSC message just arrived!", oscMsg); + debug("Remote info is: ", info); + }); + + // Open the socket. + this.udpPort.open(); + + // When the port is read, send an OSC message + const that = this; + this.udpPort.on("ready", function () { + that.portReady = true; + }); + + this.started = true; + } + + write(body: string) { + if (!this.portReady) { + debug("UDP Port is not ready yet."); + return; + } + + const newBody = this.prepare(body); + const obj = { + address: "/flok", + args: [ + { + type: "s", + value: newBody, + }, + ], + }; + this.udpPort.send(obj, "127.0.0.1", this.port); + + const lines = newBody.split("\n"); + this.emitter.emit("data", { type: "stdin", lines }); + } +} + +export default DummyREPL; \ No newline at end of file