cycle-shell

0.4.22 • Public • Published

cycle shell

Build status Git tag NPM version Code style

A programmable web based shell-like interface

Installation

npm install cycle-shell

Usage

import cycle from 'cycle-shell'
 
cycle(main, {
  welcome: 'Welcome to my shell.'
})
 
function main (input) {
  return input
}

API

cycle(update, opts)

Initialize a cycle shell instance. By default, the cycle shell will be placed in the <body> of the document.

Returns Process count listener

var counter = require('cycle-shell')(main)
counter(function (num) {
  console.log(num)
})
update
  • type: function
  • An update function that gets run when the input box is submitted
opts
  • type: object
welcome
  • type: string
  • A message to be displayed when the shell is first run
title
  • type: string
  • The title of the game/application to be displayed next to the input box
view
  • type: function
  • The return value from the main function gets run through the view function to produce a valid output.

The default view function is set up to handle objects, arrays, strings, numbers, and vdux components.

const defaultView = (output) => {
  if (typeof (output) !== 'object' || output.props) {
    return output
  } else if (isArray(output)) {
    output.join('\n')
  } else {
    return reduce((arr, item, key) => {
      arr.push(`${key}${item}`)
      return arr
    }, [], output).join('\n')
  }
}
initialState
  • type: object
  • set an initial state for the application
middleware
  • type: function || generator
  • Connect custom middleware to cycle shell

out(msg)

Exposed out action for adding messages to the output log.

msg
  • type: string
  • A message to be placed in the output log.

Readme

Keywords

none

Package Sidebar

Install

npm i cycle-shell

Weekly Downloads

7

Version

0.4.22

License

ISC

Last publish

Collaborators

  • danleavitt0