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:
parent
29d070c305
commit
10d8c4bfce
@ -445,7 +445,9 @@ class Editor
|
||||
|
||||
private function doOpenFile()
|
||||
{
|
||||
$wd = getcwd();
|
||||
$includeHidden = false;
|
||||
$wd = dirname($this->filename);
|
||||
if ($wd == '.') $wd = getcwd();
|
||||
$menu = new Menu($this->term, []);
|
||||
while (true) {
|
||||
$items = [
|
||||
@ -456,7 +458,11 @@ class Editor
|
||||
"-"
|
||||
)
|
||||
];
|
||||
$files = glob($wd."/*");
|
||||
if ($includeHidden) {
|
||||
$files = array_merge(glob($wd.'/.[!.]*'), glob($wd.'/*'));
|
||||
}else {
|
||||
$files = glob($wd."/*");
|
||||
}
|
||||
// do two sweeps, to sort directories.
|
||||
foreach ($files as $file) {
|
||||
if (!is_dir($file)) continue;
|
||||
@ -476,11 +482,18 @@ class Editor
|
||||
date("Y-m-d H:i:s", filemtime($file))
|
||||
);
|
||||
}
|
||||
$this->redrawInfoBar([ '^C' => "Cancel", '↑↓' => "Navigate", 'Enter' => "Select/Open" ]);
|
||||
$this->redrawEditor();
|
||||
$this->redrawInfoBar([ '^C' => "Cancel", '^H' => "Hidden", '↑↓' => "Navigate", 'Enter' => "Select/Open" ]);
|
||||
$sel = $menu
|
||||
->setKeyhandler(function ($key) use (&$includeHidden) {
|
||||
if ($key == "\x08") {
|
||||
$includeHidden = !$includeHidden;
|
||||
return true;
|
||||
}
|
||||
})
|
||||
->setItems($items)
|
||||
->setTitle($wd)
|
||||
->display(0, 0, 70, 20, null);
|
||||
->display(0, 0, 70, 20, $this->filename);
|
||||
if ($sel === null) {
|
||||
$this->redrawEditor();
|
||||
return;
|
||||
@ -943,7 +956,7 @@ class Editor
|
||||
$this->term->setCursor(1, $h);
|
||||
echo "\e[37;40m\e[K";
|
||||
foreach ($keys as $key=>$info)
|
||||
echo "\e[2m\u{f104}\e[22;97;1m{$key}\e[22;37;2m\u{f105} \e[22;36m{$info}\e[37m ";
|
||||
echo "\e[2m\u{f104}\e[22;97;1m{$key}\e[22;37;2m\u{f105} \e[22;33m{$info}\e[37m ";
|
||||
//echo "\e[37;40;2m\u{e0b6}\e[7;37m{$key} \e[22m {$info} \e[27m\u{e0b4}\e[0m";
|
||||
//echo " \e[1m{$key}\e[2m \e[3m{$info}\e[0m \e[90m\u{2502}\e[0m";
|
||||
}
|
||||
@ -1019,7 +1032,6 @@ There is no need to select YAML or JSON mode. All operations work the same, and
|
||||
|
||||
# Disclaimer
|
||||
This is beta software, if not alpha. It kinda works, but there will be issues. Feel free to help out with a patch, or by filing bug reports.
|
||||
Known issues include:
|
||||
|
||||
# Support
|
||||
Go to https://dev.noccylabs.info/noccy/jsonedit to find the source code, issue tracker, and learn more about the project!
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user