Skip to content
This repository has been archived by the owner on Nov 6, 2023. It is now read-only.

Commit

Permalink
Improve silent mode (#20)
Browse files Browse the repository at this point in the history
* Make activity() respect silent mode

* Make progress() respect silent mode

* Disable activity and progress in CI environment

* Update readme with text about silent mode
  • Loading branch information
0x80 authored Jan 22, 2020
1 parent aa39b82 commit 7f9f722
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 15 deletions.
54 changes: 41 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ An elegant console reporter, borrowed from [Yarn](https://yarnpkg.com).

## Introduction

Pretty console output makes developers happy and Yarn is doing a nice job. Yurnalist takes the internal console reporter code from Yarn and makes it available for use in other Node.js applications.
Pretty console output makes developers happy and Yarn is doing a nice job.
Yurnalist takes the internal console reporter code from Yarn and makes it
available for use in other Node.js applications.

The current version is based on code from Yarn v1.13.0.

Expand Down Expand Up @@ -80,7 +82,9 @@ Node >= 4

## Examples

Examples showing different API functions are found in [/examples](/examples). You can run them directly with node >= 7.6 (because of async/await syntax). For older versions you could use the `--harmony` flag, or otherwise Babel.
Examples showing different API functions are found in [/examples](/examples).
You can run them directly with node >= 7.6 (because of async/await syntax). For
older versions you could use the `--harmony` flag, or otherwise Babel.

To run the activity example:

Expand All @@ -90,7 +94,9 @@ node examples/activity.js

## Configuration

A normal import gives you a reporter instance configured with defaults for easy use. If you want something else you can call `createReporter(options)` to give you an instance with different options.
A normal import gives you a reporter instance configured with defaults for easy
use. If you want something else you can call `createReporter(options)` to give
you an instance with different options.

### Options

Expand Down Expand Up @@ -126,11 +132,26 @@ const defaults = {
}
```

The peekMemoryCounter is disabled by default. If you enable it, you'll have to call `reporter.close()` to stop its running timer. Otherwise your program will not exit. The memory counter can be used to display in the footer data.
The peekMemoryCounter is disabled by default. If you enable it, you'll have to
call `reporter.close()` to stop its running timer. Otherwise your program will
not exit. The memory counter can be used to display in the footer data.

## Silent Mode and CI

Silent mode can be set via the options passed to createReporter. It disables
output for various functions like `info`, `list`, `activity` and `progress`. The
output from `warning` and `error` messages is not silenced.

Silent mode can also be enabled with the `YURNALIST_SILENT` environment
variable.

In CI environments the output from `activity` and `progress` is disabled.

## API

The API still needs some documentation, but most methods are straightforward. In the meantime you can also look at the [examples](./examples) and possibly even the [tests](./__tests__).
The API still needs some documentation, but most methods are straightforward. In
the meantime you can also look at the [examples](./examples) and possibly even
the [tests](./__tests__).

The following functions are available:

Expand All @@ -142,10 +163,10 @@ The following functions are available:

Pretty-prints the `thing`.

### list(key: string, items: Array<string>, hints?: Object)
### list(key: string, items: Array<string>, hints?: Object)

Generates a list of the provided items. Turns into a definition
list if `hints` are provided. Note that the `key` is not used.
Generates a list of the provided items. Turns into a definition list if `hints`
are provided. Note that the `key` is not used.

Example of a simple list:

Expand Down Expand Up @@ -184,7 +205,7 @@ report.list('dunno', someList, hints);
```
generates
```
info My grocery list
info My grocery list
- bananas
for baking
- tulips
Expand Down Expand Up @@ -214,13 +235,18 @@ info My grocery list

## Language

Yarn uses a language file for certain messages. For example if you try to skip a required question, or when you pick an invalid item from a select. This language file is not yet exposed in the Yurnalist API. The only supported language is English, as it is in Yarn at the moment.
Yarn uses a language file for certain messages. For example if you try to skip a
required question, or when you pick an invalid item from a select. This language
file is not yet exposed in the Yurnalist API. The only supported language is
English, as it is in Yarn at the moment.

I plan to make this configurable so that you can define your own messages in your own language .
I plan to make this configurable so that you can define your own messages in
your own language .

## Emojis

You can use Emojis in your output. Yurnalist should disable them if they are not allowed in the application environment.
You can use Emojis in your output. Yurnalist should disable them if they are not
allowed in the application environment.

Check:

Expand All @@ -229,4 +255,6 @@ Check:

## Credits

Of course ❤️ and credits to all the contributers of [Yarn](https://yarnpkg.com). The ease with which I was able to extract this module from their codebase is proving some awesome engineering skills.
Of course ❤️ and credits to all the contributers of [Yarn](https://yarnpkg.com).
The ease with which I was able to extract this module from their codebase is
proving some awesome engineering skills.
5 changes: 3 additions & 2 deletions src/reporters/console/console-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {clearLine} from './util.js';
import {removeSuffix} from '../../util/misc.js';
import {sortTrees, recurseTree, getFormattedOutput} from './helpers/tree-helper.js';
import inquirer from 'inquirer';
import isCI from 'is-ci';

const {inspect} = require('util');
const readline = require('readline');
Expand Down Expand Up @@ -321,7 +322,7 @@ export default class ConsoleReporter extends BaseReporter {
}
activity(): ReporterSpinner {
if (!this.isTTY) {
if (!this.isTTY || this.isSilent || isCI) {
return {
tick() {},
end() {},
Expand Down Expand Up @@ -411,7 +412,7 @@ export default class ConsoleReporter extends BaseReporter {
};
}

if (!this.isTTY) {
if (!this.isTTY || this.isSilent || isCI) {
return function() {
// TODO what should the behaviour here be? we could buffer progress messages maybe
};
Expand Down

0 comments on commit 7f9f722

Please sign in to comment.