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

Commit

Permalink
Improve list (#21)
Browse files Browse the repository at this point in the history
* Add title for lists with magenta category name

* Update examples and readme for list
  • Loading branch information
0x80 authored Jan 22, 2020
1 parent 7f9f722 commit 9c03169
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
24 changes: 11 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,24 +163,21 @@ The following functions are available:

Pretty-prints the `thing`.

### list(key: string, items: Array<string>, hints?: Object)
### list(title: 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.
are provided.

Example of a simple list:

```
const someList = ['bananas', 'tulips', 'eggs', 'bamischijf'];
report.info('My grocery list');
report.list('ignored', someList);
report.list('My grocery list', ['bananas', 'tulips', 'eggs', 'bamischijf']);
```

generates
Outputs:

```
info My grocery list
list My grocery list
- bananas
- tulips
- eggs
Expand All @@ -191,7 +188,7 @@ info My grocery list
Example with hints:

```
const someList = ['bananas', 'tulips', 'eggs', 'bamischijf'];
const items = ['bananas', 'tulips', 'eggs', 'bamischijf'];
const hints = {
bananas: 'for baking',
Expand All @@ -200,12 +197,13 @@ const hints = {
bamischijf: 'if they have it',
};
report.info('My grocery list');
report.list('dunno', someList, hints);
report.list('My grocery list', items, hints);
```
generates

Outputs:

```
info My grocery list
list My grocery list
- bananas
for baking
- tulips
Expand Down
6 changes: 2 additions & 4 deletions examples/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ const report = require('../dist');
/* eslint-disable flowtype/require-return-type */
const someList = ['bananas', 'tulips', 'eggs', 'bamischijf'];

report.info('My grocery list');
report.list('dunno', someList);
report.list('My grocery list', someList);

const hints = {
bananas: 'for baking',
Expand All @@ -13,5 +12,4 @@ const hints = {
bamischijf: 'if they have it',
};

report.info('The same list with hints');
report.list('dunno', someList, hints);
report.list('The same list with hints', someList, hints);
9 changes: 8 additions & 1 deletion src/reporters/console/console-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,14 @@ export default class ConsoleReporter extends BaseReporter {
this.log(String(value), {force: true});
}

list(key: string, items: Array<string>, hints?: Object) {
list(title: string, items: Array<string>, hints?: Object) {
/**
* Because in the original Yarn code list() is called starting with a "key:
* string" argument that is ignored, we don't assume that a title has been
* passed in or is a valid string, to avoid creating a breaking change.
*/
this._logCategory('list', 'magenta', typeof title === 'string' ? this.format.bold(title) : '');

const gutterWidth = (this._lastCategorySize || 2) - 1;

if (hints) {
Expand Down

0 comments on commit 9c03169

Please sign in to comment.