From 2bb4d30e0c50ec1c3d9d821c768fc711e8be4ca9 Mon Sep 17 00:00:00 2001 From: Sunil Pai Date: Wed, 4 May 2022 12:17:55 +0100 Subject: [PATCH] polish: accept Enter as a valid key in confirm dialogs (#887) 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. --- .changeset/tasty-pets-divide.md | 7 +++++++ packages/wrangler/src/dialogs.tsx | 9 ++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 .changeset/tasty-pets-divide.md diff --git a/.changeset/tasty-pets-divide.md b/.changeset/tasty-pets-divide.md new file mode 100644 index 000000000000..1fe435acb182 --- /dev/null +++ b/.changeset/tasty-pets-divide.md @@ -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. diff --git a/packages/wrangler/src/dialogs.tsx b/packages/wrangler/src/dialogs.tsx index 8afc0e895bf6..d7d7b2da57ea 100644 --- a/packages/wrangler/src/dialogs.tsx +++ b/packages/wrangler/src/dialogs.tsx @@ -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"; @@ -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); @@ -19,7 +20,9 @@ function Confirm(props: ConfirmProps) { }); return ( - {props.text} (y/n) + + {props.text} ({chalk.bold("y")}/n) + ); }