Package Exports
- neat-log
- neat-log/output
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (neat-log) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
neat-log
A neat logger for command line tools, inspired by Choo! I've heard so much about how awesome front-end javascript has gotten, I wanted to bring some of that magic to command line applications.
- Use tagged template literals to output to console log.
- Automatically diff template output with existing console (via ansi-diff-stream)
- Update console output in any order with event based output.
- Pretty neat!
Example
See a basic example here and another more complex one in example.js
.
var neatLog = require('neat-log')
var output = require('neat-log/output')
var neat = neatLog(view)
neat.use(countTheSeconds)
function view (state) {
// This gets printed to the console! Wow. So neat.
return output`
Hello World!
I've been running for ${state.seconds} second${state.seconds === 1 ? '' : 's'}.
`
}
function countTheSeconds (state, bus) {
state.seconds = 0
setInterval(function () {
state.seconds++
bus.emit('render')
}, 1000)
bus.emit('render')
}
This example will print to the console:
Hello world!
I've been running for 0 seconds.
And update every second!
Install
npm install neat-log
API
Heavily inspired by Choo! If you get confused here, check docs there because they are much nicer =).
var neat = neatLog(views, [opts])
views
is a single function or array of functions that return string(s) to output to the console.views
are passed thestate
as the first argument.opts.logspeed
, default 250ms, throttles how often output is rendered.
neat.use(callback(state, emitter))
Use a function (state, bus)
to change state and emit events via the bus. You can call bus.emit()
to emit a new event and bus.on()
to listen.
neat.render()
For an immediate render. Helpful outside of a use function.
var output = require('neat-log/output')
Get a tagger for your template literals to make them nicer. Removes spaces and stuff™.
TODO
- Use
bus.on('*')
to make a cool debug option - Could expose status-logger and ansi-diff-stream stuff if needed (e.g.
log.clear()
) - Other neat things