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 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-terminal-emulator-ui

v1.2.0

Published

Terminal Emulator UI with React + Tailwind

Downloads

78

Readme

React Terminal Emulator UI

Description

A customizable terminal component for React applications. This component simulates a command-line interface where users can input commands and view the output. Built with React + TypeScript + Tailwind

demo-gif

Live example

Installation

You can install the package from npm using the following command:

npm i react-terminal-emulator-ui

Usage

import React from "react";
import { Terminal, Command } from "terminal";

const MyTerminal = () => {
  // Define commands
  const commands: Array<Command> = [
    {
      command: "help",
      result: (
        <div>
          <p>Available commands:</p>
          <ul>
            <li>
              <b>help</b> - List of available commands
            </li>
            <li>
              <b>bio</b> - Display bio details about the user
            </li>
          </ul>
        </div>
      ),
    },
    {
      command: "bio",
      result: (
        <div>
          <p>
            👋 Hello! I'm user-name, a passionate developer with a love for coding and technology.
          </p>
          <ul>
            <li>💻 Full-Stack Developer</li>
            <li>📚 Avid Learner</li>
            <li>🎨 Creative Problem Solver</li>
            <li>🌐 Open Source Contributor</li>
          </ul>
          <p>Let's build something amazing together!</p>
        </div>
      ),
    },
  ];

  return (
    <Terminal
      commands={commands}
      userName="user-name"
      machineName="machine-name"
      initialFeed="Welcome to your terminal. Type help to see available commands."
    />
  );
};

export default MyTerminal;

Important Note on Next.js Integration

There is a change you are using Next.js framework to build your project. If that is the case please add this configuration line to your next.config.mjs file:

/** @type {import('next').NextConfig} */
const nextConfig = { transpilePackages: ["react-terminal-emulator-ui"] }; // add this line

export default nextConfig;

This will ensure Next.js transpiles and bundles dependencies from this package into your project out of the box.

For more information refer to: https://nextjs.org/docs/app/api-reference/next-config-js/transpilePackages

Important Note on TailwindCSS Integration

As of the date of publishing this package, TailwindCSS does not support native package resolution for styles. This means that any custom styling provided by this package using TailwindCSS will not automatically be included in your project. To ensure that the TailwindCSS styles from this package are applied correctly, you need to update your TailwindCSS configuration in your project.

Please follow these steps (assuming you've already installed TailwindCSS and created a configuration file):

  1. Update your tailwind.config.js file to include the paths to the components of this package:
/** @type {import('tailwindcss').Config} */
module.exports = {
  content: [
    ...
    "./node_modules/react-terminal-emulator-ui/**/*.{js,ts,jsx,tsx}", // Add this line,
    ...
  ],
};

For more information refer to: https://tailwindcss.com/docs/content-configuration#working-with-third-party-libraries

API

| Name | Type | Default | Description | | --------------------- | ------------------------- | ------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------- | | commands | Array<Command> | - | An array of command objects defining the available commands and their corresponding results or side effects. | | userName | string | - | The username to be displayed in the terminal prompt. | | machineName | string | - | The machine name to be displayed in the terminal prompt. | | initialFeed | string | "Welcome to your terminal. Type help to see available commands." | Initial text to be displayed in the terminal. | | onCommandNotFound | (cmd: string) => string | A function returning '${cmd}': command not found. | A function called when an unknown command is entered. It should return the error message to be displayed in the terminal. | | disableClearCommand | boolean | false | Boolean flag to disable native clear command (clears the terminal) |

Note on Height

The main element of the terminal component uses the h-full TailwindCSS class. This means that if you want to restrict the height of the terminal, you need to wrap the component in a <div> or any other element and apply a custom height. For example, to use the full page height, you can use the h-screen class, or for a custom height, you can use something like h-96.

Example with h-screen:

<div className="h-screen">
  <Terminal commands={commands} machineName="machine-name" userName="user-name" />
</div>

Example with h-96:

// your parent element with `h-96`
<div className="h-96">
  <Terminal commands={commands} machineName="machine-name" userName="user-name" />
</div>

License

This package is licensed under the MIT License.

Author

Support

For any issues or questions, please open an issue on GitHub.

Upcoming features

  • Enable arrow navigation
  • Styling wrapper classes with Tailwind + Styling for the rest of the bits (prompt parts - user name, machine name etc, tilde etc)
  • Resizing/Size props