Add edit program
This commit is contained in:
@@ -28,7 +28,7 @@ Bare OS picks: **one swarm topic** for the project, **Protomux** channels for co
|
||||
| **Personal drive** | Separate Hyperdrive (Corestore namespace) for `$HOME`, `/.bare`, cron, logs |
|
||||
| **MBR** | 512 bytes: magic `BIOS` + embedded Hyperdrive **public keys** (primary + optional failover) |
|
||||
| **Kernel** | `/boot/init.js` — `async function start(ctx)`; not a microkernel, a **session loop** |
|
||||
| **/bin** | Small JS programs (`async function run(ctx, argv)`) built from **bare-os-coreutils** |
|
||||
| **/bin** | Small JS programs (`async function run(ctx, argv)`) built from **bare-os-coreutils** — includes a TTY editor (**`edit`**, **`nano`**) and usual POSIX-style tools |
|
||||
| **VFS** | Booter-provided path layer: routes paths under `$HOME` to the **personal** drive, else **system** |
|
||||
| **ctx** | Context object passed to kernel and commands: `vfs`, `console`, `execLine`, identity hooks, etc. |
|
||||
| **Guest** | Default session before `login` — predictable `HOME=/home/guest`, no Ed25519 identity |
|
||||
|
||||
@@ -89,7 +89,7 @@ Work is sequenced for **POSIX/script ergonomics first**, then networking and lon
|
||||
|
||||
- Tokenizes words, quotes, escapes, **`$VAR`**, pipelines **`|`**, redirections **`>` / `>>` / `<`**.
|
||||
- Builtins: **`alias`**, **`unalias`**, **`cd`**, **`export`**, **`unset`**, **`readonly`**, **`umask`**, **`:`**, **`command`**, **`type`**, **`login`**, **`logout`**, **`exit`** — plus external commands via **`runBinCommand`**. **`readonly`** blocks **`export`** and assignment writes to the same name; **`command -v` / `-V`** and **`type`** use **`resolveBinInPath`** for **`PATH`** lookup.
|
||||
- First-word **aliases** (defaults like **`ll` → `ls -la`**) expand after **`$VAR`** substitution; **`alias`** / **`unalias`** match the restricted **`~/.barerc`** syntax (not full POSIX **`sh`**).
|
||||
- First-word **aliases** (defaults like **`ll` → `ls -la`**, **`nano` → `edit`**) expand after **`$VAR`** substitution; **`alias`** / **`unalias`** match the restricted **`~/.barerc`** syntax (not full POSIX **`sh`**).
|
||||
- Pipes capture **`console.log`** into the next stage or a string sink.
|
||||
|
||||
**`runBinCommand`** (`lib/kernel-runner.js`):
|
||||
@@ -98,7 +98,7 @@ Work is sequenced for **POSIX/script ergonomics first**, then networking and lon
|
||||
2. Else if the name **ends with `.js`** — resolve **`$PWD/name.js`** first (same as explicit `./` for many cases).
|
||||
3. Else walk **`PATH`** on the **system** drive only.
|
||||
|
||||
**`runScriptFromSource`** strips an optional **`#!`** line, requires **`async function run(ctx, argv)`**, and **catches** errors—logs to **`ctx.console.error`** without unwinding the kernel loop.
|
||||
**`runScriptFromSource`** strips an optional **`#!`** line, runs the script body as top-level code in an async function, then **awaits** a top-level **`run(ctx, argv)`** if one is defined (optional for user scripts; **`/bin`** utilities always define **`run`**). It **catches** errors—logs to **`ctx.console.error`** without unwinding the kernel loop.
|
||||
|
||||
**`runKernelFromSource`** requires **`async function start(ctx)`** at the top level of `/boot/init.js`.
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ Replacing **`/boot/init.js`** on the system image is supported: the booter loads
|
||||
```
|
||||
packages/bare-os-coreutils/lib/runtime.js
|
||||
+
|
||||
(optional) packages/bare-os-coreutils/lib/<engine>.js ← sed-engine, awk-engine
|
||||
(optional) packages/bare-os-coreutils/lib/<engine>.js ← sed-engine, awk-engine, edit-*.js, …
|
||||
+
|
||||
packages/bare-os-coreutils/src/<cmd>.js
|
||||
↓ (build.mjs, see preamble map)
|
||||
@@ -59,7 +59,7 @@ kernel/bin/<cmd>
|
||||
packages/bare-os-seeder/kernel/bin/<cmd> ← Pear vendored copy
|
||||
```
|
||||
|
||||
**Rule:** no `import` in `src/*.js` — only `async function run(ctx, argv)` (shared helpers live in **`lib/runtime.js`**). Large **`sed`** and **`awk`** bodies live in **`lib/*-engine.js`** and are prepended at build time (same global scope as **`run`**).
|
||||
**Rule:** no `import` in `src/*.js` — only `async function run(ctx, argv)` (shared helpers live in **`lib/runtime.js`**). Large **`sed`** and **`awk`** bodies live in **`lib/*-engine.js`** and are prepended at build time (same global scope as **`run`**). **`edit`** and **`nano`** share the same **`src/edit.js`** and **`lib/edit-*.js`** preamble; **`/bin/nano`** is a separate staged name for familiarity (default shell alias **`nano` → `edit`**).
|
||||
|
||||
**Full POSIX-style catalog, stubs, and divergence notes:** [Chapter 9 — POSIX utilities, shell, and VFS](09-posix-utilities-shell-and-vfs.md).
|
||||
|
||||
@@ -80,6 +80,7 @@ Hyperdrive entries carry optional **`metadata.bareOs`** (mode, uid, gid, names,
|
||||
| `crontab` | `-l` list, `-r` remove, `<file>` install (`~/.crontab`; writes need login) |
|
||||
| `date` | Date/time |
|
||||
| `echo`, `printf`-like simplicity | Args to stdout |
|
||||
| `edit`, `nano` | TTY full-screen buffer editor (same source for both **`/bin`** names; stock alias **`nano` → `edit`**); requires real TTY — see [ch. 9 §5.2a](09-posix-utilities-shell-and-vfs.md) |
|
||||
| `env`, `printenv` | Environment |
|
||||
| `exit` | Sets exit code / session end via booter |
|
||||
| `false`, `true` | Status |
|
||||
|
||||
@@ -129,6 +129,13 @@ Sources: **`packages/bare-os-coreutils/src/<name>.js`**. **Authoritative list:**
|
||||
| **`awk`** | Substantial interpreter — see §7. |
|
||||
| **`grep`** | **`-F`** fixed strings, **`-i`**, **`-v`**, **`-w`**, **`-x`**, **`-n`**, **`-c`**, **`-l`**, **`-o`**, **`-m`**, **`-e`**, **`-f`**, etc.; JS **`RegExp`** (not PCRE / full GNU). |
|
||||
|
||||
### 5.2a TTY text editor (`edit` / `nano`)
|
||||
|
||||
| Command | Notes |
|
||||
| --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| **`edit`** | Full-screen in-terminal editor over **`ctx.vfs`**: multi-line buffer, search / goto / save-as, optional syntax highlighting. Requires **`stdout.isTTY`**; exits with a clear error if stdin/stdout is not a TTY. Source: **`src/edit.js`** with preamble **`lib/edit-ansi.js`**, **`edit-highlight.js`**, **`edit-buffer.js`**, **`edit-key-parse.js`**, **`edit-tui.js`**. |
|
||||
| **`nano`** | Same built artifact as **`edit`** (**`build.mjs`** maps **`nano`** → **`src/edit.js`** and the same preamble). **`/bin/nano`** is installed for muscle memory; the default shell alias **`nano` → `edit`** (see **`defaultShellAliases`** in **`shell.js`**) makes **`nano`** invoke that binary. **`man edit`** and **`man nano`** describe flags and keys. |
|
||||
|
||||
### 5.3 Discovery and measurement
|
||||
|
||||
| Command | Notes |
|
||||
@@ -182,8 +189,8 @@ All other commands from **`build.mjs`** not listed here follow the summaries in
|
||||
**[`build.mjs`](../packages/bare-os-coreutils/build.mjs)** concatenates:
|
||||
|
||||
1. **`lib/runtime.js`**
|
||||
2. Optional extra libs from the **`preamble`** map (**`sed` → `sed-engine.js`**, **`awk` → `awk-engine.js`**)
|
||||
3. **`src/<cmd>.js`**
|
||||
2. Optional extra libs from the **`preamble`** map (**`sed` → `sed-engine.js`**, **`awk` → `awk-engine.js`**, **`jq` → `jq-engine.js`**, **`man` → `man-render.js`**, **`ls` / `dircolors` → lscolors**, **`edit` / `nano` → `edit-*.js`** TUI stack)
|
||||
3. **`src/<cmd>.js`** ( **`nano`** uses **`src/edit.js`** )
|
||||
|
||||
There is still **no `import`** in **`src/*.js`** — large utilities are **vendored as plain script** chunks in **`lib/`**.
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ The merged **`man.json`** adds **`schemaVersion`**, **`generatedAt`**, **`pages`
|
||||
|
||||
## Relationship to **`help`**
|
||||
|
||||
**`/bin/help`** prints a **compact one-screen** list of builtins and **`/bin`** names. **`man`** is the **long-form** reference. Users are encouraged to run **`man handbook`** for the full narrative handbook, **`man bare-os-shell`** for builtins, and **`man <command>`** for **`/bin`** utilities.
|
||||
**`/bin/help`** prints a **compact one-screen** list of builtins and **`/bin`** names (including **`edit`** and **`nano`**). **`man`** is the **long-form** reference — e.g. **`man edit`**, **`man nano`**, **`man bare-os-shell`**. Users are encouraged to run **`man handbook`** for the full narrative handbook and **`man <command>`** for each utility.
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user