-
Notifications
You must be signed in to change notification settings - Fork 314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implemented input completion for Userland #733
base: main
Are you sure you want to change the base?
Changes from all commits
ef4f22d
5af699e
1ac3239
0e5d28c
8fab47f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ | |
|
||
namespace Psy\Readline; | ||
|
||
use Psy\TabCompletion\AutoCompleter; | ||
|
||
/** | ||
* A Readline interface implementation for GNU Readline. | ||
* | ||
|
@@ -176,4 +178,18 @@ public function writeHistory(): bool | |
|
||
return true; | ||
} | ||
|
||
public function activateAutoCompleter(AutoCompleter $autoCompleter): void | ||
{ | ||
\readline_completion_function([$autoCompleter, 'callback']); | ||
} | ||
|
||
public function deactivateAutoCompleter(): void | ||
{ | ||
// PHP didn't implement the whole readline API when they first switched | ||
// to libedit. And they still haven't. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎉 |
||
if (\function_exists('readline_callback_handler_remove')) { | ||
\readline_callback_handler_remove(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,8 +46,11 @@ interface Autocompleter | |
/** | ||
* Complete a word. | ||
* Returns null for no word, a full-word or an array of full-words. | ||
* | ||
* @param array{line_buffer: string} $info A subset of {@see readline_info()}'s return value. | ||
* @see https://www.php.net/readline_info | ||
*/ | ||
public function complete(&$prefix); | ||
public function complete(string $prefix, int $index, array $info); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these were passing by reference because they changed |
||
|
||
/** | ||
* Get definition of a word. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,7 +120,7 @@ public static function getSize(): array | |
} | ||
|
||
$command = $term.'tput cols && '.$term.'tput lines'; | ||
$tput = Processus::execute($command, false); | ||
$tput = ConsoleProcessus::execute($command, false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ooh, sorry about that. |
||
|
||
if (!empty($tput)) { | ||
list($x, $y) = \explode("\n", $tput); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Psy\Readline; | ||
|
||
use Psy\Readline\Hoa\Autocompleter as HoaAutocompleter; | ||
use Psy\TabCompletion\AutoCompleter; | ||
|
||
class HoaAutocompleterAdapter implements HoaAutocompleter | ||
{ | ||
/** @var AutoCompleter */ | ||
private $autoCompleter; | ||
|
||
public function __construct(AutoCompleter $autoCompleter) | ||
{ | ||
$this->autoCompleter = $autoCompleter; | ||
} | ||
|
||
public function complete(string $prefix, int $index, array $info) | ||
{ | ||
return $this->autoCompleter->complete($prefix, $index, $info); | ||
} | ||
|
||
public function getWordDefinition(): string | ||
{ | ||
return '.'; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I left this adapter for interoperability with existing Hoa completions, but you can also remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's the benefit of interoperability with existing Hoa completions? it's deprecated and unsupported, and the code here is effectively a stripped-down fork. i'm not sure i see the point :) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ | |
|
||
namespace Psy\Readline; | ||
|
||
use Psy\TabCompletion\AutoCompleter; | ||
|
||
/** | ||
* An interface abstracting the various readline_* functions. | ||
*/ | ||
|
@@ -80,4 +82,14 @@ public function redisplay(); | |
* @return bool Success | ||
*/ | ||
public function writeHistory(): bool; | ||
|
||
/** | ||
* Activete auto completer for tab completion. | ||
*/ | ||
public function activateAutoCompleter(AutoCompleter $autoCompleter): void; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's make these two a second interface so we can maintain backwards compatibility for existing Readline API. |
||
|
||
/** | ||
* Deactivete auto completer for tab completion. | ||
*/ | ||
public function deactivateAutoCompleter(): void; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do nothing for deactivate except native |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe these should also be called "useNativeReadline", but I haven't changed them as they are separate issues from auto-completion.