diff --git a/src/Concerns/TypedValue.php b/src/Concerns/TypedValue.php index c4cddbd..3d486b3 100644 --- a/src/Concerns/TypedValue.php +++ b/src/Concerns/TypedValue.php @@ -53,7 +53,7 @@ protected function trackTypedValue(string $default = '', bool $submit = true, ?c return; } - if ($key === Key::ENTER) { + if ($key === Key::ENTER || $key === Key::CR) { if ($submit) { $this->submit(); diff --git a/src/ConfirmPrompt.php b/src/ConfirmPrompt.php index 3abccf0..c092806 100644 --- a/src/ConfirmPrompt.php +++ b/src/ConfirmPrompt.php @@ -30,7 +30,7 @@ public function __construct( 'y' => $this->confirmed = true, 'n' => $this->confirmed = false, Key::TAB, Key::UP, Key::UP_ARROW, Key::DOWN, Key::DOWN_ARROW, Key::LEFT, Key::LEFT_ARROW, Key::RIGHT, Key::RIGHT_ARROW, Key::CTRL_P, Key::CTRL_F, Key::CTRL_N, Key::CTRL_B, 'h', 'j', 'k', 'l' => $this->confirmed = ! $this->confirmed, - Key::ENTER => $this->submit(), + Key::ENTER, Key::CR => $this->submit(), default => null, }); } diff --git a/src/Key.php b/src/Key.php index 21b8bf2..237ac6a 100644 --- a/src/Key.php +++ b/src/Key.php @@ -32,6 +32,8 @@ class Key const ENTER = "\n"; + const CR = "\r"; + const SPACE = ' '; const TAB = "\t"; diff --git a/src/MultiSearchPrompt.php b/src/MultiSearchPrompt.php index 25fcdfe..ce92742 100644 --- a/src/MultiSearchPrompt.php +++ b/src/MultiSearchPrompt.php @@ -57,7 +57,7 @@ public function __construct( Key::SPACE => $this->highlighted !== null ? $this->toggleHighlighted() : null, Key::CTRL_A => $this->highlighted !== null ? $this->toggleAll() : null, Key::CTRL_E => null, - Key::ENTER => $this->submit(), + Key::ENTER, Key::CR => $this->submit(), Key::LEFT, Key::LEFT_ARROW, Key::RIGHT, Key::RIGHT_ARROW => $this->highlighted = null, default => $this->search(), }); diff --git a/src/MultiSelectPrompt.php b/src/MultiSelectPrompt.php index c28bedf..c7c69e4 100644 --- a/src/MultiSelectPrompt.php +++ b/src/MultiSelectPrompt.php @@ -59,7 +59,7 @@ public function __construct( Key::oneOf(Key::END, $key) => $this->highlight(count($this->options) - 1), Key::SPACE => $this->toggleHighlighted(), Key::CTRL_A => $this->toggleAll(), - Key::ENTER => $this->submit(), + Key::ENTER, Key::CR => $this->submit(), default => null, }); } diff --git a/src/PausePrompt.php b/src/PausePrompt.php index 5556aa5..ed99855 100644 --- a/src/PausePrompt.php +++ b/src/PausePrompt.php @@ -13,7 +13,7 @@ public function __construct(public string $message = 'Press enter to continue... $this->validate = null; $this->on('key', fn ($key) => match ($key) { - Key::ENTER => $this->submit(), + Key::ENTER, Key::CR => $this->submit(), default => null, }); } diff --git a/src/SearchPrompt.php b/src/SearchPrompt.php index 259b429..e859bf1 100644 --- a/src/SearchPrompt.php +++ b/src/SearchPrompt.php @@ -46,7 +46,7 @@ public function __construct( Key::DOWN, Key::DOWN_ARROW, Key::TAB, Key::CTRL_N => $this->highlightNext(count($this->matches), true), Key::oneOf([Key::HOME, Key::CTRL_A], $key) => $this->highlighted !== null ? $this->highlight(0) : null, Key::oneOf([Key::END, Key::CTRL_E], $key) => $this->highlighted !== null ? $this->highlight(count($this->matches()) - 1) : null, - Key::ENTER => $this->highlighted !== null ? $this->submit() : $this->search(), + Key::ENTER, Key::CR => $this->highlighted !== null ? $this->submit() : $this->search(), Key::oneOf([Key::LEFT, Key::LEFT_ARROW, Key::RIGHT, Key::RIGHT_ARROW, Key::CTRL_B, Key::CTRL_F], $key) => $this->highlighted = null, default => $this->search(), }); diff --git a/src/SelectPrompt.php b/src/SelectPrompt.php index 8d48a73..0bdb025 100644 --- a/src/SelectPrompt.php +++ b/src/SelectPrompt.php @@ -55,7 +55,7 @@ public function __construct( Key::DOWN, Key::DOWN_ARROW, Key::RIGHT, Key::RIGHT_ARROW, Key::TAB, Key::CTRL_N, Key::CTRL_F, 'j', 'l' => $this->highlightNext(count($this->options)), Key::oneOf([Key::HOME, Key::CTRL_A], $key) => $this->highlight(0), Key::oneOf([Key::END, Key::CTRL_E], $key) => $this->highlight(count($this->options) - 1), - Key::ENTER => $this->submit(), + Key::ENTER, Key::CR => $this->submit(), default => null, }); } diff --git a/src/SuggestPrompt.php b/src/SuggestPrompt.php index 73efbdc..a0e0b48 100644 --- a/src/SuggestPrompt.php +++ b/src/SuggestPrompt.php @@ -50,7 +50,7 @@ public function __construct( Key::DOWN, Key::DOWN_ARROW, Key::TAB, Key::CTRL_N => $this->highlightNext(count($this->matches()), true), Key::oneOf([Key::HOME, Key::CTRL_A], $key) => $this->highlighted !== null ? $this->highlight(0) : null, Key::oneOf([Key::END, Key::CTRL_E], $key) => $this->highlighted !== null ? $this->highlight(count($this->matches()) - 1) : null, - Key::ENTER => $this->selectHighlighted(), + Key::ENTER, Key::CR => $this->selectHighlighted(), Key::oneOf([Key::LEFT, Key::LEFT_ARROW, Key::RIGHT, Key::RIGHT_ARROW, Key::CTRL_B, Key::CTRL_F], $key) => $this->highlighted = null, default => (function () { $this->highlighted = null;