From 5055370bb0e0adebaa171c7dcced69b63ddc3bbd Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Wed, 25 Mar 2020 09:57:02 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20issue=20when=20process.st?= =?UTF-8?q?din=20could=20be=20not=20an=20interactive?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/kittik-deck/src/Deck.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/kittik-deck/src/Deck.ts b/src/kittik-deck/src/Deck.ts index 3a444f6..478da0e 100644 --- a/src/kittik-deck/src/Deck.ts +++ b/src/kittik-deck/src/Deck.ts @@ -2,6 +2,7 @@ import { Canvas } from 'terminal-canvas'; import { DeckDeclaration } from './DeckDeclaration'; import { Slide } from 'kittik-slide'; import readline from 'readline'; +import tty from 'tty'; export { DeckDeclaration } from './DeckDeclaration'; @@ -32,9 +33,12 @@ export class Deck { } private initKeyboard (): void { + if (process.stdin instanceof tty.ReadStream) { + process.stdin.setRawMode(true); + process.stdin.setEncoding('utf8'); + } + readline.emitKeypressEvents(process.stdin); - process.stdin.setRawMode(true); - process.stdin.setEncoding('utf8'); process.stdin.on('keypress', this.onKeyPress.bind(this)); }