Hidden files in open browser, menu tweaks

* Add key callback for menus
* Use key callback to intercept ^H and toggle hidden files in browser
This commit is contained in:
2024-10-06 16:22:46 +02:00
parent 29d070c305
commit 10d8c4bfce
2 changed files with 36 additions and 7 deletions
+18 -1
View File
@@ -29,6 +29,8 @@ class Menu
private int $scroll = 0;
private $keyhandler = null;
/**
* constructor
*
@@ -41,6 +43,12 @@ class Menu
}
public function setKeyhandler(?callable $handler): self
{
$this->keyhandler = $handler;
return $this;
}
/**
* Update the menu items
*
@@ -77,7 +85,10 @@ class Menu
*/
public function display(int $left, int $top, int $width, int $height = 0, string|int|null $value): mixed
{
$this->index = 0;
//$this->index = 0;
$keys = array_keys($this->items);
$this->index = array_search($value, $keys) ?? 0;
[$w,$h] = $this->terminal->getSize();
if ($height == 0) {
@@ -97,6 +108,12 @@ class Menu
while (null === ($ch = $this->terminal->readKey())) {
usleep(10000);
}
if (is_callable($this->keyhandler)) {
$ret = call_user_func($this->keyhandler, $ch);
if ($ret === true) {
return false;
}
}
if (mb_strlen($ch) == 1) {
if ($ch == "\x03") {
$showing = false;