Add compact mode, toggle with 'c'
This commit is contained in:
parent
bf6756773e
commit
be63775334
@ -216,6 +216,12 @@ class Editor
|
||||
$this->redrawEditor();
|
||||
break;
|
||||
|
||||
case "c":
|
||||
Settings::$compactGroups = !Settings::$compactGroups;
|
||||
$this->list->parseTree();
|
||||
$this->redrawEditor();
|
||||
break;
|
||||
|
||||
case "\x0e": // ctrl-n
|
||||
$this->document->load((object)[]);
|
||||
$this->list->parseTree();
|
||||
@ -359,6 +365,8 @@ class Editor
|
||||
e Edit selected value
|
||||
E Edit selected key
|
||||
D Delete selected key
|
||||
c Toggle compact list view
|
||||
q Toggle quoted keys in list view
|
||||
^W Write to file
|
||||
^R Read from file
|
||||
^N New document with empty object
|
||||
|
@ -50,12 +50,14 @@ class TreeList implements Countable
|
||||
foreach ($node->items as $item) {
|
||||
$this->parseNode($item, [ ...$path, $key ], $index++);
|
||||
}
|
||||
$this->list[$entryKey.'$'] = new Entry(depth: $level, key: $key, node: $node, closer: true);
|
||||
if (!Settings::$compactGroups)
|
||||
$this->list[$entryKey.'$'] = new Entry(depth: $level, key: $key, node: $node, closer: true);
|
||||
} elseif ($node instanceof ObjectNode) {
|
||||
foreach ($node->properties as $nodekey=>$item) {
|
||||
$this->parseNode($item, [ ...$path, $key ], $nodekey);
|
||||
}
|
||||
$this->list[$entryKey.'$'] = new Entry(depth: $level, key: $key, node: $node, closer: true);
|
||||
if (!Settings::$compactGroups)
|
||||
$this->list[$entryKey.'$'] = new Entry(depth: $level, key: $key, node: $node, closer: true);
|
||||
|
||||
}
|
||||
}
|
||||
@ -150,10 +152,12 @@ class TreeList implements Countable
|
||||
echo "\e[90m".str_repeat("\u{258f} ",$entry->depth)."\e[37m";
|
||||
|
||||
if ($entry->closer) {
|
||||
if ($entry->node instanceof ArrayNode) {
|
||||
echo "]";
|
||||
} elseif ($entry->node instanceof ObjectNode) {
|
||||
echo "}";
|
||||
if (!Settings::$compactGroups) {
|
||||
if ($entry->node instanceof ArrayNode) {
|
||||
echo "]";
|
||||
} elseif ($entry->node instanceof ObjectNode) {
|
||||
echo "}";
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -167,9 +171,9 @@ class TreeList implements Countable
|
||||
));
|
||||
}
|
||||
if ($entry->node instanceof ArrayNode) {
|
||||
echo "[";
|
||||
echo "[" . (Settings::$compactGroups ? "…]":"");
|
||||
} elseif ($entry->node instanceof ObjectNode) {
|
||||
echo "{";
|
||||
echo "{" . (Settings::$compactGroups ? "…}":"");
|
||||
} elseif ($entry->node instanceof ValueNode) {
|
||||
$value = $entry->node->value;
|
||||
echo match (gettype($value)) {
|
||||
|
@ -6,18 +6,22 @@ class Settings
|
||||
{
|
||||
public static bool $editorQuotedKeys = false;
|
||||
|
||||
public static bool $compactGroups = false;
|
||||
|
||||
public static function load(string $filename): void
|
||||
{
|
||||
if (file_exists($filename) && is_readable($filename)) {
|
||||
$data = json_decode(file_get_contents($filename));
|
||||
self::$editorQuotedKeys = $data->editorQuotedKeys ?? false;
|
||||
self::$compactGroups = $data->compactGroups ?? false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function save(string $filename): void
|
||||
{
|
||||
$data = json_encode([
|
||||
'editorQuotedKeys' => self::$editorQuotedKeys
|
||||
'editorQuotedKeys' => self::$editorQuotedKeys,
|
||||
'compactGroups' => self::$compactGroups,
|
||||
], JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT)."\n";
|
||||
@file_put_contents($filename, $data);
|
||||
}
|
||||
@ -27,6 +31,8 @@ class Settings
|
||||
switch ($key) {
|
||||
case 'editorQuotedKeys':
|
||||
self::$editorQuotedKeys = (bool)$value; break;
|
||||
case 'compactGroups':
|
||||
self::$compactGroups = (bool)$value; break;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user