Skip to content

Commit

Permalink
Reset colors at the end of lines
Browse files Browse the repository at this point in the history
This is necessary if the gauge line had color codes but the display wasn't
wide enough to display the in-line color reset code.
  • Loading branch information
iarna committed Apr 21, 2017
1 parent 2defcdb commit 7986688
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions plumbing.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ Plumbing.prototype.show = function (status) {
}

return renderTemplate(this.width, this.template, values).trim() +
consoleControl.color('reset') +
consoleControl.eraseLine() + consoleControl.gotoSOL()
}
11 changes: 6 additions & 5 deletions test/plumbing.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var Plumbing = requireInject('../plumbing.js', {
'console-control-strings': {
eraseLine: function () { return 'ERASE' },
gotoSOL: function () { return 'CR' },
color: function (to) { return 'COLOR:' + to },
hideCursor: function () { return 'HIDE' },
showCursor: function () { return 'SHOW' }
}
Expand Down Expand Up @@ -37,30 +38,30 @@ test('hide', function (t) {
})

test('show', function (t) {
t.is(plumbing.show({name: 'test'}), 'w:10, t:[{"type":"name"}], v:{"name":"test"}ERASECR')
t.is(plumbing.show({name: 'test'}), 'w:10, t:[{"type":"name"}], v:{"name":"test"}COLOR:resetERASECR')
t.end()
})

test('width', function (t) {
var plumbing = new Plumbing(theme, template)
t.is(plumbing.show({name: 'test'}), 'w:80, t:[{"type":"name"}], v:{"name":"test"}ERASECR')
t.is(plumbing.show({name: 'test'}), 'w:80, t:[{"type":"name"}], v:{"name":"test"}COLOR:resetERASECR')
t.end()
})

test('setTheme', function (t) {
plumbing.setTheme({x: 'abc'})
t.is(plumbing.show({name: 'test'}), 'w:10, t:[{"type":"name"}], v:{"name":"test","x":"abc"}ERASECR')
t.is(plumbing.show({name: 'test'}), 'w:10, t:[{"type":"name"}], v:{"name":"test","x":"abc"}COLOR:resetERASECR')
t.end()
})

test('setTemplate', function (t) {
plumbing.setTemplate([{type: 'name'}, {type: 'x'}])
t.is(plumbing.show({name: 'test'}), 'w:10, t:[{"type":"name"},{"type":"x"}], v:{"name":"test","x":"abc"}ERASECR')
t.is(plumbing.show({name: 'test'}), 'w:10, t:[{"type":"name"},{"type":"x"}], v:{"name":"test","x":"abc"}COLOR:resetERASECR')
t.end()
})

test('setWidth', function (t) {
plumbing.setWidth(20)
t.is(plumbing.show({name: 'test'}), 'w:20, t:[{"type":"name"},{"type":"x"}], v:{"name":"test","x":"abc"}ERASECR')
t.is(plumbing.show({name: 'test'}), 'w:20, t:[{"type":"name"},{"type":"x"}], v:{"name":"test","x":"abc"}COLOR:resetERASECR')
t.end()
})

0 comments on commit 7986688

Please sign in to comment.