Refactor namespace, context sensitive info bar
This commit is contained in:
parent
f23c378020
commit
89d0e2ca0e
@ -5,7 +5,7 @@
|
|||||||
"license": "GPL-3.0-or-later",
|
"license": "GPL-3.0-or-later",
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"NoccyLabs\\JEdit\\": "src/"
|
"NoccyLabs\\JsonEdit\\": "src/"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"authors": [
|
"authors": [
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace NoccyLabs\JEdit\Editor;
|
namespace NoccyLabs\JsonEdit\Editor;
|
||||||
|
|
||||||
use NoccyLabs\JEdit\List\TreeList;
|
use NoccyLabs\JsonEdit\List\TreeList;
|
||||||
use NoccyLabs\JEdit\Settings;
|
use NoccyLabs\JsonEdit\Settings;
|
||||||
use NoccyLabs\JEdit\Terminal\Terminal;
|
use NoccyLabs\JsonEdit\Terminal\Terminal;
|
||||||
use NoccyLabs\JEdit\Tree\ArrayNode;
|
use NoccyLabs\JsonEdit\Tree\ArrayNode;
|
||||||
use NoccyLabs\JEdit\Tree\ObjectNode;
|
use NoccyLabs\JsonEdit\Tree\ObjectNode;
|
||||||
use NoccyLabs\JEdit\Tree\Tree;
|
use NoccyLabs\JsonEdit\Tree\Tree;
|
||||||
use NoccyLabs\JEdit\Tree\ValueNode;
|
use NoccyLabs\JsonEdit\Tree\ValueNode;
|
||||||
use Symfony\Component\Yaml\Yaml;
|
use Symfony\Component\Yaml\Yaml;
|
||||||
|
|
||||||
class Editor
|
class Editor
|
||||||
@ -175,6 +175,7 @@ class Editor
|
|||||||
'object' => "Insert Object{}",
|
'object' => "Insert Object{}",
|
||||||
'array' => "Insert Array[]",
|
'array' => "Insert Array[]",
|
||||||
], 'Insert');
|
], 'Insert');
|
||||||
|
$this->redrawInfoBar([ '^C' => 'Cancel', '↑/↓' => 'Select option', 'Enter' => 'Accept' ]);
|
||||||
$sel = $menu->display(5, 2, 30, 0, "value");
|
$sel = $menu->display(5, 2, 30, 0, "value");
|
||||||
$this->redrawEditor();
|
$this->redrawEditor();
|
||||||
switch ($sel) {
|
switch ($sel) {
|
||||||
@ -221,11 +222,13 @@ class Editor
|
|||||||
* Some things just don't work yet.
|
* Some things just don't work yet.
|
||||||
* Unhandled keys will appear in the bottom left of the screen with a delay.
|
* Unhandled keys will appear in the bottom left of the screen with a delay.
|
||||||
* Folding is not yet implemented.
|
* 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!
|
Go to https://dev.noccylabs.info/noccy/jsonedit to find the source code, issue tracker, and learn more about the project!
|
||||||
EOT;
|
EOT;
|
||||||
$msg = new MessageBox($this->term, $text, "Help (press ctrl-C to close)");
|
$msg = new MessageBox($this->term, $text, "Help");
|
||||||
$msg->display(5, 3, 70, 20);
|
$this->redrawInfoBar([ '^C' => 'Close' ]);
|
||||||
|
$msg->display(10, 4, $w - 20, $h - 8);
|
||||||
$this->redrawEditor();
|
$this->redrawEditor();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -383,7 +386,7 @@ class Editor
|
|||||||
|
|
||||||
if ($parent->node instanceof ObjectNode) {
|
if ($parent->node instanceof ObjectNode) {
|
||||||
$newVal = $this->ask("\e[0;33mnew key:\e[0m ", $entry->key);
|
$newVal = $this->ask("\e[0;33mnew key:\e[0m ", $entry->key);
|
||||||
if ($newVal !== null) {
|
if (!empty($newVal)) {
|
||||||
$parent->node->rename($entry->key, $newVal);
|
$parent->node->rename($entry->key, $newVal);
|
||||||
$entry->key = $newVal;
|
$entry->key = $newVal;
|
||||||
$this->list->parseTree();
|
$this->list->parseTree();
|
||||||
@ -440,7 +443,7 @@ class Editor
|
|||||||
$node = $this->list->getNodeForIndex($coll);
|
$node = $this->list->getNodeForIndex($coll);
|
||||||
if ($node instanceof ObjectNode) {
|
if ($node instanceof ObjectNode) {
|
||||||
$key = $this->ask("\e[0;33mkey:\e[0m ");
|
$key = $this->ask("\e[0;33mkey:\e[0m ");
|
||||||
if ($key === null) {
|
if (empty($key)) {
|
||||||
$this->redrawInfoBar();
|
$this->redrawInfoBar();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -581,27 +584,32 @@ class Editor
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function redrawInfoBar()
|
private function redrawInfoBar(?array $keys = null)
|
||||||
{
|
{
|
||||||
[$w,$h] = $this->term->getSize();
|
[$w,$h] = $this->term->getSize();
|
||||||
|
|
||||||
|
if (!$keys) {
|
||||||
$keys = [
|
$keys = [
|
||||||
|
'h' => 'Help',
|
||||||
'e' => 'Edit',
|
'e' => 'Edit',
|
||||||
'E' => 'Edit key',
|
'E' => 'Edit key',
|
||||||
'I' => 'Insert',
|
'I' => 'Insert…',
|
||||||
'i' => 'Insert value',
|
//'i' => 'Ins value',
|
||||||
'D' => 'Delete',
|
'D' => 'Delete',
|
||||||
//'C' => 'Copy',
|
//'C' => 'Copy',
|
||||||
//'P' => 'Paste',
|
//'P' => 'Paste',
|
||||||
|
'^N' => 'New',
|
||||||
'^R' => 'Read',
|
'^R' => 'Read',
|
||||||
'^W' => 'Write',
|
'^W' => 'Write',
|
||||||
'^C' => 'Exit',
|
'^C' => 'Exit',
|
||||||
];
|
];
|
||||||
|
}
|
||||||
|
|
||||||
$this->term->setCursor(1, $h);
|
$this->term->setCursor(1, $h);
|
||||||
echo "\e[0m\e[K";
|
echo "\e[0;40m\e[K";
|
||||||
foreach ($keys as $key=>$info)
|
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";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace NoccyLabs\JEdit\Editor;
|
namespace NoccyLabs\JsonEdit\Editor;
|
||||||
|
|
||||||
use NoccyLabs\JEdit\Terminal\Terminal;
|
use NoccyLabs\JsonEdit\Terminal\Terminal;
|
||||||
|
|
||||||
class Menu
|
class Menu
|
||||||
{
|
{
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace NoccyLabs\JEdit\Editor;
|
namespace NoccyLabs\JsonEdit\Editor;
|
||||||
|
|
||||||
use NoccyLabs\JEdit\Terminal\Terminal;
|
use NoccyLabs\JsonEdit\Terminal\Terminal;
|
||||||
|
|
||||||
class MessageBox
|
class MessageBox
|
||||||
{
|
{
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace NoccyLabs\JEdit\List;
|
namespace NoccyLabs\JsonEdit\List;
|
||||||
|
|
||||||
use NoccyLabs\JEdit\Tree\Tree;
|
use NoccyLabs\JsonEdit\Tree\Tree;
|
||||||
use NoccyLabs\JEdit\Tree\Node;
|
use NoccyLabs\JsonEdit\Tree\Node;
|
||||||
|
|
||||||
class Entry
|
class Entry
|
||||||
{
|
{
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace NoccyLabs\JEdit\List;
|
namespace NoccyLabs\JsonEdit\List;
|
||||||
|
|
||||||
use Countable;
|
use Countable;
|
||||||
use NoccyLabs\JEdit\Settings;
|
use NoccyLabs\JsonEdit\Settings;
|
||||||
use NoccyLabs\JEdit\Tree\ArrayNode;
|
use NoccyLabs\JsonEdit\Tree\ArrayNode;
|
||||||
use NoccyLabs\JEdit\Tree\Tree;
|
use NoccyLabs\JsonEdit\Tree\Tree;
|
||||||
use NoccyLabs\JEdit\Tree\Node;
|
use NoccyLabs\JsonEdit\Tree\Node;
|
||||||
use NoccyLabs\JEdit\Tree\ObjectNode;
|
use NoccyLabs\JsonEdit\Tree\ObjectNode;
|
||||||
use NoccyLabs\JEdit\Tree\ValueNode;
|
use NoccyLabs\JsonEdit\Tree\ValueNode;
|
||||||
|
|
||||||
class TreeList implements Countable
|
class TreeList implements Countable
|
||||||
{
|
{
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace NoccyLabs\JEdit;
|
namespace NoccyLabs\JsonEdit;
|
||||||
|
|
||||||
class Settings
|
class Settings
|
||||||
{
|
{
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace NoccyLabs\JEdit\Terminal;
|
namespace NoccyLabs\JsonEdit\Terminal;
|
||||||
|
|
||||||
class Terminal
|
class Terminal
|
||||||
{
|
{
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace NoccyLabs\JEdit\Tree;
|
namespace NoccyLabs\JsonEdit\Tree;
|
||||||
|
|
||||||
class ArrayNode extends Node implements CollapsibleNode
|
class ArrayNode extends Node implements CollapsibleNode
|
||||||
{
|
{
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace NoccyLabs\JEdit\Tree;
|
namespace NoccyLabs\JsonEdit\Tree;
|
||||||
|
|
||||||
interface CollapsibleNode
|
interface CollapsibleNode
|
||||||
{
|
{
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace NoccyLabs\JEdit\Tree;
|
namespace NoccyLabs\JsonEdit\Tree;
|
||||||
|
|
||||||
trait CollapsibleNodeTrait
|
trait CollapsibleNodeTrait
|
||||||
{
|
{
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace NoccyLabs\JEdit\Tree;
|
namespace NoccyLabs\JsonEdit\Tree;
|
||||||
|
|
||||||
use JsonSerializable;
|
use JsonSerializable;
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace NoccyLabs\JEdit\Tree;
|
namespace NoccyLabs\JsonEdit\Tree;
|
||||||
|
|
||||||
class ObjectNode extends Node implements CollapsibleNode
|
class ObjectNode extends Node implements CollapsibleNode
|
||||||
{
|
{
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace NoccyLabs\JEdit\Tree;
|
namespace NoccyLabs\JsonEdit\Tree;
|
||||||
|
|
||||||
class Tree
|
class Tree
|
||||||
{
|
{
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace NoccyLabs\JEdit\Tree;
|
namespace NoccyLabs\JsonEdit\Tree;
|
||||||
|
|
||||||
class ValueNode extends Node
|
class ValueNode extends Node
|
||||||
{
|
{
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use NoccyLabs\JEdit\Settings;
|
use NoccyLabs\JsonEdit\Settings;
|
||||||
|
|
||||||
require_once __DIR__."/../vendor/autoload.php";
|
require_once __DIR__."/../vendor/autoload.php";
|
||||||
|
|
||||||
@ -8,11 +8,11 @@ define("SETTINGS_FILE", getenv("HOME")."/.config/jsonedit/config.json");
|
|||||||
|
|
||||||
$filename = $argv[1]??null;
|
$filename = $argv[1]??null;
|
||||||
|
|
||||||
$terminal = new NoccyLabs\JEdit\Terminal\Terminal();
|
$terminal = new NoccyLabs\JsonEdit\Terminal\Terminal();
|
||||||
|
|
||||||
Settings::load(SETTINGS_FILE);
|
Settings::load(SETTINGS_FILE);
|
||||||
|
|
||||||
$editor = new NoccyLabs\JEdit\Editor\Editor($terminal);
|
$editor = new NoccyLabs\JsonEdit\Editor\Editor($terminal);
|
||||||
if ($filename) {
|
if ($filename) {
|
||||||
$editor->loadFile($filename);
|
$editor->loadFile($filename);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user