Improve tail line, fix edit box

* Edit box now supports the usual keys; left/right plus home/end, and does
  the appropriate scrolling.
* Tail line is now a top bar.
* Added option to toggle tail bar, but not bound to any key.
This commit is contained in:
2024-10-03 17:57:41 +02:00
parent 466406733d
commit 19ba6a9bee
4 changed files with 96 additions and 15 deletions

View File

@ -2,7 +2,9 @@
namespace NoccyLabs\JsonEdit\List;
use ArrayIterator;
use Countable;
use IteratorAggregate;
use NoccyLabs\JsonEdit\Settings;
use NoccyLabs\JsonEdit\Tree\ArrayNode;
use NoccyLabs\JsonEdit\Tree\CollapsibleNode;
@ -10,8 +12,9 @@ use NoccyLabs\JsonEdit\Tree\Tree;
use NoccyLabs\JsonEdit\Tree\Node;
use NoccyLabs\JsonEdit\Tree\ObjectNode;
use NoccyLabs\JsonEdit\Tree\ValueNode;
use Traversable;
class TreeList implements Countable
class TreeList implements Countable, IteratorAggregate
{
/** @var array<string,Entry> */
public array $list = [];
@ -31,6 +34,11 @@ class TreeList implements Countable
{
}
public function getIterator(): Traversable
{
return new ArrayIterator($this->list);
}
public function count(): int
{
return count($this->list);
@ -146,7 +154,7 @@ class TreeList implements Countable
echo "\e[{$screenRow};1H";
if ($entryRow >= count($keys)) {
echo ($selected?"\e[44;97m":"\e[0;90m")."\e[K";
if ($entryRow == count($keys)) echo str_repeat("\u{2574}",$columns);
if ($entryRow == count($keys) && Settings::$tailLine) echo str_repeat("\u{2594}",$columns);
echo "\e[0m";
//else echo "\e[90m\u{2805}\e[0m";
return;
@ -183,10 +191,10 @@ class TreeList implements Countable
if ($entry->node instanceof CollapsibleNode) {
if ($entry->node->isCollapsed()) {
//echo "\e[90m\u{25ba} \e[37m";
echo "\e[90m".self::TREE_FOLD_OPEN." \e[37m";
echo "\e[37m".self::TREE_FOLD_OPEN." \e[37m";
} else {
//echo "\e[90m\u{25bc} \e[37m";
echo "\e[90m".self::TREE_FOLD_CLOSE." \e[37m";
echo "\e[37m".self::TREE_FOLD_CLOSE." \e[37m";
}
}
}
@ -231,8 +239,8 @@ class TreeList implements Countable
$value = $entry->node->value;
echo match (gettype($value)) {
'string' => "\e[33m",
'integer' => "\e[34m",
'double' => "\e[32m",
'integer' => "\e[94m",
'double' => "\e[96m",
'boolean' => "\e[35m",
'NULL' => "\e[31m",
default => "",