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 🙏

© 2025 – Pkg Stats / Ryan Hefner

whiptail-js

v1.0.6

Published

A lightweight terminal-style dialog library for the web, inspired by the whiptail tool.

Downloads

95

Readme

whiptail-js

whiptail-js is a lightweight terminal-style dialog library for the web, inspired by the classic Linux whiptail tool, featuring keyboard navigation and touch support for mobile devices.

Getting Started

Installation

npm install jquery
npm install whiptail-js

Or use a CDN:

<link rel="stylesheet" href="https://unpkg.com/whiptail-js/dist/whiptail.css">
<script src="https://unpkg.com/[email protected]/dist/jquery.min.js"></script>
<script src="https://unpkg.com/whiptail-js/dist/whiptail.js"></script>

Usage

First, add a container element where your UI will render:

<div id="whiptail-container"></div>

Then create a new instance of WhiptailJS:

const whiptail = new WhiptailJS({
    title: "Raspberry Pi Software Configuration Tool (raspi-config)",
    items: [
        { label: "1 System Options&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Configure system settings", focus: true },
        { label: "2 Display Options&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Configure display settings" },
        { label: "3 Interface Options&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Configure connections to peripherals" },
        { label: "4 Performance Options&nbsp;&nbsp;&nbsp;Configure performance settings" },
        { label: "5 Localisation Options&nbsp;&nbsp;Configure language and regional settings" },
        { label: "6 Advanced Options&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Configure advanced settings" },
        { label: "7 Update&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Update this tool to the latest version" },
        { label: "8 About raspi-config&nbsp;&nbsp;&nbsp;&nbsp;Information about this configuration tool" }
    ],
    footer: [{ label: "&lt;Select&gt;", id: 'select' }, { label: "&lt;Finish&gt;", id: 'close' }],
    selector: "#whiptail-container",
    focus: true,
    onSelect: (item, btn) => {
        if(btn.id === 'close') {
            whiptail.destroy(); // destroy the instance
        } else if (btn.id === 'select') {
            alert(`You selected: ${item.textContent}`);
        }
    }
});

Output

Configuration Options

  • title | (string, optional) The dialog's header text.

  • selector | (string) The CSS selector of the container element where the dialog will render.

  • height | (string, optional) The height of the dialog. Accepts values in pixels (e.g., "400px") or percentages (e.g., "60%").

  • width | (string, optional) The width of the dialog. Accepts values in pixels (e.g., "600px") or percentages (e.g., "80%").

  • focus | (boolean, optional) Whether the dialog should automatically receive focus when created.

  • text | (string, optional) Additional text content to display in the dialog.

  • items | (array of objects, optional) List of menu items, each with the following:

    • label (string) | The text content of the item.
    • id (string, optional) | The HTML id attribute for the item.
    • class (string, optional) | The HTML class attribute for the item.
    • focus (boolean, optional) | Whether this item is initially focused.
    • active (boolean, optional) | Whether this item is initially active (selected).
  • footer | (array of objects) List of footer buttons, each with the same properties as items.

  • onSelect | (function) Callback called when a user selects an item or footer button. Receives two arguments:

    • The selected item DOM element.
    • The selected footer button DOM element.
  • onClose | (function, optional) Callback called when a user closes the dialog via the Escape key.

API Methods

  • constructor(config) | Creates a new whiptail dialog instance with the provided configuration options.

  • get() | Returns the DOM element of the dialog container.

  • focus() | Sets focus to the dialog, used to ensure keyboard navigation works properly.

  • status() | Returns an object with item and footer properties containing the currently focused menu item and footer button element.

  • destroy() | Destroys the dialog from the DOM and cleans up all event listeners.

  • return() | Calls the onClose callback, equivalent to pressing Escape key.

  • onSelect(item, footerButton) | Callback triggered when a user makes a selection. Receives the selected item and footer button elements.

  • onClose() | Callback triggered when a user closes the dialog (via Escape key).

Default Options

whiptail-js provides a selection of convenience methods that mimic the Linux whiptail commands, allowing you to create standard dialogs quickly.

Methods:

WhiptailJS.msgbox(selector, text, [height], [width], [callback], [config])

Displays a simple message box with an OK button.

WhiptailJS.msgbox('#whiptail-container', 'Hello world!', 200, 400, () => {
    console.log('OK pressed');
});

WhiptailJS.yesno(selector, text, [height], [width], [callback], [config])

Displays a [Yes / No] confirmation dialog.

WhiptailJS.yesno('#whiptail-container', 'Do you want to continue?', 200, 400, (item, btn) => {
    console.log(`${btn.id} pressed`);
});

WhiptailJS.infobox(selector, text, [height], [width], [callback], [config])

Displays a message box without any buttons; automatically calls the callback.

WhiptailJS.infobox('#whiptail-container', 'Processing...', 200, 400, () => {
    // do whatever before destroying
});

WhiptailJS.textbox(selector, fileUrl, [height], [width], [callback], [config])

Displays a file's content in a message box.

WhiptailJS.msgbox('#whiptail-container', '/path/to/file.txt', 200, 400, () => {
    console.log('OK pressed');
});

Tip: This method also supports external URLs.

WhiptailJS.menu(selector, text, [height], [width], items, [callback], [config])

Displays a menu list with selectable items.

WhiptailJS.menu('#whiptail-container', 'Choose an option:', 500, 800, [
    { label: 'Option 1' },
    { label: 'Option 2', focus: true },
    { label: 'Option 3' }
], (item, btn) => {
    console.log(`Selected: ${item.textContent}`);
});