Refactor namespace, context sensitive info bar
This commit is contained in:
@ -1,14 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace NoccyLabs\JEdit\Editor;
|
||||
namespace NoccyLabs\JsonEdit\Editor;
|
||||
|
||||
use NoccyLabs\JEdit\List\TreeList;
|
||||
use NoccyLabs\JEdit\Settings;
|
||||
use NoccyLabs\JEdit\Terminal\Terminal;
|
||||
use NoccyLabs\JEdit\Tree\ArrayNode;
|
||||
use NoccyLabs\JEdit\Tree\ObjectNode;
|
||||
use NoccyLabs\JEdit\Tree\Tree;
|
||||
use NoccyLabs\JEdit\Tree\ValueNode;
|
||||
use NoccyLabs\JsonEdit\List\TreeList;
|
||||
use NoccyLabs\JsonEdit\Settings;
|
||||
use NoccyLabs\JsonEdit\Terminal\Terminal;
|
||||
use NoccyLabs\JsonEdit\Tree\ArrayNode;
|
||||
use NoccyLabs\JsonEdit\Tree\ObjectNode;
|
||||
use NoccyLabs\JsonEdit\Tree\Tree;
|
||||
use NoccyLabs\JsonEdit\Tree\ValueNode;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
class Editor
|
||||
@ -175,6 +175,7 @@ class Editor
|
||||
'object' => "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";
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user