Skip to content

Commit

Permalink
Support carriage returns
Browse files Browse the repository at this point in the history
  • Loading branch information
jessarcher committed Nov 20, 2024
1 parent 42d9568 commit 3cfd29f
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Concerns/TypedValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion src/ConfirmPrompt.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
Expand Down
2 changes: 2 additions & 0 deletions src/Key.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class Key

const ENTER = "\n";

const CR = "\r";

const SPACE = ' ';

const TAB = "\t";
Expand Down
2 changes: 1 addition & 1 deletion src/MultiSearchPrompt.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
});
Expand Down
2 changes: 1 addition & 1 deletion src/MultiSelectPrompt.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/PausePrompt.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/SearchPrompt.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
});
Expand Down
2 changes: 1 addition & 1 deletion src/SelectPrompt.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/SuggestPrompt.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3cfd29f

Please sign in to comment.