# @totemish/shell

> Tools for styling up console output and prompting for user input. Dependency-free.

Latest version **1.3.1** (published 2018-07-29) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @totemish/shell
pnpm add @totemish/shell
yarn add @totemish/shell
bun add @totemish/shell
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.3.1 |
| Published | 2018-07-29 |
| First published | 2018-02-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 45.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | priestine |
| Maintainers | priestine |
| Keywords | totemish, node, console, shell, terminal, prompt, colors, typescript |

## Links

- npm: https://www.npmjs.com/package/@totemish/shell
- Repository: https://github.com/totemish/shell
- Homepage: https://github.com/totemish/shell#readme
- Issues: https://github.com/totemish/shell/issues
- npm.io page: https://npm.io/package/@totemish/shell

## Alternatives

- [localforage](https://npm.io/package/localforage.md) — 6.2M weekly downloads
- [localforage-observable](https://npm.io/package/localforage-observable.md) — 30.8K weekly downloads
- [@y/y](https://npm.io/package/@y/y.md) — 30.1K weekly downloads
- [@metaobjectsdev/render](https://npm.io/package/@metaobjectsdev/render.md) — 3.5K weekly downloads
- [@ledgerhq/coin-algorand](https://npm.io/package/@ledgerhq/coin-algorand.md) — 1.1K weekly downloads

## Recent versions

- 1.3.1 (latest) — 2018-07-29
- 1.3.0 — 2018-02-22
- 1.2.0 — 2018-02-21
- 1.1.0 — 2018-02-21
- 1.0.0 — 2018-02-21

## README

# Shell

[![Core Build Status](https://travis-ci.org/totemish/shell.svg?branch=master)](https://travis-ci.org/totemish/shell)
[![codecov](https://img.shields.io/codecov/c/github/totemish/shell.svg)](https://codecov.io/gh/totemish/shell)
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
[![downloads](https://img.shields.io/npm/dt/@totemish/shell.svg)](https://www.npmjs.com/package/@totemish/shell)
[![version](https://img.shields.io/npm/v/@totemish/shell.svg)](https://www.npmjs.com/package/@totemish/shell)
[![license](https://img.shields.io/github/license/mashape/apistatus.svg)]()

Totemish shell is a set of tools for styling the console output and prompting for user input.

## Installation

```bash
npm i --save @totemish/shell
```

## Usage


#### Input

To prompt for user input, you need to call `Shell.prompt()`. You need to provide a question you want to ask. Optionally, you may provide a **default value** that will be referred to as an answer in case user gives no input, and a **values** array, that represents a set of values and at least one of them must be picked by user or they will be informed about invalid choice provided and prompted the same question once again. Prompt returns user answer, automatically resolving floats, numbers and boleans.

```javascript
import { Shell } from '@totemish/shell';

// NOTE: Shell.prompt() method is asynchronous
Shell.prompt('Pick a number').then((a) => { // ? Pick a number
  Shell.prompt('What?', 'Nothing').then((b) => { // ? What? (Nothing)
    Shell.prompt('Lemon is yellow', true, [true, false]).then(); // ? Lemon is yellow? [true, false] (true)
  });
});
```

#### Output

```javascript
import { Shell } from '@totemish/shell';

/**
 * There are five default helper methods
 */
Shell.write('white');
Shell.warn('yellow');
Shell.success('green');
Shell.info('blue');
Shell.error('red');

/**
 * Prints a blank line
 */
Shell.blank();

/**
 * You can specify amount of blank lines to be printed
 */
Shell.blank(2);

/**
 * You can apply three types of enhanced decoration - bold, underline and inverse
 * The spread operator is optional but it removes the nasty TypeScript incompatibility anger
 */
Shell.success(...Shell.bold('bold green'));
Shell.warn(...Shell.underline('underlined yellow'));
Shell.info(...Shell.inverse('inversed blue'));

/**
 * Shell.describe method prints out the contents of an array or an object in a nice coloured way
 * Booleans are given in magenta color, numbers - in yellow, object keys - in cyan and strings - in green
 */
Shell.describe({
  boolean: true,
  number: 42,
  object: {
    string: 'green',
    array: [
      "each",
      "item",
      "is",
      "green",
    ],
    nestedObject: {
      hello: 'world'
    }
  }
});
Shell.describe([1,4,3,2]);
```

## Controlling behaviour

* You can disable awaiting prompt input by providing a `--y` flag when starting the process. If `process.argv` includes the `--y` flag, prompter will automatically apply default value if it is given, or an empty string ('').

* You can disable applying colors to console output by providing a `--no-color` flag when starting the process. If `process.argv` includes the `--no-color` flag, writer will write output to console without any ASCI magic.

* You can disable output to console by providing a `--silent` flag when starting the process. If `process.argv` includes the `--silent` flag, prompter will automatically apply default value if it is given, or an empty string ('') and writer will give no output to console.

## Custom output

You can apply several styles and wrap up everything like so:

```javascript
import { Shell } from '@totemish/shell';

Shell.write(Shell.green('hello'), Shell.red(' world'));
```

## Links

* [API](https://totemish.github.io/framework)
* [Docs (Under Construction)](https://totemish.com/docs)
* [Tutorials (Under Construction)](https://totemish.com/tutorials)
* [Sample App (Under Construction)](https://github.com/totemish/sample-app)

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