# EditBench

A desktop editor for Linux and Windows, for text, source files and binary data, written in Rust against the
functional specification in [`spec/`](spec/SPECIFICATION.md). The interface follows TermBench
Terminal: the same Studio palette, Inter interface font, Fugue full-colour toolbar icons (CC BY 3.0), painted tab
strip, status bar and settings window.

## Building and running

```sh
cargo build --release
./target/release/editbench [-r] [-p] [-m SPEC] [-s SPEC] [FILE[:LINE[:COLUMN]]]... [-- FILE [--lcLINE:COLUMN]...]
```

| Option | Meaning |
| --- | --- |
| `-r` | Open the files read-only. |
| `-p` | Print the files to the default printer and exit. |
| `-m [e,][count,][name,]FILE` | Load a macro collection and run a macro. |
| `-s [e,]FILE` | Run a JavaScript file. |
| `--new-instance` | Do not hand the files to a running instance. |

For Windows, `scripts/build-windows.sh` cross-compiles from Linux (MinGW) and makes an installer
and a portable ZIP; see the Windows section of LIMITATIONS.md.

Settings live in `~/.config/editbench/` (`%APPDATA%\editbench` on Windows) (`config.toml`, plus accounts, macros, templates and
recovery files). `EDITBENCH_CONFIG_DIR=` (set but empty) keeps everything in memory, which is
useful for testing.

Optional programs, used when present: `aspell` (spell check), `tidy`, `xmllint`, `ctags`,
`git`, `secret-tool` (saved passwords), `gio` (Trash), `lp`/`lpstat` (printing), `fc-list`
(font list), `curl` (update check), `pkexec` (installing an update from the .deb).

## What it does

All 372 catalog commands are implemented; see [LIMITATIONS.md](LIMITATIONS.md) for known
gaps and for what has and has not been verified by hand.

- **Editing:** rope buffer, grouped undo, multiple carets, column mode, word wrap, folding,
  bookmarks, split views, 29 highlighted languages, ten themes, ruler, document map.
- **Files:** 149 encodings, exact line terminators, safe saving, conflict and crash recovery,
  hex editing, a disk-backed viewer for very large files, encryption, printing.
- **Search:** literal, caret, Unix-style and Perl-compatible expressions; Find and Replace in
  Files; Quick Open; Find Symbol.
- **Text tools:** compare with merge, advanced sort, paragraph and column operations, JSON
  and XML formatting with structure panels, HTML toolbar, Markdown preview, spell check.
- **Workspace:** projects with backup and restore, File View, Git toolbar and console.
- **Remote:** FTP, FTPS and SFTP browsing, remote open and save, SSH and Telnet console.
- **Automation:** recorded and written macros, JavaScript scripts, external tools, templates.

## Layout

| Path | What it holds |
| --- | --- |
| `crates/editbench-search` | The query model and four dialects on PCRE2, replacement templates, Find in Files. |
| `crates/editbench-io` | The encoding registry, decoding and encoding, file identity, safe saving. |
| `crates/editbench-text` | Diff, sort, paragraph and column operations, XML and JSON trees, HTML transforms. |
| `crates/editbench-automation` | Macro language and player, QuickJS script host, external tools, templates. |
| `crates/editbench-remote` | FTP/FTPS and SFTP clients, known hosts, SSH and Telnet sessions, safe remote save. |
| `src/catalog.rs` | Reads `spec/COMMANDS.md` at build time: menus and keymap come from the catalog. |
| `src/doc.rs`, `view.rs`, `editor.rs`, `hex.rs` | Documents, views and the painted editing surfaces. |
| `src/app.rs`, `commands.rs`, `files.rs`, `find.rs`, `panels.rs` | The window, command dispatch, file lifecycle, search and dialogs. |
| `src/textops.rs`, `workspace.rs`, `project.rs`, `extras.rs`, `more.rs`, `devtools.rs` | Text tools, projects and Git, smaller commands, encryption, printing, preview, terminal, formatter, validator. |
| `src/remote_ui.rs`, `automation_ui.rs` | The remote and automation interfaces. |

## craft-libs

Used from `storytold/craft-libs` at commit `fab4570`, with the Craft forks of egui and winit
(patched in `Cargo.toml`, as in the craft-libs workspace): `craft-ui` (icons, buttons, tabs,
splits, palette, fonts), `craft-menu`, `craft-keymap` (bindings and the Keyboard Shortcuts
dialog), `craft-dialogs`, `craft-settings`, `craft-atomic`, `craft-quit`, `craft-zip` (project
backups) and `craft-print`.

## Tests

`cargo test --workspace` runs about 300 tests. The remote clients are tested against
in-process loopback servers. `crates/editbench-remote/tests/manual_fixture.rs` serves a loopback
FTP account for trying the remote interface by hand.

Third-party licences are in `third_party/licenses/`.
