Skip to content

Commit 34e8ed2

Browse files
authored
fix: make it work again in Deno < 1.40 (#215)
1 parent 90af734 commit 34e8ed2

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/console/utils.ts

+17-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,22 @@ export function showCursor() {
6868
Deno.stderr.writeSync(encoder.encode("\x1B[?25h"));
6969
}
7070

71-
export const isOutputTty = safeConsoleSize() != null && Deno.stderr.isTerminal();
71+
export const isOutputTty = safeConsoleSize() != null && isTerminal(Deno.stderr);
72+
73+
function isTerminal(pipe: { isTerminal?(): boolean; rid?: number }) {
74+
if (typeof pipe.isTerminal === "function") {
75+
return pipe.isTerminal();
76+
} else if (
77+
pipe.rid != null &&
78+
// deno-lint-ignore no-deprecated-deno-api
79+
typeof Deno.isatty === "function"
80+
) {
81+
// deno-lint-ignore no-deprecated-deno-api
82+
return Deno.isatty(pipe.rid);
83+
} else {
84+
throw new Error("Unsupported pipe.");
85+
}
86+
}
7287

7388
export function resultOrExit<T>(result: T | undefined): T {
7489
if (result == null) {
@@ -86,7 +101,7 @@ export interface SelectionOptions<TReturn> {
86101
}
87102

88103
export function createSelection<TReturn>(options: SelectionOptions<TReturn>): Promise<TReturn | undefined> {
89-
if (!isOutputTty || !Deno.stdin.isTerminal()) {
104+
if (!isOutputTty || !isTerminal(Deno.stdin)) {
90105
throw new Error(`Cannot prompt when not a tty. (Prompt: '${options.message}')`);
91106
}
92107
if (safeConsoleSize() == null) {

0 commit comments

Comments
 (0)