std-mumu 0.3.0-rc.8

Standard input/output tools for MuMu/Lava
Documentation
# std-mumu

_Standard input/output & a deep pretty-printer for the Lava/MuMu runtime._

**Crate:** `std-mumu`  
**Repository:** <https://gitlab.com/tofo/std-mumu>  
**License:** MIT OR Apache-2.0 (dual)  
**Engine compatibility:** `core-mumu = 0.9.0-rc.4` (host and wasm builds)

---

## What this plugin provides

`std-mumu` exposes a compact “std” surface for Lava/MuMu scripts:

- `std:put(x)` – print **without** a trailing newline (drains iterators).
- `std:log(x)` – print **with** a trailing newline (drains iterators).
- `std:deep(x)` – emit a **deep, single-line**, MuMu-ish representation and return `x`.
- `std:input([prompt])` – optional prompt, then read a single **line** from `stdin` (host only).
- `std:input_iter()` – a **line iterator** over `stdin` (host only).
- `format(options, data)`**minimal formatter**; prints and returns `data` unchanged. Supports partial application and `_` placeholders.

Works when dynamically loaded at runtime (`extend("std")`) and when statically registered in a host.

---

## Quick taste (minimal examples)

```lava
extend("std")

std:log("Hello, Lava!")      // prints with newline
std:put("no newline"); std:put("\n")

// Deep printer – compact, escaped, single line
std:deep([a: 1, b: ["x", "y"], c: [1.0, 2.5]])

// Read a line (host/native builds)
std:put("Your name: ")
name = std:input()
std:log("Hi " + name + "!")
```

Iterator draining (blocking):

```lava
extend("std")
// 'step' is provided by the core host; this prints 1, 2, 3 each on its own line.
std:log(step(1,4))
```

Minimal formatter:

```lava
extend("std")

// Deep vs shallow
format([deep:true],  [a:[1,2], b:"x"])
format([deep:false], [a:[1,2], b:"x"])

// Quote strings in shallow mode (to see spaces/tabs/newlines)
format([deep:false, quote_strings:true], " hi\t")

// Prefix / suffix / newline control
format([prefix:"=> "], 42)         // "=> 42\n"
format([suffix:" ;"], 42)          // "42 ;\n"
format([newline:false], 42)        // "42"
```

> `std:put`/`std:log` **drain** iterators synchronously. Use the core `slog`/`sput` non‑blocking pollers when you need background progress in a REPL/UI loop.

---

## Minimal `format` API

`format(options, data) -> data`

A *very* small option set — no trees, no frames, no colors, no wrapping:

- `deep` (bool, default **true**) — deep, single‑line representation (quotes + escapes for strings).  
  If `false`, use a shallow form similar to `std:put`.
- `newline` (bool, default **true**) — print with newline; `false` prints without `\n`.
- `prefix` (string, default `""`) — prepend once to the first line.
- `suffix` (string, default `""`) — append once at the end.
- `quote_strings` (bool, default **false**) — when `deep:false`, quote/escape string **leaves** so spaces/tabs/newlines are visible. (Deep mode already quotes.)

**Partial application & `_` placeholders** are supported:

- `format(_)` → returns a function expecting `(options, data)`  
- `format(opts)` → returns a function expecting `data`  
- `format(_, data)` → returns a function expecting `options`  
- `format(opts, data)` → formats immediately

All legacy options (tree view, colors, numbering, frame, wrapping, timestamps, help, etc.) were **removed** for simplicity.

---

## Host vs Web (wasm) behavior

`std-mumu` builds for both native hosts and wasm targets. Input is intentionally **stubbed** on the web:

| Function         | Native (host)                       | Web/wasm (browser)                                |
|------------------|-------------------------------------|----------------------------------------------------|
| `std:input`      | ✅ reads from `stdin`               | ❌ error: `std:input is unavailable in this build` |
| `std:input_iter` | ✅ line iterator over `stdin`       | ❌ error: `std:input_iter is unavailable`          |
| `std:put`        | ✅ print + push to print buffer     | ✅ print buffer updated                            |
| `std:log`        | ✅ print newline + push buffer      | ✅ print buffer updated                            |
| `std:deep`       | ✅ deep printer                     | ✅ deep printer                                    |
| `format`         | ✅ minimal formatter                | ✅ formatter                                       |

---

## Dynamic & static integration

- **Dynamic (preferred):** the shared library exports `Cargo_lock`. Hosts that support `extend("…")` can load the plugin at runtime:

  ```lava
  extend("std")
  std:log("OK")
  format([deep:false], [a:1, b:[2,3]])
  ```

- **Static:** hosts can call `register_all(interp)` to make the functions available without dynamic loading.

---

## License

Dual-licensed under either of:

- MIT License — see `LICENSE`
- Apache License, Version 2.0 — see `LICENSE`

You may choose either license.