Skip to content

Commit

Permalink
feat(fancy): support icon field
Browse files Browse the repository at this point in the history
  • Loading branch information
Pooya Parsa committed May 27, 2018
1 parent 7a750bf commit 0123bed
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ Extended fields:
- `badge`
- `additional`
- `additionalStyle` (By default: `grey`)
- `icon` (Default depends on log type)

## Integrations

Expand Down
11 changes: 6 additions & 5 deletions src/reporters/fancy.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ export default class FancyReporter {
this.stream = stream || process.stderr
}

formatBadge (type, color = 'blue') {
formatBadge (type, color = 'blue', icon) {
return chalk['bg' + startCase(color)].black(` ${type.toUpperCase()} `) + ' '
}

formatTag (type, color = 'blue') {
const icon = ICONS[type] || ICONS.default
formatTag (type, color = 'blue', icon) {
return chalk[color](`${icon} ${type.toLowerCase()}`) + ' '
}

Expand All @@ -48,10 +47,12 @@ export default class FancyReporter {
this.clear()
}

const icon = logObj.icon || ICONS[type] || ICONS.default

if (logObj.badge) {
this.stream.write('\n\n' + this.formatBadge(logObj.type, logObj.color) + message + '\n\n')
this.stream.write('\n\n' + this.formatBadge(logObj.type, logObj.color, icon) + message + '\n\n')
} else {
this.stream.write(this.formatTag(logObj.type, logObj.color) + message + '\n')
this.stream.write(this.formatTag(logObj.type, logObj.color, icon) + message + '\n')
}

if (logObj.additional) {
Expand Down

0 comments on commit 0123bed

Please sign in to comment.