Skip to content

Commit

Permalink
Add setGaugeTemplate to let you control the progress bar template
Browse files Browse the repository at this point in the history
  • Loading branch information
iarna committed Feb 28, 2015
1 parent 0ea0343 commit 0cf07dd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ Force the unicode theme to be used for the progress bar.

Disable the use of unicode in the progress bar.

## log.setGaugeTemplate(template)

Overrides the default gauge template.

## log.pause()

Stop emitting messages to the stream, but do not drop them.
Expand Down
23 changes: 15 additions & 8 deletions log.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,22 @@ log.tracker = new Progress.TrackerGroup()
// no progress bars unless asked
log.progressEnabled = false

var unicodeEnabled = undefined
var gaugeTheme = undefined

log.enableUnicode = function () {
unicodeEnabled = true
log.gauge.setTheme(Gauge.unicode)
gaugeTheme = gauge.unicode
log.gauge.setTheme(gaugeTheme)
}

log.disableUnicode = function () {
unicodeEnabled = false
log.gauge.setTheme(Gauge.ascii)
gaugeTheme = gauge.ascii
log.gauge.setTheme(gaugeTheme)
}

var gaugeTemplate = undefined
log.setGaugeTemplate = function (template) {
gaugeTemplate = template
log.gauge.setTemplate(gaugeTemplate)
}

log.enableProgress = function () {
Expand Down Expand Up @@ -194,9 +202,8 @@ log.write = function (msg, style) {
if (this.stream !== this.cursor.stream) {
this.cursor = ansi(this.stream, { enabled: colorEnabled })
var options = {}
if (unicodeEnabled != null) {
options.theme = unicodeEnabled ? Gauge.unicode : Gauge.ascii
}
if (gaugeTheme != null) options.theme = gaugeTheme
if (gaugeTemplate != null) options.template = gaugeTemplate
this.gauge = new Gauge(options, this.cursor)
}

Expand Down

0 comments on commit 0cf07dd

Please sign in to comment.