0.4.22 • Published 9 years ago

cycle-shell v0.4.22

Weekly downloads
2
License
ISC
Repository
github
Last release
9 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

9 years ago

0.4.21

9 years ago

0.4.20

9 years ago

0.4.19

9 years ago

0.4.18

9 years ago

0.4.17

9 years ago

0.4.16

9 years ago

0.4.15

9 years ago

0.4.14

9 years ago

0.4.13

9 years ago

0.4.12

9 years ago

0.4.11

9 years ago

0.4.10

9 years ago

0.4.9

9 years ago

0.4.8

9 years ago

0.4.7

9 years ago

0.4.6

9 years ago

0.4.5

9 years ago

0.4.3

9 years ago

0.4.2

9 years ago

0.4.1

9 years ago

0.4.0

9 years ago

0.3.9

9 years ago

0.3.8

9 years ago

0.3.7

9 years ago

0.3.5

10 years ago

0.3.3

10 years ago

0.3.2

10 years ago

0.3.1

10 years ago

0.3.0

10 years ago

0.2.1

10 years ago

0.1.6

10 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.3

10 years ago