Skip to content
Merged
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
4 changes: 2 additions & 2 deletions cli/_prompt_select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ const SAFE_PADDING = 4;
const MORE_CONTENT_BEFORE_INDICATOR = "...";
const MORE_CONTENT_AFTER_INDICATOR = "...";

const input = Deno.stdin;
const output = Deno.stdout;
const encoder = new TextEncoder();
const decoder = new TextDecoder();

Expand Down Expand Up @@ -40,6 +38,8 @@ export function handlePromptSelect<V>(
inputStr(): void;
}) => boolean | "return",
) {
const input = Deno.stdin;
const output = Deno.stdout;
const indexedValues = values.map((value, absoluteIndex) => ({
value,
absoluteIndex,
Expand Down
15 changes: 7 additions & 8 deletions cli/prompt_secret.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright 2018-2025 the Deno authors. MIT license.

const input = Deno.stdin;
const output = Deno.stdout;
import { isWindows } from "@std/internal/os";
const encoder = new TextEncoder();
const decoder = new TextDecoder();
const LF = "\n".charCodeAt(0); // ^J - Enter on Linux
Expand All @@ -12,9 +11,7 @@ const CLR = encoder.encode("\r\u001b[K"); // Clear the current line
const MOVE_LINE_UP = encoder.encode("\r\u001b[1F"); // Move to previous line

// The `cbreak` option is not supported on Windows
const setRawOptions = Deno.build.os === "windows"
? undefined
: { cbreak: true };
const setRawOptions = isWindows ? undefined : { cbreak: true };

/** Options for {@linkcode promptSecret}. */
export type PromptSecretOptions = {
Expand Down Expand Up @@ -47,6 +44,8 @@ export function promptSecret(
message = "Secret",
options?: PromptSecretOptions,
): string | null {
const input = Deno.stdin;
const output = Deno.stdout;
const { mask = "*", clear } = options ?? {};

if (!input.isTerminal()) {
Expand Down Expand Up @@ -90,7 +89,7 @@ export function promptSecret(

output.writeSync(encoder.encode(message));

Deno.stdin.setRaw(true, setRawOptions);
input.setRaw(true, setRawOptions);
try {
return readLineFromStdinSync(callback);
} finally {
Expand All @@ -99,7 +98,7 @@ export function promptSecret(
} else {
output.writeSync(encoder.encode("\n"));
}
Deno.stdin.setRaw(false);
input.setRaw(false);
}
}

Expand All @@ -112,7 +111,7 @@ function readLineFromStdinSync(callback?: (n: number) => void): string {
const buf = [];

while (true) {
const n = input.readSync(c);
const n = Deno.stdin.readSync(c);
if (n === null || n === 0) {
break;
}
Expand Down
4 changes: 1 addition & 3 deletions cli/unstable_prompt_multiple_select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ const DELETE = "\u007F";
const CHECKED = "◉";
const UNCHECKED = "◯";

const input = Deno.stdin;

/**
* Shows the given message and waits for the user's input. Returns the user's selected value as string.
*
Expand Down Expand Up @@ -105,7 +103,7 @@ export function promptMultipleSelect<V = undefined>(
values: PromptEntry<V>[],
options: PromptMultipleSelectOptions = {},
): PromptEntry<V>[] | null {
if (!input.isTerminal()) return null;
if (!Deno.stdin.isTerminal()) return null;

const selectedAbsoluteIndexes = new Set<number>();

Expand Down
4 changes: 1 addition & 3 deletions cli/unstable_prompt_select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ const ARROW_DOWN = "\u001B[B";
const CR = "\r";
const DELETE = "\u007F";

const input = Deno.stdin;

/**
* Shows the given message and waits for the user's input. Returns the user's selected value as string.
*
Expand Down Expand Up @@ -104,7 +102,7 @@ export function promptSelect<V = undefined>(
values: PromptEntry<V>[],
options: PromptSelectOptions = {},
): PromptEntry<V> | null {
if (!input.isTerminal()) return null;
if (!Deno.stdin.isTerminal()) return null;

let selectedIndex = 0;

Expand Down
Loading