diff options
author | Liam <towerofnix@gmail.com> | 2017-01-07 18:26:02 -0400 |
---|---|---|
committer | Liam <towerofnix@gmail.com> | 2017-01-07 18:26:02 -0400 |
commit | 16da7fb310198851c2e4b02abedfb24979287242 (patch) | |
tree | d7546f7c1a3c3833e6450ea1e10af388f8848bb5 /ui/Label.js |
Initial commit
Diffstat (limited to 'ui/Label.js')
-rw-r--r-- | ui/Label.js | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/ui/Label.js b/ui/Label.js new file mode 100644 index 0000000..60ece15 --- /dev/null +++ b/ui/Label.js @@ -0,0 +1,39 @@ +const ansi = require('../ansi') + +const DisplayElement = require('./DisplayElement') + +module.exports = class Label extends DisplayElement { + // A simple text display. Automatically adjusts size to fit text. + + constructor(text='') { + super() + + this.text = text + this.textAttributes = [] + } + + drawTo(writable) { + if (this.textAttributes.length) { + writable.write(ansi.setAttributes(this.textAttributes)) + } + + writable.write(ansi.moveCursor(this.absTop, this.absLeft)) + writable.write(this.text) + + if (this.textAttributes.length) { + writable.write(ansi.resetAttributes()) + } + + super.drawTo(writable) + } + + set text(newText) { + this._text = newText + + this.w = newText.length + } + + get text() { + return this._text + } +} |