asciitorium
Version:
an ASCII ui framework for web + cli
182 lines (128 loc) ⢠4.22 kB
Markdown
# asciitorium
**asciitorium** is a UI framework for building retro terminal interfaces that fully function in the browser as well as the terminal.
Why? I am still not sure š. But it started with wanting to create a text-based game reminiscent of **Wizardry I**, **Zork**, and **Bard's Tale** from the 80s. I realized it would be fun to create a UI framework while I was at it ā given my experience with React, here is that first pass.
## Installation
```bash
npm install asciitorium
```
## Quick Start
### Basic Example
```tsx
import { App, Text, TextInput, State, start } from 'asciitorium';
const message = new State('Hello, World!');
const app = (
<App width={50} height={10}>
<Text value="Enter your message:" />
<TextInput value={message} width={40} />
<Text value={message} />
</App>
);
await start(app);
```
### JSX Configuration
Add to your `tsconfig.json`:
```json
{
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "asciitorium/jsx"
}
}
```
## Use Cases
- Terminal-style web apps
- ASCII dashboards
- Text-driven games
- BBS-inspired experiments
- Developer tools with retro aesthetics
## Features
- Support for TypeScript
- Works in both **Web** and **CLI** (DOM or stdout)
- Built-in components (`Text`, `Button`, `ListBox`, `ProgressBar`, etc.)
- Reactive `State<T>` system for live updates
- Custom JSX runtime (like React, minus the baggage)
## Built-in Components
- **`Text`** - Display static or dynamic text
- **`Button`** - Interactive buttons with click handlers
- **`TextInput`** - Text input fields
- **`ListBox`** - Selectable lists with keyboard navigation
- **`ProgressBar`** - Visual progress indicators
- **`Tabs`** - Tabbed interface containers
- **`HorizontalLine`** - Decorative dividers
- **`AsciiArt`** - Display ASCII art from files
- **`CelticBorder`** - Decorative borders
### Layout Components
- **`HorizontalLayout`** - Arrange components horizontally
- **`VerticalLayout`** - Arrange components vertically (default)
---
## š Developing
### 1ļøā£ Install dependencies
```bash
npm install
```
### 2ļøā£ Run in the browser (Web mode)
```bash
npm run web
```
- Starts the Vite dev server
- Open your browser at **http://localhost:5173** (or the port Vite displays)
- Uses the `DomRenderer` to draw into a `<pre>` block
### 3ļøā£ Run in the terminal (CLI mode)
```bash
npm run cli
```
- Renders directly to stdout
- Uses the `TerminalRenderer` for an interactive terminal UI
### 4ļøā£ Build for production
```bash
npm run build
```
- Builds both the browser bundle and TypeScript definitions
### 5ļøā£ Preview the production build
```bash
npm run preview
```
- Serves the `dist/` output locally using Vite
### 6ļøā£ Format the code
```bash
npm run format
```
- Runs Prettier across the entire project
### 7ļøā£ Generate FIGlet ASCII art assets
```bash
npm run art FIGlet-font-name "phrase"
```
- Runs the `scripts/generate-art.js` tool to build `.txt` ASCII art files
To list available FIGlet fonts:
```bash
npm run art:fonts
```
---
## š Project Structure
```txt
asciitorium/
āāā src/ # Core source code
ā āāā components/ # UI components (Text, Button, etc.)
ā āāā core/ # Core framework code
ā ā āāā layouts/ # Layout components
ā ā āāā renderers/ # DOM and Terminal renderers
ā āāā jsx/ # Custom JSX runtime
ā āāā demo.tsx # Demo application
āāā public/ # Static assets
ā āāā art/ # ASCII art files (.txt)
ā ā āāā asciitorium.txt
ā āāā fonts/ # Custom fonts (.ttf, .woff, .woff2)
ā ā āāā PRNumber3.* # Monospace font files
ā ā āāā PrintChar21.* # Pixel-style font files
ā āāā images/ # Image assets
āāā scripts/ # Helper scripts
ā āāā generate-art.js # ASCII art generator
āāā package.json
āāā README.md
```
---
## š Changelog
See [CHANGELOG.md](../../CHANGELOG.md) for detailed release notes and migration guides.
---
## š License
MIT