Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: possible fix for isTTY and GitBash #36

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions lib/elements/prompt.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still have to look into this. The second param to emitKeypressEvents is optional - do we even need it?

Also have to dig deeper into createInterface options like crlfDelay and terminal
https://nodejs.org/api/readline.html#readline_readline_createinterface_options


if (this.in.isTTY) {
this.in.setRawMode(true);
Expand All @@ -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);
};
Expand Down
6 changes: 3 additions & 3 deletions lib/elements/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down