$ yarn add @pronix/hyper-flow
#or
$ npm i @pronix/hyper-flow
const { Hyper, HyperContext } = require('@pronix/hyper-flow')
// or
// import { Hyper, HyperContext } from '@pronix/hyper-flow''
const app = new Hyper()
const ctx = new HyperContext()
ctx.on('/', () => console.log('hello'))
app.next(ctx)
app.listen()
at first, you need to create application
import { Hyper } from '@pronix/hyper-flow'
const app = new Hyper()
next you need to create ctx - this is the object that will process the commands, you can create more than one context and then you can change current context in runtime
import { Hyper, HyperContext, utils } from '@pronix/hyper-flow'
const app = new Hyper()
const ctx1 = new HyperContext(utils.marker('ctx1'))
const ctx2 = new HyperContext(utils.marker('ctx2'))
ctx1
.on('/next', () => app.next(ctx2))
.on('/back', () => app.back())
.on('/', () => console.log(utils.renderCommands(ctx1.cmds)))
ctx2
.on('/next', () => app.next(ctx1))
.on('/back', () => app.back())
.nothing('', ' ')
app
.next(ctx1)
.listen()
also you can use async code in your program, it will works, because the readline is async
const app = new Hyper()
const ctx = new HyperContext()
const ctx2 = new HyperContext()
ctx.on('/', () => {
console.log('hello')
app.next(ctx2)
})
ctx2
.on('/', () => console.log('end'))
.on('/ask', () => {
// question must be a sync call ->
const response = question('what is your name?')
// processing response
console.log(response)
})
.default((ctx, cmd) => {
console.log(cmd)
})
app.next(ctx)
// you can use async side-effects ->
setTimeout(() => {
console.log('async call')
}, 3000)
app.listen()
marker is a tool, which writes the text in comand line befor every command, it is a string
import { error } from "@pronix/hyper-flow";
ctx.marker = 'ctx1:\\> '
ctx
.on('/', () => console.log('hello'))
.on('/error', () => console.log(error('error handler', 1)))
.on('exit', () => process.exit(0))
.on('/exit', ctx => ctx.run('exit'))
app
.defaultContext
.on('/info', () => console.log('info: ...'))
.nothing('')
app
.next(ctx)
.listen()
stop word:
ctx
.on('/', () => console.log('hello world'))
app.next(ctx)
app.stopWord = 'stop'
app.listen()
$ git clone http://github.com/pronix575/hyper-flow
$ cd hyper-flow
$ yarn setup
# or
$ npm setup
$ yarn build
$ yarn start
$ yarn dev:build
$ yarn dev:start