0.4.22 • Published 7 years ago

cycle-shell v0.4.22

Weekly downloads
2
License
ISC
Repository
github
Last release
7 years ago

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.
0.4.22

7 years ago

0.4.21

7 years ago

0.4.20

7 years ago

0.4.19

8 years ago

0.4.18

8 years ago

0.4.17

8 years ago

0.4.16

8 years ago

0.4.15

8 years ago

0.4.14

8 years ago

0.4.13

8 years ago

0.4.12

8 years ago

0.4.11

8 years ago

0.4.10

8 years ago

0.4.9

8 years ago

0.4.8

8 years ago

0.4.7

8 years ago

0.4.6

8 years ago

0.4.5

8 years ago

0.4.3

8 years ago

0.4.2

8 years ago

0.4.1

8 years ago

0.4.0

8 years ago

0.3.9

8 years ago

0.3.8

8 years ago

0.3.7

8 years ago

0.3.5

8 years ago

0.3.3

8 years ago

0.3.2

8 years ago

0.3.1

8 years ago

0.3.0

8 years ago

0.2.1

8 years ago

0.1.6

8 years ago

0.1.5

8 years ago

0.1.4

8 years ago

0.1.3

8 years ago