Skip to content

Commit 7db823f

Browse files
committed
polish: accept Enter as a valid key in confirm dialogs
Instead of logging "Unrecognised input" when hitting return/enter in a confirm dialog, we should accept it as a confirmation. This patch also makes the default choice "y" bold in the dialog.
1 parent 21af9ad commit 7db823f

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

.changeset/tasty-pets-divide.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
polish: accept Enter as a valid key in confirm dialogs
6+
7+
Instead of logging "Unrecognised input" when hitting return/enter in a confirm dialog, we should accept it as a confirmation. This patch also makes the default choice "y" bold in the dialog.

packages/wrangler/src/dialogs.tsx

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import chalk from "chalk";
12
import { Box, Text, useInput, render } from "ink";
23
import TextInput from "ink-text-input";
34
import * as React from "react";
@@ -8,8 +9,8 @@ type ConfirmProps = {
89
onConfirm: (answer: boolean) => void;
910
};
1011
function Confirm(props: ConfirmProps) {
11-
useInput((input: string) => {
12-
if (input === "y") {
12+
useInput((input: string, key) => {
13+
if (input === "y" || key.return === true) {
1314
props.onConfirm(true);
1415
} else if (input === "n") {
1516
props.onConfirm(false);
@@ -19,7 +20,9 @@ function Confirm(props: ConfirmProps) {
1920
});
2021
return (
2122
<Box>
22-
<Text>{props.text} (y/n) </Text>
23+
<Text>
24+
{props.text} ({chalk.bold("y")}/n)
25+
</Text>
2326
</Box>
2427
);
2528
}

0 commit comments

Comments
 (0)