# hanji

> Designless command line user interface builder

Latest version **0.0.8** (published 2026-03-15) · ISC license · 0 weekly downloads

## Install

```sh
npm install hanji
pnpm add hanji
yarn add hanji
bun add hanji
```

## Health

**Score 55/100 (C)** — status: stable.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.0.8 |
| Published | 2026-03-15 |
| First published | 2022-08-25 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 16.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 96 |
| Maintainers | dankochetov, sheriman, alexblokh, kyrylo_usichenko |

## Links

- npm: https://www.npmjs.com/package/hanji
- Repository: https://github.com/drizzle-team/hanji
- Homepage: https://github.com/drizzle-team/hanji#readme
- Issues: https://github.com/drizzle-team/hanji/issues
- npm.io page: https://npm.io/package/hanji

## Dependencies (2)

- [sisteransi](https://npm.io/package/sisteransi.md) ^1.0.5
- [lodash.throttle](https://npm.io/package/lodash.throttle.md) ^4.1.1

## Recent versions

- 0.0.8 (latest) — 2026-03-15
- 0.0.7 — 2025-10-13
- 0.0.6 — 2025-10-13
- 0.0.5 — 2023-01-06
- 0.0.4 — 2023-01-05
- 0.0.3 — 2022-08-31
- 0.0.2 — 2022-08-31
- 0.0.1 — 2022-08-25

## README

Hanji is a designless command line user interface builder for nodejs+typescript.
by [@_alexblokh](https://twitter.com/_alexblokh)

You can implement prompts by extending `Prompt` class   
Below is an example of how to implement `Select` with utility `SelectData` bundle provided from the library   
I will provide more view agnostic datasets to make implementing custom views like `input` a breath    
```typescript
import color from "kleur";
import { ITerminal, Prompt, render, SelectData } from "hanji";

export class Select extends Prompt<{ index: number; value: string }> {
  private readonly data: SelectState<{ label: string; value: string }>;
  private readonly spinner: () => string;
  private timeout: NodeJS.Timer | undefined;

  constructor(items: string[]) {
    super();
    this.on("attach", (terminal) => terminal.toggleCursor("hide"));
    this.on("detach", () => clearInterval(this.timeout));

    this.data = new SelectState(
      items.map((it) => ({ label: it, value: `${it}-value` }))
    );
    this.data.bind(this);
  }

  render(status: "idle" | "submitted" | "aborted"): string {
    if (status === "submitted" || status === "aborted") {
      return "";
    }

    let text = "";
    this.data.items.forEach((it, idx) => {
      text +=
        idx === this.data.selectedIdx
          ? `${color.green("❯ " + it.label)}`
          : `  ${it.label}`;
      text += idx != this.data.items.length - 1 ? "\n" : "";
    });

    return text;
  }

  result() {
    return {
      index: this.data.selectedIdx,
      value: this.data.items[this.data.selectedIdx]!.value!,
    };
  }
}

 const { status, data } = await render(
  new Select(["user1", "user2", "user3", "user4"])
);
if (status === "aborted") return;
console.log(data);
// { index: 0, value: 'users1' }
```

---
_Source: https://npm.io/package/hanji · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
