Skip to content

Commit

Permalink
polish: accept Enter as a valid key in confirm dialogs (#887)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
threepointone authored May 4, 2022
1 parent fd3517a commit 2bb4d30
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .changeset/tasty-pets-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"wrangler": patch
---

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.
9 changes: 6 additions & 3 deletions packages/wrangler/src/dialogs.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import chalk from "chalk";
import { Box, Text, useInput, render } from "ink";
import TextInput from "ink-text-input";
import * as React from "react";
Expand All @@ -8,8 +9,8 @@ type ConfirmProps = {
onConfirm: (answer: boolean) => void;
};
function Confirm(props: ConfirmProps) {
useInput((input: string) => {
if (input === "y") {
useInput((input: string, key) => {
if (input === "y" || key.return === true) {
props.onConfirm(true);
} else if (input === "n") {
props.onConfirm(false);
Expand All @@ -19,7 +20,9 @@ function Confirm(props: ConfirmProps) {
});
return (
<Box>
<Text>{props.text} (y/n) </Text>
<Text>
{props.text} ({chalk.bold("y")}/n)
</Text>
</Box>
);
}
Expand Down

0 comments on commit 2bb4d30

Please sign in to comment.