Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dummy REPL added as target option #291

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,40 @@ Web-based P2P collaborative editor for live coding music and graphics

## Usage

### Keybindings

*Some keybindings may differ depending on the language/target you choose*

| 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) |
| `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 |

<!-- On Mac (not tested on Windows/Linux)

| `ctrl` `e` | jump to end of the line |
| `ctrl` `a` | jump to the beginning of the line |
| `ctrl` `t` | move character one step right |
| `ctrl` `y` | delete selected text |
| `ctrl` `o` | insert linebreak |
| `ctrl` `d` | delete character on the right of cursor |
| `ctrl` `h` | backspace character on the left of cursor |
| `ctrl` `l` | select whole line after cursor |
| `ctrl` `v` | jump to bottom end |
| `ctrl` `b` | move cursor to the left |
| `ctrl` `n` | move cursor down | -->

### Public server

**WARNING - Please Read**: Using a public server can be dangerous as *anyone*
Expand Down Expand Up @@ -138,6 +172,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.
Expand Down Expand Up @@ -261,6 +303,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 <session> -t <target> -T user:<name>
```

### Packages overview

This repository is a monorepo, with multiple modular packages. Each package
Expand Down
2 changes: 2 additions & 0 deletions packages/repl/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -23,6 +24,7 @@ const replClasses = {
renardo: RenardoREPL,
mercury: MercuryREPL,
sardine: SardineREPL,
dummy: DummyREPL
};

function createREPLFor(repl: string, ctx: CommandREPLContext) {
Expand Down
81 changes: 81 additions & 0 deletions packages/repl/lib/repl/dummy.ts
Original file line number Diff line number Diff line change
@@ -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;
6 changes: 4 additions & 2 deletions packages/web/src/components/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions packages/web/src/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"sardine",
"sclang",
"strudel",
"tidal"
"tidal",
"dummy"
],
"defaultTarget": "hydra",
"langByTarget": {
Expand All @@ -20,7 +21,8 @@
"sardine": "python",
"sclang": "javascript",
"strudel": "javascript",
"tidal": "tidal"
"tidal": "tidal",
"dummy": "none"
},
"targetsWithDocumentEvalMode": ["mercury", "mercury-web", "strudel"],
"panicCodes": {
Expand All @@ -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",
Expand Down
Loading