aggregated-cli-reporter
A way of reporting results of multiple processes without overflowing the terminal.
It will rewrite the previous lines, so there never are more visible than the latest message.
Note: If something else is writing to stdout, it will interfere with this module,
since this module can only delete the x last lines
, which no longer matches the
actual lines written to stdout.
Usage
The interface:
set(name, messages, { showTime = true showName = false })
Creating a new reporter
// Orconst AggregatedCLIReporter = const reporter =
The constructor can take some configuration options:
showTime
: Shows a timestamp that the message was received. Defaults totrue
.showName
: Shows the name passed to#set()
. Defaults tofalse
.
const reporter = showTime: false showName: true
Writing logs
The reporter.set()
method sets the latest output for a specific name.
reporter /* output:12:45:12: Some message*/
There can only ever be one message per name, but there is no limit to the number of names.
reporter /* output:12:45:12: Some message12:47:22: Some other message*/ // skip 12 seconds reporter /* output:12:45:12: Some message12:47:34: Something new happened*/
The names are printed in the order that they were last modified, so the latest message is always in the bottom.
reporter /* output:12:47:34: Something new happened12:49:01: Something happened to the first tool*/
Any characters can be added, including colors and newlines.
reporter/* output:12:47:34: Something new happened13:01:43: Tool 1 is spliton lines*/
The message can also be an array, in which case the tool will print each value on a separate line, all prefixed.
reporter /* output:12:47:34: Something new happened13:02:23: Something happened13:02:23: that should13:02:23: be spliton lines*/
Overriding options per message
The #set()
call takes the same arguments as the constructor. The options will
override the default for that specific message only.
const reporter = showTime: true showName: true reporter/* output:12:34:56: tool1: abc*/ reporter/* output:12:34:56: abc*/ reporter/* output:12:34:56: abctool2: def*/ reporter/* output:12:34:56: abctool2: def12:34:56: tool3: ghi12:34:56: tool3: jkl*/