misty
TypeScript icon, indicating that this package has built-in type declarations

1.6.10 • Public • Published

misty

npm Code style: Prettier Donate

Logging utils for command line

 

Example

Clone misty and run the test.js script.

git clone https://github.com/alloc/misty
node misty/test.js

 

Usage

import {
  isInteractive,
  warn,
  warnOnce,
  fatal,
  success,
  clear,
  print,
} from 'misty'

if (isInteractive) {
  // Prompt the user or something.
}

// Print a yellow message with [!] in front.
warn('Be careful')

// Like `warn` but messages are deduplicated.
warnOnce('Deprecated: Use foo instead')

// Print a message to stderr with red [!] in front. Then call process.exit(1)
fatal('Bollocks')

// Print a message with green checkmark in front.
success('We did it!')

// Clear the screen and scrollback.
clear()

// Clear two lines above the cursor.
clear(2)

// Like console.log without a line break. Useful for control sequences.
print('...')

 

Tasks

The misty/task module provides the startTask function, which helps you communicate what your script is doing without spamming the final output. Task logs are transient, so it's best to avoid using tasks for information that could be useful for debugging.

Tasks are logs that:

  • have a spinner in front
  • stick to the end
  • can be updated
  • can be finished
  • print their elapsed time
import { startTask } from 'misty/task'

const task = startTask('Building…')
task.update('Analyzing…')
task.finish('Build completed')

What else should you know?

  • Multiple tasks can be active at once.
  • Call finish with no message to hide the task.

 

Spinner

The misty/spin module provides functions to customize the spinner and build your own task-like messages.

import { setSpinner } from 'misty/spin'

// Customize the spinner!
setSpinner({
  interval: 50,
  frames: ['◐', '◓', '◑', '◒'],
  color: require('kleur').magenta,
})

// These are for advanced usage.
import { spin, spinListeners, getSpinner } from 'misty/spin'

What else should you know?

  • Animating multiple different spinners is not supported.
  • Tasks use the spinner passed to setSpinner.

 

Prompts

Prompts are not supported by misty, but I recommend these packages:

 

Colors

Color support is provided by kleur, so you should use that too.

 

Logging

Logs are handled by shared-log.

Readme

Keywords

none

Package Sidebar

Install

npm i misty

Weekly Downloads

63

Version

1.6.10

License

MIT

Unpacked Size

38.1 kB

Total Files

35

Last publish

Collaborators

  • aleclarson