All Projects β†’ ctaylo21 β†’ termy-the-terminal

ctaylo21 / termy-the-terminal

Licence: MIT License
Web-based terminal powered by React

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
SCSS
7915 projects
HTML
75241 projects

Projects that are alternatives of or similar to termy-the-terminal

zero
πŸ“¦ A zero config scripts library
Stars: ✭ 17 (-60.47%)
Mutual labels:  jest, rollup, prettier
Nextjs Ts
Opinionated Next JS project boilerplate with TypeScript and Redux
Stars: ✭ 134 (+211.63%)
Mutual labels:  jest, prettier
ying-template
θΏ™ζ˜―δΈ€δΈͺ基于 `webpack@^5.27.2` + `typescript@^4.2.3` + `@babel/core@^7.2.2` + `jest@^26.6.3` + `eslint@^7.22.0` ηš„ε€šι‘΅ι’θ„šζ‰‹ζžΆγ€‚
Stars: ✭ 125 (+190.7%)
Mutual labels:  jest, prettier
reactjs-vite-tailwindcss-boilerplate
ReactJS + Vite boilerplate to be used with Tailwindcss.
Stars: ✭ 103 (+139.53%)
Mutual labels:  jest, prettier
Simple React Calendar
A simple react based calendar component to be used for selecting dates and date ranges
Stars: ✭ 97 (+125.58%)
Mutual labels:  jest, prettier
Sketchmine
Tools to validate, generate and analyse sketch files from web pages
Stars: ✭ 114 (+165.12%)
Mutual labels:  jest, rollup
Typescript Express Starter
πŸš€ TypeScript Express Starter
Stars: ✭ 238 (+453.49%)
Mutual labels:  jest, prettier
Mostly
They mostly come at night; mostly.
Stars: ✭ 78 (+81.4%)
Mutual labels:  jest, prettier
Express-REST-API-Template
Minimal starter project for a Node.js RESTful API based off express generator
Stars: ✭ 26 (-39.53%)
Mutual labels:  jest, prettier
nimbus
Centralized CLI for JavaScript and TypeScript developer tools.
Stars: ✭ 112 (+160.47%)
Mutual labels:  jest, prettier
rollup-jest-boilerplate
πŸŽ‰ Full featured boilerplate for building JavaScript libraries the modern way
Stars: ✭ 81 (+88.37%)
Mutual labels:  jest, rollup
React Boilerplate
This project is deprecated. Please use CRA instead.
Stars: ✭ 88 (+104.65%)
Mutual labels:  jest, prettier
Alias Hq
The end-to-end solution for configuring, refactoring, maintaining and using path aliases
Stars: ✭ 77 (+79.07%)
Mutual labels:  jest, rollup
Reeakt
A modern React boilerplate to awesome web applications
Stars: ✭ 116 (+169.77%)
Mutual labels:  jest, prettier
Gatsby Starter Typescript Rebass Netlifycms
My default Gatsby setup. Includes rich MDX support.
Stars: ✭ 79 (+83.72%)
Mutual labels:  jest, prettier
Modern Node
All-in-one development toolkit for creating node modules with Jest, Prettier, ESLint, and Standard
Stars: ✭ 216 (+402.33%)
Mutual labels:  jest, prettier
Node Typescript Boilerplate
Minimalistic project template to jump start a Node.js back-end application in TypeScript. ESLint, Jest and type definitions included.
Stars: ✭ 1,061 (+2367.44%)
Mutual labels:  jest, prettier
Starter React Flux
Generate your React PWA project with TypeScript or JavaScript
Stars: ✭ 65 (+51.16%)
Mutual labels:  jest, prettier
fly-helper
It's a Tool library, method collection
Stars: ✭ 21 (-51.16%)
Mutual labels:  jest, rollup
generator-node
πŸ”§ Yeoman generator for Node projects.
Stars: ✭ 16 (-62.79%)
Mutual labels:  jest, prettier
Coverage Status Build Status bundle size NPM Version

Termy the Terminal

A web-based terminal powered by React. Check out the demo.

Table of Contents

Installation

The package can be installed via NPM:

npm i termy-the-terminal

You will need to install the React and ReactDOM packages separately as they aren't included in this package.

Usage

import React from 'react';
import ReactDOM from 'react-dom';
import { Terminal } from 'termy-the-terminal';
import 'termy-the-terminal/dist/index.css';
import exampleFileSystem from './data/exampleFileSystem';

ReactDOM.render(
  <Terminal fileSystem={exampleFileSystem} inputPrompt="$>" />,
  document.getElementById('terminal-container'),
);

Terminal Props

Prop Name Description Required
fileSystem A properly formatted (see below) JSON object representing the filesystem Yes
inputPrompt String to use as input prompt (default is $>) No
customCommands Custom commands to add to the terminal No

The fileSystem prop needs to be a particular format (code example):

import dogImg from '../../src/images/dog.png';

const BlogPost ({date, content}) => (
  <>
    <h3>{date}</h3>
    <p>{content}</p>
  </>
);

const exampleFileSystem = {
  home: {
    type: 'FOLDER',
    children: {
      user: {
        type: 'FOLDER',
        children: null,
      },
      file1: {
        type: 'FILE',
        content: 'Contents of file 1',
        extension: 'txt',
      },
      dog: {
        type: 'FILE',
        content: dogImg,
        extension: 'png',
      },
    },
  },
  docs: {
    type: 'FOLDER',
    children: null,
  },
  blog: {
    type: 'FILE',
    content: <BlogPost date="3/22" content="Today is a good day" />,
    extension: 'txt'
  },
};

Important: To support using cat to display images from your filesystem, you need to pass a valid image location and valid extension ('jpg', 'png', or 'gif'). To follow the example above, you will need to make sure your bundler (webpack, rollup, etc..) supports importing images. For an example of this in webpack, see the weback docs, and for rollup, check out @rollup/plugin-image.

General

The following sections include general features that Termy supports outside of the terminal commands.

Command History

Termy supports using the arrow keys (up and down) to move through the command history.

Auto Complete

Termy supports using the tab key to trigger autocomplete for commands to complete a target path. This includes using multiple tab presses to cycle through the possible auto-complete options for a given command.

Custom Commands

You can add custom commands to Termy by passing in your commands as the customCommands prop. Here is an example command "hello" that just prints "world" when executed:

const hello = {
  hello: {
    // Function that handles command execution
    handler: function hello(): Promise<CommandResponse> {
      return new Promise((resolve): void => {
        resolve({
          commandResult: 'world',
        });
      });
    },
  },
};

ReactDOM.render(
  <Terminal fileSystem={exampleFileSystem} customCommands={hello} />,
  document.getElementById('terminal-container'),
);

You can also make a more complex command that acts upon the files and folders of the filesystem. Here is an example that will print the length of contents of a file, but only if it is a .txt file and the content is a simple string. It also supports autocomplete by using default autoComplete method and some utility functions exported from the base file.

import React from 'react';
import ReactDOM from 'react-dom';
import get from 'lodash/get';
import {
  autoComplete,
  CommandResponse,
  FileSystem,
  Terminal,
  utilities
} from 'termy-the-terminal';
const { getInternalPath, stripFileExtension } = utilities;
import exampleFileSystem from './data/exampleFileSystem';

const lengthCommand = {
  length: {
    handler: function length(
      fileSystem: FileSystem,
      currentPath: string,
      targetPath: string,
    ): Promise<CommandResponse> {
      return new Promise((resolve, reject): void => {
        if (!targetPath) {
          reject('Invalid target path');
        }

        const pathWithoutExtension = stripFileExtension(targetPath);
        const file = get(
          fileSystem,
          getInternalPath(currentPath, pathWithoutExtension),
        );

        if (!file) {
          reject('Invalid target path');
        }

        if (file.extension !== 'txt') {
          reject('Target is not a .txt file');
        }

        let fileLength = 'Unknown length';
        if (typeof file.content === 'string') {
          fileLength = '' + file.content.length;
        }

        resolve({
          commandResult: fileLength,
        });
      });
    },
    autoCompleteHandler: autoComplete,  // Function that returns results for autocomplete for given command
    description: 'Calculates the length of a given text file' // Description that will be show from "help" command
  },
};

ReactDOM.render(
  <Terminal fileSystem={exampleFileSystem} customCommands={lengthCommand} />,
  document.getElementById('terminal-container'),

You can add multiple commands to your customCommands prop as each command name is just defined by its key in the object you pass in.

// Create two custom commands, "hello" and "length"
const customCommands = {
  hello: {
    handler: // hello handler defined here
    // No autoCompleteHandler function defined so auto complete isn't supported for this command
  },
  length: {
    handler: // length handler defined here
    autoCompleteHandler: // autocomplete handler defined here for length command
    description: 'Some description' // include a description if you want command to appear when "help" is executed
  }
};

Commands

The following commands are supported by Termy.

cd [DIRECTORY]

Supports changing directory, including use .. to move up a level

# cd with relative path
/home $> cd user/test

/home/user/test $> cd user/test

# cd from absolute path
/ $> cd /home/user/test

/home/user/test $>

# cd using ".."
/home $> cd ..

/ $>

# cd using nested path with ".."
/ $> cd /home/user/../user

/home/user $>

pwd

Prints current directory to the console

/home/user $> pwd
/home/user

ls [DIRECTORY]

Lists information about files and directories within the file system. With no arguments, it will use the current directory.

/home/user $> ls
# Contents of /home/user

/home/user $> ls /home
# Contents of /home

/home/user $> ls ..
# Contents of /home

mkdir [DIRECTORY]

Creates a folder for a given path in the filesystem

# mkdir with relative path
/ $> mkdir test
Folder created: test

# mkdir with absolute path
/ $> mkdir /home/banana
Folder created: /home/banana

# mkdir with ".." path
/home/user $> mkdir ../test2
Folder created: ../test2 #/home/test2

cat [FILE]

Shows the contents of a file. Both basic text files and images are supported (with some dependencies, see the Usage section).

/home $> cat file1.txt
# Contents of file1.txt

/home $> cat videos/file2.txt
# Contents of file2.txt

/home $> cat home/dog.png
   / \__
  (    @\___
  /         O
 /   (_____/
/_____/   U

rm [OPTIONS] [FILE]

Remove a file or directory from the filesystem

Options

  • -r - remove directories and their contents recursively
/ $> rm -r home
# home directory deleted

/home $> rm videos/file2.txt
# file2.txt deleted

help

Prints available commands for the terminal with descriptions.

/ $> help
cd - Changes the current working directory
pwd - Prints the current working directory
ls - Lists the contents of the given directory
mkdir - Creates a folder for a given path in the filesystem
cat - Shows the contents of a file
rm - Removes a file or directory
help - Prints list of available commands
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].