diff --git a/lib/elements/prompt.js b/lib/elements/prompt.js index 6a6ea59a..95a4e0ff 100644 --- a/lib/elements/prompt.js +++ b/lib/elements/prompt.js @@ -1,9 +1,9 @@ 'use strict'; const readline = require('readline'); -const { action } = require('../util'); +const { action, clear} = require('../util'); const EventEmitter = require('events'); -const { beep, cursor } = require('sisteransi'); +const { beep, cursor, erase } = require('sisteransi'); /** * Base prompt skeleton @@ -16,7 +16,7 @@ class Prompt extends EventEmitter { this.out = process.stdout; const rl = readline.createInterface(this.in); - readline.emitKeypressEvents(this.in, this.rl); + readline.emitKeypressEvents(this.in, rl); if (this.in.isTTY) { this.in.setRawMode(true); @@ -36,7 +36,12 @@ class Prompt extends EventEmitter { const close = () => { this.out.write(cursor.show); this.in.removeListener('keypress', keypress); - this.in.setRawMode(false); + if (this.in.isTTY) { + this.in.setRawMode(false); + } else { + this.clear = clear(this.prompt) + this.out.write(this.clear); + } rl.close(); this.emit(this.aborted ? 'abort' : 'submit', this.value); }; diff --git a/lib/elements/text.js b/lib/elements/text.js index 6a75d4a8..1e325e03 100644 --- a/lib/elements/text.js +++ b/lib/elements/text.js @@ -86,17 +86,17 @@ class TextPrompt extends Prompt { } render() { - const prompt = [ + this.prompt = [ stl.symbol(this.done, this.aborted), color.bold(this.msg), stl.delimiter(this.done), this.rendered ].join(' '); - this.out.write(this.clear + prompt); + this.out.write(this.clear + this.prompt); this.out.write(cursor.move(-this.rendered.length + this.cursor)); - this.clear = clear(prompt); + this.clear = clear(this.prompt); } }