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",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"NoccyLabs\\JEdit\\": "src/"
|
||||
"NoccyLabs\\JsonEdit\\": "src/"
|
||||
}
|
||||
},
|
||||
"authors": [
|
||||
|
@ -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();
|
||||
|
||||
if (!$keys) {
|
||||
$keys = [
|
||||
'h' => 'Help',
|
||||
'e' => 'Edit',
|
||||
'E' => 'Edit key',
|
||||
'I' => 'Insert',
|
||||
'i' => 'Insert value',
|
||||
'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";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace NoccyLabs\JEdit\Editor;
|
||||
namespace NoccyLabs\JsonEdit\Editor;
|
||||
|
||||
use NoccyLabs\JEdit\Terminal\Terminal;
|
||||
use NoccyLabs\JsonEdit\Terminal\Terminal;
|
||||
|
||||
class Menu
|
||||
{
|
||||
|
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace NoccyLabs\JEdit\Editor;
|
||||
namespace NoccyLabs\JsonEdit\Editor;
|
||||
|
||||
use NoccyLabs\JEdit\Terminal\Terminal;
|
||||
use NoccyLabs\JsonEdit\Terminal\Terminal;
|
||||
|
||||
class MessageBox
|
||||
{
|
||||
|
@ -1,9 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace NoccyLabs\JEdit\List;
|
||||
namespace NoccyLabs\JsonEdit\List;
|
||||
|
||||
use NoccyLabs\JEdit\Tree\Tree;
|
||||
use NoccyLabs\JEdit\Tree\Node;
|
||||
use NoccyLabs\JsonEdit\Tree\Tree;
|
||||
use NoccyLabs\JsonEdit\Tree\Node;
|
||||
|
||||
class Entry
|
||||
{
|
||||
|
@ -1,14 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace NoccyLabs\JEdit\List;
|
||||
namespace NoccyLabs\JsonEdit\List;
|
||||
|
||||
use Countable;
|
||||
use NoccyLabs\JEdit\Settings;
|
||||
use NoccyLabs\JEdit\Tree\ArrayNode;
|
||||
use NoccyLabs\JEdit\Tree\Tree;
|
||||
use NoccyLabs\JEdit\Tree\Node;
|
||||
use NoccyLabs\JEdit\Tree\ObjectNode;
|
||||
use NoccyLabs\JEdit\Tree\ValueNode;
|
||||
use NoccyLabs\JsonEdit\Settings;
|
||||
use NoccyLabs\JsonEdit\Tree\ArrayNode;
|
||||
use NoccyLabs\JsonEdit\Tree\Tree;
|
||||
use NoccyLabs\JsonEdit\Tree\Node;
|
||||
use NoccyLabs\JsonEdit\Tree\ObjectNode;
|
||||
use NoccyLabs\JsonEdit\Tree\ValueNode;
|
||||
|
||||
class TreeList implements Countable
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace NoccyLabs\JEdit;
|
||||
namespace NoccyLabs\JsonEdit;
|
||||
|
||||
class Settings
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace NoccyLabs\JEdit\Terminal;
|
||||
namespace NoccyLabs\JsonEdit\Terminal;
|
||||
|
||||
class Terminal
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace NoccyLabs\JEdit\Tree;
|
||||
namespace NoccyLabs\JsonEdit\Tree;
|
||||
|
||||
class ArrayNode extends Node implements CollapsibleNode
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace NoccyLabs\JEdit\Tree;
|
||||
namespace NoccyLabs\JsonEdit\Tree;
|
||||
|
||||
interface CollapsibleNode
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace NoccyLabs\JEdit\Tree;
|
||||
namespace NoccyLabs\JsonEdit\Tree;
|
||||
|
||||
trait CollapsibleNodeTrait
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace NoccyLabs\JEdit\Tree;
|
||||
namespace NoccyLabs\JsonEdit\Tree;
|
||||
|
||||
use JsonSerializable;
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace NoccyLabs\JEdit\Tree;
|
||||
namespace NoccyLabs\JsonEdit\Tree;
|
||||
|
||||
class ObjectNode extends Node implements CollapsibleNode
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace NoccyLabs\JEdit\Tree;
|
||||
namespace NoccyLabs\JsonEdit\Tree;
|
||||
|
||||
class Tree
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace NoccyLabs\JEdit\Tree;
|
||||
namespace NoccyLabs\JsonEdit\Tree;
|
||||
|
||||
class ValueNode extends Node
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
use NoccyLabs\JEdit\Settings;
|
||||
use NoccyLabs\JsonEdit\Settings;
|
||||
|
||||
require_once __DIR__."/../vendor/autoload.php";
|
||||
|
||||
@ -8,11 +8,11 @@ define("SETTINGS_FILE", getenv("HOME")."/.config/jsonedit/config.json");
|
||||
|
||||
$filename = $argv[1]??null;
|
||||
|
||||
$terminal = new NoccyLabs\JEdit\Terminal\Terminal();
|
||||
$terminal = new NoccyLabs\JsonEdit\Terminal\Terminal();
|
||||
|
||||
Settings::load(SETTINGS_FILE);
|
||||
|
||||
$editor = new NoccyLabs\JEdit\Editor\Editor($terminal);
|
||||
$editor = new NoccyLabs\JsonEdit\Editor\Editor($terminal);
|
||||
if ($filename) {
|
||||
$editor->loadFile($filename);
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user