npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

hakoniwa-term

v0.0.6

Published

A robust, pluggable retro terminal engine for React, powered by CSS Modules and Async Generators.

Readme

hakoniwa-term (箱庭-term)

A programmable, retro hacker-style terminal UI engine for React applications, powered by Async Generators and CSS Modules with total style isolation.

English | 日本語

npm version license


🪴 What is Hakoniwa (箱庭)?

In Japanese, 「箱庭(はこにわ / hakoniwa)」 literally means “box garden.”
It refers to a small, self-contained miniature garden or landscape arranged inside a box or tray—like tiny rocks, plants, and buildings forming a little self-contained world you can observe and interact with.

hakoniwa-term brings that miniature, self-contained concept to terminal UIs in React.


📷 Screenshot & Demo

screenshot


✨ Features

  • ⚡ Async Generator Commands: Easily stream logs, output step-by-step responses, or trigger real-time progress bar animations using simple async function* yield syntax.
  • 🎨 Built-in Themes & Customization: Comes with 6 pre-built retro presets (emerald, matrix, dracula, amber, cyberpunk, light) and supports custom color overrides via Dynamic CSS Variables.
  • 🔒 Style Isolation: Built using CSS Modules—zero CSS leaks into your global styles or main app layout.
  • ⏳ Built-in Progress Bar: Stream live % progress updates directly from command generators.
  • 🔐 System Locking: Disables input during command execution to prevent race conditions.
  • 🧹 Built-in Utilities: Automatic clear command support.
  • 📘 TypeScript Native: Full type safety for props, logs, yield chunks, presets, and command handlers.

📦 Installation

Install hakoniwa-term using your favorite package manager:

npm install hakoniwa-term lucide-react
# or
pnpm add hakoniwa-term lucide-react
# or
yarn add hakoniwa-term lucide-react

Note: lucide-react is required for terminal icons. react and react-dom (>= 18.0.0) are peer dependencies.


🚀 Quick Start

  1. Import the Terminal component.
  2. Import the bundled CSS stylesheet (hakoniwa-term/dist/index.css).
  3. Map your commands using async generator functions.
import React from "react";
import { Terminal } from "hakoniwa-term";
import type { CommandAction } from "hakoniwa-term";

import "hakoniwa-term/dist/index.css";

export default function App() {
  const commands: Record<string, CommandAction> = {
    // Simple greeting command
    hello: async function* (args) {
      const name = args[1] || "Guest";
      yield {
        type: "log",
        log: { type: "success", text: `✨ Welcome aboard, ${name}!` },
      };
    },

    // Info command
    system: async function* () {
      yield {
        type: "log",
        log: { type: "output", text: "System status: Operational" },
      };
      yield {
        type: "log",
        log: { type: "output", text: "Kernel: hakoniwa-v0.0.3" },
      };
    },
  };

  return (
    <div style={{ padding: "2rem", height: "100vh", background: "#020204" }}>
      <Terminal
        commands="{commands}"
        placeholder="Type 'hello [name]' or 'system'..."
        preset="dracula"
        promptString="user@hakoniwa:~$ "
        title="guest@hakoniwa:~"
      />
    </div>
  );
}

🎨 Built-in Themes & Customization

hakoniwa-term includes 6 built-in presets out of the box and allows seamless color overrides using the theme prop.

Available Presets

| Preset | Aesthetic Description | | --------------------- | --------------------------------------------------------------------- | | emerald (default) | Classic dark theme with vibrant emerald green prompt accents. | | matrix | Neon green monochrome inspired by 90s cyber aesthetics. | | dracula | Popular dark purple theme with vibrant pink and cyan highlights. | | amber | CRT amber monitor aesthetic with warm yellow-orange hues. | | cyberpunk | High-contrast dark blue with neon cyan, yellow, and magenta accents. | | light | Clean, modern light mode with high contrast for daytime applications. |

1. Using a Preset

Simply pass the preset prop to the Terminal component:

<Terminal commands={commands} preset="matrix" />

2. Customizing Specific Colors (Partial Override)

You can override specific theme colors while keeping the base preset for everything else:

<Terminal
  commands={commands}
  preset="dracula"
  theme={{
    prompt: "#00f0ff",
    progress: "#ff0055",
  }}
/>

🧪 Example: hakoniwa-sample-3

https://github.com/user-attachments/assets/14330583-4141-4269-a055-b41c94f8addb

The example/hakoniwa-sample-3 project is an interactive preset playground. Use the preset selector or run these commands in the terminal:

  • help — show the available commands
  • preset <name> — switch between the built-in presets
  • deploy — stream deployment logs and progress updates
  • clear — clear the terminal history

It also demonstrates overriding the prompt color with the theme prop. Start it from the repository root with:

cd example/hakoniwa-sample-3
pnpm install
pnpm dev

💡 Advanced Usage: Streaming Logs & Progress Bars

hakoniwa-term commands leverage JavaScript Async Generators (async function*). This allows long-running or multi-stage asynchronous tasks to progressively stream log messages and update an integrated progress bar.

Example: Multi-step Async Command with Progress Updates

import { Terminal } from "hakoniwa-term";
import type { CommandAction } from "hakoniwa-term";
import "hakoniwa-term/dist/index.css";

const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));

const commands: Record<string, CommandAction> = {
  sync: async function* () {
    // 1. Stream log output
    yield {
      type: "log",
      log: { type: "output", text: "Connecting to remote repository..." },
    };

    // 2. Stream progress (20%)
    await delay(500);
    yield { type: "progress", percent: 20, text: "Fetching remote refs..." };

    // 3. Stream progress (65%)
    await delay(500);
    yield { type: "progress", percent: 65, text: "Unpacking objects..." };

    // 4. Stream progress (100%)
    await delay(500);
    yield {
      type: "progress",
      percent: 100,
      text: "Finalizing sync procedure...",
    };

    // 5. Stream final success log
    yield {
      type: "log",
      log: {
        type: "success",
        text: "✨ Repository synchronized successfully!",
      },
    };
  },

  errorTest: async function* () {
    yield {
      type: "log",
      log: {
        type: "error",
        text: "❌ CRITICAL: Unauthorized access detected!",
      },
    };
  },
};

🎛️ Component API (TerminalProps)

| Prop | Type | Default | Description | | -------------------------- | ------------------------------- | --------------------------------------- | -------------------------------------------------------------------------------------- | | commands | Record<string, CommandAction> | Required | Map of command names to async generator handlers. | | promptString | string | 'user@terminal:~$' | The prompt prefix displayed before user input. | | placeholder | string | 'Type a command...' | Placeholder text for the input box. | | systemLockedText | string | 'System locked during execution...' | Placeholder shown while an async command is executing. | | title | React.ReactNode | 'terminal' | Header title string or custom React element. | | preset | TerminalPreset | 'emerald' | Built-in color preset (emerald, matrix, dracula, amber, cyberpunk, light). | | theme | Partial<TerminalTheme> | undefined | Custom theme object to override specific colors. | | initialHistory | CommandLog[] | [] | Pre-populated log items displayed when mounted. | | showCloseButton | boolean | true | Whether to render the window close button (X). | | onClose | () => void | undefined | Callback invoked when the close button is clicked. | | headerRightActions | React.ReactNode | undefined | Custom React nodes rendered in the top-right of the title bar. | | commandNotFoundFormatter | (cmd: string) => string | (cmd) => Command not found: "${cmd}". | Formatter function for unknown commands. |


📐 TypeScript Types & Interfaces

export interface CommandLog {
  type: "input" | "output" | "error" | "success";
  text: string;
}

export type YieldChunk =
  | { type: "log"; log: CommandLog }
  | { type: "progress"; percent: number; text?: string };

export type CommandAction = (
  args: string[],
) => AsyncGenerator<YieldChunk, void, unknown>;

export interface TerminalTheme {
  bg: string;
  titleBg: string;
  border: string;
  text: string;
  prompt: string;
  error: string;
  success: string;
  progress: string;
}

export type TerminalPreset =
  "emerald" | "matrix" | "dracula" | "amber" | "cyberpunk" | "light";

export const TERMINAL_PRESETS: Record<TerminalPreset, TerminalTheme>;

📜 License

MIT © koji