diff options
-rw-r--r-- | examples/list-scroll-form.js | 2 | ||||
-rw-r--r-- | ui/Root.js | 6 | ||||
-rw-r--r-- | ui/form/FocusElement.js | 1 | ||||
-rw-r--r-- | ui/form/TextInput.js | 1 | ||||
-rw-r--r-- | util/ansi.js | 6 |
5 files changed, 12 insertions, 4 deletions
diff --git a/examples/list-scroll-form.js b/examples/list-scroll-form.js index a68cb78..cb7fa27 100644 --- a/examples/list-scroll-form.js +++ b/examples/list-scroll-form.js @@ -13,6 +13,7 @@ interfacer.getScreenSize().then(size => { const list = new ListScrollForm() root.addChild(list) + list.x = 2 list.y = 2 list.w = root.contentW - 4 @@ -23,6 +24,7 @@ interfacer.getScreenSize().then(size => { list.addInput(button) button.on('pressed', () => { + process.stdout.write(ansi.cleanCursor()) process.stdout.write(ansi.clearScreen()) console.log(item) process.exit(0) diff --git a/ui/Root.js b/ui/Root.js index b170f99..fc494a7 100644 --- a/ui/Root.js +++ b/ui/Root.js @@ -50,9 +50,7 @@ module.exports = class Root extends DisplayElement { // Render the cursor, based on the cursorX and cursorY of the currently // selected element. if ( - this.selected && - typeof this.selected.cursorX === 'number' && - typeof this.selected.cursorY === 'number' && + this.selected && this.selected.cursorVisible && (Date.now() - this.cursorBlinkOffset) % 1000 < 500 ) { writable.write(ansi.moveCursor( @@ -61,7 +59,7 @@ module.exports = class Root extends DisplayElement { writable.write('I') writable.write(ansi.resetAttributes()) } - writable.write(ansi.moveCursor(0, 0)) + writable.write(ansi.hideCursor()) } cursorMoved() { diff --git a/ui/form/FocusElement.js b/ui/form/FocusElement.js index 5967e26..18f13bf 100644 --- a/ui/form/FocusElement.js +++ b/ui/form/FocusElement.js @@ -6,6 +6,7 @@ module.exports = class FocusElement extends DisplayElement { constructor() { super() + this.cursorVisible = false this.cursorX = 0 this.cursorY = 0 diff --git a/ui/form/TextInput.js b/ui/form/TextInput.js index fc59cbb..a10a26f 100644 --- a/ui/form/TextInput.js +++ b/ui/form/TextInput.js @@ -11,6 +11,7 @@ module.exports = class TextInput extends FocusElement { super() this.value = '' + this.cursorVisible = true this.cursorIndex = 0 this.scrollChars = 0 } diff --git a/util/ansi.js b/util/ansi.js index 0e6e3fe..0ee1bc1 100644 --- a/util/ansi.js +++ b/util/ansi.js @@ -43,6 +43,12 @@ const ansi = { return `${ESC}[${line + 1};${col + 1}H` }, + cleanCursor() { + // A combination of codes that generally cleans up the cursor. + + return ansi.resetAttributes() + ansi.showCursor() + }, + hideCursor() { // Makes the cursor invisible. |