Skip to content

Commit 3cfd29f

Browse files
committed
Support carriage returns
1 parent 42d9568 commit 3cfd29f

File tree

9 files changed

+10
-8
lines changed

9 files changed

+10
-8
lines changed

src/Concerns/TypedValue.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ protected function trackTypedValue(string $default = '', bool $submit = true, ?c
5353
return;
5454
}
5555

56-
if ($key === Key::ENTER) {
56+
if ($key === Key::ENTER || $key === Key::CR) {
5757
if ($submit) {
5858
$this->submit();
5959

src/ConfirmPrompt.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function __construct(
3030
'y' => $this->confirmed = true,
3131
'n' => $this->confirmed = false,
3232
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,
33-
Key::ENTER => $this->submit(),
33+
Key::ENTER, Key::CR => $this->submit(),
3434
default => null,
3535
});
3636
}

src/Key.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class Key
3232

3333
const ENTER = "\n";
3434

35+
const CR = "\r";
36+
3537
const SPACE = ' ';
3638

3739
const TAB = "\t";

src/MultiSearchPrompt.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function __construct(
5757
Key::SPACE => $this->highlighted !== null ? $this->toggleHighlighted() : null,
5858
Key::CTRL_A => $this->highlighted !== null ? $this->toggleAll() : null,
5959
Key::CTRL_E => null,
60-
Key::ENTER => $this->submit(),
60+
Key::ENTER, Key::CR => $this->submit(),
6161
Key::LEFT, Key::LEFT_ARROW, Key::RIGHT, Key::RIGHT_ARROW => $this->highlighted = null,
6262
default => $this->search(),
6363
});

src/MultiSelectPrompt.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function __construct(
5959
Key::oneOf(Key::END, $key) => $this->highlight(count($this->options) - 1),
6060
Key::SPACE => $this->toggleHighlighted(),
6161
Key::CTRL_A => $this->toggleAll(),
62-
Key::ENTER => $this->submit(),
62+
Key::ENTER, Key::CR => $this->submit(),
6363
default => null,
6464
});
6565
}

src/PausePrompt.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public function __construct(public string $message = 'Press enter to continue...
1313
$this->validate = null;
1414

1515
$this->on('key', fn ($key) => match ($key) {
16-
Key::ENTER => $this->submit(),
16+
Key::ENTER, Key::CR => $this->submit(),
1717
default => null,
1818
});
1919
}

src/SearchPrompt.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function __construct(
4646
Key::DOWN, Key::DOWN_ARROW, Key::TAB, Key::CTRL_N => $this->highlightNext(count($this->matches), true),
4747
Key::oneOf([Key::HOME, Key::CTRL_A], $key) => $this->highlighted !== null ? $this->highlight(0) : null,
4848
Key::oneOf([Key::END, Key::CTRL_E], $key) => $this->highlighted !== null ? $this->highlight(count($this->matches()) - 1) : null,
49-
Key::ENTER => $this->highlighted !== null ? $this->submit() : $this->search(),
49+
Key::ENTER, Key::CR => $this->highlighted !== null ? $this->submit() : $this->search(),
5050
Key::oneOf([Key::LEFT, Key::LEFT_ARROW, Key::RIGHT, Key::RIGHT_ARROW, Key::CTRL_B, Key::CTRL_F], $key) => $this->highlighted = null,
5151
default => $this->search(),
5252
});

src/SelectPrompt.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function __construct(
5555
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)),
5656
Key::oneOf([Key::HOME, Key::CTRL_A], $key) => $this->highlight(0),
5757
Key::oneOf([Key::END, Key::CTRL_E], $key) => $this->highlight(count($this->options) - 1),
58-
Key::ENTER => $this->submit(),
58+
Key::ENTER, Key::CR => $this->submit(),
5959
default => null,
6060
});
6161
}

src/SuggestPrompt.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function __construct(
5050
Key::DOWN, Key::DOWN_ARROW, Key::TAB, Key::CTRL_N => $this->highlightNext(count($this->matches()), true),
5151
Key::oneOf([Key::HOME, Key::CTRL_A], $key) => $this->highlighted !== null ? $this->highlight(0) : null,
5252
Key::oneOf([Key::END, Key::CTRL_E], $key) => $this->highlighted !== null ? $this->highlight(count($this->matches()) - 1) : null,
53-
Key::ENTER => $this->selectHighlighted(),
53+
Key::ENTER, Key::CR => $this->selectHighlighted(),
5454
Key::oneOf([Key::LEFT, Key::LEFT_ARROW, Key::RIGHT, Key::RIGHT_ARROW, Key::CTRL_B, Key::CTRL_F], $key) => $this->highlighted = null,
5555
default => (function () {
5656
$this->highlighted = null;

0 commit comments

Comments
 (0)