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/form/Button.js |
Initial commit
Diffstat (limited to 'ui/form/Button.js')
-rw-r--r-- | ui/form/Button.js | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/ui/form/Button.js b/ui/form/Button.js new file mode 100644 index 0000000..9a3d2f7 --- /dev/null +++ b/ui/form/Button.js @@ -0,0 +1,49 @@ +const ansi = require('../../ansi') +const telc = require('../../telchars') + +const FocusElement = require('./FocusElement') + +module.exports = class ButtonInput extends FocusElement { + // A button. + + constructor(text) { + super() + + this.text = text + + this.cursorX = null + this.cursorY = null + } + + // Setting the text of the button should change the width of the button to + // fit the text. + // + // TODO: Make this happen in fixLayout + set text(newText) { + this._text = newText + this.w = newText.length + } + + get text() { + return this._text + } + + drawTo(writable) { + if (this.isSelected) { + writable.write(ansi.invert()) + } + + writable.write(ansi.moveCursor(this.absTop, this.absLeft)) + writable.write(this.text) + + writable.write(ansi.resetAttributes()) + + super.drawTo(writable) + } + + keyPressed(keyBuf) { + if (telc.isSelect(keyBuf)) { + this.emit('pressed') + } + } +} |