2.1.0 • Published 8 years ago

kool-shell v2.1.0

Weekly downloads
60
License
MIT
Repository
github
Last release
8 years ago

kool-shell

:microphone::tv::notes: A minimal module to deal with shell

Build Status Build Status

Spinner

Features

  • 1 dependency (support-color)
  • Native promises from Nodejs
  • Shell commands with silent & inherited stdio
  • Ansi Colors + Auto-detects color support
  • Log methods with 4 log levels
  • User input with hidden input option
  • List input with multiple or single choice
  • Awesome emoji-based spinner
  • Progressbar
  • Create and add your own kool-shell plugins easily
  • Cool emojis!

Requirements

  • Node > 8
  • npm > 5
  • ANSI/VT100 compatible terminal

Installation

npm install --save kool-shell

Usage

Create a new kool-shell instance

const sh = require('kool-shell')
sh.warn(sh.colors.gray('Display a gray warning'))

// You can also use object destructuring
const { warn, colors } = require('kool-shell')
warn(colors.gray('Display a gray warning'))

Namespacing

It can be useful to not share kool-shell configuration and state when dealing with multiple modules. You can specify a namespace using the kool-shell/namespaced module.

const sh1 = require('kool-shell/namespaced')('MyModule')
sh1.setLogOptions(globalPrefix: '[MyModule] ')
sh1.log('Customized log for the MyModule namespace')

const sh2 = require('kool-shell')
sh2.log('This log will not have the [MyModule] prefix')

Kool-shell features

All features are basically native plugins, always available in kool-shell. See the Plugins section below to learn how to create & add your own plugins.

  • Log - Log functions
  • Colors - Add colors to your log messages
  • Progressbar - Display a progressbar
  • Spinner - Display a spinner
  • Exec - Execute a promised shell command
  • Input - User prompt with hidden input option
  • Select - Select/Radio input
  • Cleanup - Do some actions before exiting your app
  • Exit - Simple alias of process.exit(code)

Plugins

Add a plugin

Add a plugin with sh.use(plugin, [options]). You can specify options for your plugin.

const koolPlugin = require('kool-shell-plugin')
sh.use(koolPlugin, { colors: false })

Create a plugin

Plugin template
module.exports = myPlugin (sh, opts = {}) {
  return {
    sayHello () {
      // kool-shell native features are always available from the sh object.
      // for instance, you can easily use colors using sh.colors method
      opts.gray
        ? console.log('hello.')
        : console.log(sh.colors.gray('hello'))
    }
  }
}

Two arguments will be passed when your plugin is used through sh.use():

  • sh is the kool-shell instance used
  • opts is the options object passed trough sh.use(plugin, options)

Your plugin need to be a function that return an object. When your plugin is used, the returned object will be merged into the api object of the kool-shell instance.

:warning: Method/Property will be overiden if a new one has the same name. Namespace your plugin api if you use common method names

To do

  • Test all native features

License

MIT.

2.1.0

8 years ago

2.0.1

8 years ago

1.5.0

9 years ago

1.4.3

9 years ago

1.4.2

9 years ago

1.4.0

9 years ago

1.3.0

9 years ago

0.5.4

10 years ago

0.5.3

10 years ago

0.5.2

10 years ago

0.5.1

10 years ago

0.4.0

10 years ago

0.3.2

10 years ago

0.3.1

10 years ago

0.3.0

10 years ago