Skip to content

dionxe/browser-ed

Repository files navigation

Ed in the browser

A port of GNU ed to the browser.

Ed is a UNIX text editor from a time computer consoles resembled typewriters called teletypes. Some have called it the most user-hostile editor ever created. You can’t see the document and it replies an unhelpful ? to almost everything.

This project is a curiosity to simulate what it was like to edit text on a teletype and share that experience with others. Note that ed is the spiritual predecessor of vi. Some commands you might recognize.

Check the live demo

Features

  • GNU ed compiled to WebAssembly
  • Teletype simulation in browser input field

Installation

Prerequisites

  • Emscripten SDK (Tested with 4.0.18)
  • Python 3

Build

# Clone the repository
git clone https://github.com/dionxe/browser-ed.git
cd browser-ed

# Build the WebAssembly module and Javascript runtime
./configure
make

# Serve locally for testing
python3 serve_isolated.py

Usage

Basic integration in an HTML document requires an ed-output element to display text output and an ed-input input element for input. Like so:

<html lang="en">
<head>
    <title>ed - WebAssembly Text Editor</title>
</head>
<body>
    <div id="ed-output"></div>
    <input type="text" id="ed-input" placeholder="Enter ed commands...">
    <script src="ed.js"></script>
</body>
</html>

This is application uses SharedArrayBuffer to provide input to ed. For this feature to work in the browser the page must be served in a secure context and cross-origin isolated. This means the page must be served via localhost or over HTTPS with Cross-Origin-Embedder-Policy and Cross-Origin-Opener-Policy headers.

For more information on how to use ed check the ed man page

Port details

Emscripten compiles the C source code to WebAssembly and implements the C standard library in the browser runtime, ed.wasm and ed.js respectively.

ed is designed for synchronous interaction, blocking while it waits for user input. In the browser blocking the main Javascript thread would make the page unresponsive. Instead this is implemented by running ed in a Web Worker, write input to a SharedArrayBuffer, and using the Atomics API to block the worker.

License

This project derivative of GNU and is therefore licensed under the GNU General Public License v2.0 - see the COPYING file for details.

Acknowledgments

About

GNU ed in the browser

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published