diff --git a/composer.json b/composer.json index 22ee855..090db0c 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "license": "GPL-3.0-or-later", "autoload": { "psr-4": { - "NoccyLabs\\JEdit\\": "src/" + "NoccyLabs\\JsonEdit\\": "src/" } }, "authors": [ diff --git a/src/Editor/Editor.php b/src/Editor/Editor.php index fef1525..ec8873d 100644 --- a/src/Editor/Editor.php +++ b/src/Editor/Editor.php @@ -1,14 +1,14 @@ "Insert Object{}", 'array' => "Insert Array[]", ], 'Insert'); + $this->redrawInfoBar([ '^C' => 'Cancel', '↑/↓' => 'Select option', 'Enter' => 'Accept' ]); $sel = $menu->display(5, 2, 30, 0, "value"); $this->redrawEditor(); switch ($sel) { @@ -221,11 +222,13 @@ class Editor * Some things just don't work yet. * Unhandled keys will appear in the bottom left of the screen with a delay. * Folding is not yet implemented. + * There are crashes, and lock-ups. Data corruption is a possibility. Go to https://dev.noccylabs.info/noccy/jsonedit to find the source code, issue tracker, and learn more about the project! EOT; - $msg = new MessageBox($this->term, $text, "Help (press ctrl-C to close)"); - $msg->display(5, 3, 70, 20); + $msg = new MessageBox($this->term, $text, "Help"); + $this->redrawInfoBar([ '^C' => 'Close' ]); + $msg->display(10, 4, $w - 20, $h - 8); $this->redrawEditor(); break; @@ -383,7 +386,7 @@ class Editor if ($parent->node instanceof ObjectNode) { $newVal = $this->ask("\e[0;33mnew key:\e[0m ", $entry->key); - if ($newVal !== null) { + if (!empty($newVal)) { $parent->node->rename($entry->key, $newVal); $entry->key = $newVal; $this->list->parseTree(); @@ -440,7 +443,7 @@ class Editor $node = $this->list->getNodeForIndex($coll); if ($node instanceof ObjectNode) { $key = $this->ask("\e[0;33mkey:\e[0m "); - if ($key === null) { + if (empty($key)) { $this->redrawInfoBar(); return; } @@ -581,27 +584,32 @@ class Editor * * @return void */ - private function redrawInfoBar() + private function redrawInfoBar(?array $keys = null) { [$w,$h] = $this->term->getSize(); - $keys = [ - 'e' => 'Edit', - 'E' => 'Edit key', - 'I' => 'Insert', - 'i' => 'Insert value', - 'D' => 'Delete', - //'C' => 'Copy', - //'P' => 'Paste', - '^R' => 'Read', - '^W' => 'Write', - '^C' => 'Exit', - ]; + if (!$keys) { + $keys = [ + 'h' => 'Help', + 'e' => 'Edit', + 'E' => 'Edit key', + 'I' => 'Insert…', + //'i' => 'Ins value', + 'D' => 'Delete', + //'C' => 'Copy', + //'P' => 'Paste', + '^N' => 'New', + '^R' => 'Read', + '^W' => 'Write', + '^C' => 'Exit', + ]; + } $this->term->setCursor(1, $h); - echo "\e[0m\e[K"; + echo "\e[0;40m\e[K"; foreach ($keys as $key=>$info) - echo " \e[1m{$key}\e[2m \e[3m{$info}\e[0m \e[90m\u{2502}\e[0m"; + 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"; } } diff --git a/src/Editor/Menu.php b/src/Editor/Menu.php index 615ea2e..f23f321 100644 --- a/src/Editor/Menu.php +++ b/src/Editor/Menu.php @@ -1,8 +1,8 @@ loadFile($filename); } else {