Skip to content

Add new methods to toolbox.print (highlight and muted) (Fixes #726) #731

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions docs/toolbox-print.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,26 @@ Well, if your next line of code isn't `process.exit(0)`, then it was probably a
toolbox.print.error('Out of disk space. lol.')
```

## highlight

Prints a message that's intended to have attention drawn to it.
You could use it to point out the correct command to be run in an error message.
Or you could use it to head sections of your help screen printout.

```js
toolbox.print.highlight('Run `gluegun login` to login')
```

## muted

Prints a message in a muted gray color.
This is useful for info that's not the most important but still helpful.
Think of mundane or commonplace lines in output logging, for example.

```js
toolbox.print.muted('Connection status: GOOD')
```

## debug

Only used for debugging your plugins. You can pass this function a string or an object.
Expand All @@ -55,13 +75,14 @@ however we define a theme to make things a bit consistent.

Some available functions include:

| function | use when you want... |
| ------------------ | ---------------------------------------- |
| `colors.success()` | the user to smile |
| `colors.error()` | to say something has failed |
| `colors.warning()` | to point out that something might be off |
| `colors.info()` | to say something informational |
| `colors.muted()` | you need to say something secondary |
| function | use when you want... |
| -------------------- | ---------------------------------------- |
| `colors.success()` | the user to smile |
| `colors.error()` | to say something has failed |
| `colors.warning()` | to point out that something might be off |
| `colors.highlight()` | to draw attention to something |
| `colors.info()` | to say something informational |
| `colors.muted()` | you need to say something secondary |

Each take a `string` parameter and return a `string`.

Expand Down
1 change: 0 additions & 1 deletion package-manager.js

This file was deleted.

8 changes: 8 additions & 0 deletions src/toolbox/__snapshots__/print-tools.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ Array [
"success!!",
undefined,
],
Array [
"highlight",
undefined,
],
Array [
"muted",
undefined,
],
Array [
"error...",
undefined,
Expand Down
2 changes: 2 additions & 0 deletions src/toolbox/print-tools.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ test('info', () => {
print.info('info')
print.warning('warning!')
print.success('success!!')
print.highlight('highlight')
print.muted('muted')
print.error('error...')
print.debug('debugging...')
const title = 'there'
Expand Down
8 changes: 8 additions & 0 deletions src/toolbox/print-tools.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ Generated by [AVA](https://ava.li).
'success!!',
undefined,
],
[
'highlight',
undefined,
],
[
'muted',
undefined,
]
[
'error...',
undefined,
Expand Down
25 changes: 25 additions & 0 deletions src/toolbox/print-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ function table(data: string[][], options: GluegunPrintTableOptions = {}): void {
let t
switch (options.format) {
case 'markdown':
// eslint-disable-next-line no-case-declarations
const header = data.shift()
t = new CLITable({
head: header,
Expand Down Expand Up @@ -185,6 +186,28 @@ function success(message: string): void {
console.log(colors.success(message))
}

/**
* Writes a highlighted message.
*
* To draw attention to specific lines. Use sparingly.
*
* @param message The message to show.
*/
function highlight(message: string): void {
console.log(colors.highlight(message))
}

/**
* Writes a muted message.
*
* For ancillary info, something that's not the star of the show.
*
* @param message The message to show.
*/
function muted(message: string): void {
console.log(colors.muted(message))
}

/**
* Creates a spinner and starts it up.
*
Expand Down Expand Up @@ -232,6 +255,8 @@ const print: GluegunPrint = {
warning,
debug,
success,
highlight,
muted,
spin,
printCommands,
printHelp,
Expand Down
4 changes: 4 additions & 0 deletions src/toolbox/print-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export interface GluegunPrint {
warning: (message: any) => void
/* Prints a success-colored message. */
success: (message: any) => void
/* Prints a highlighted (cyan) message. */
highlight: (message: any) => void
/* Prints a muted (grey) message. */
muted: (message: any) => void
/* Prints an error-colored message. */
error: (message: any) => void
/* Prints debug information about any data, with an optional title. */
Expand Down