Add duplicate (^D), basic search, bugfixes

* Use ^D to duplicate array items
* Use / to search, matching keys will be highlighted
* Don't attempt to load non-existing files when passed on command line
This commit is contained in:
2024-10-08 11:04:26 +02:00
parent 1f74bbfc0d
commit ca61374654
4 changed files with 87 additions and 26 deletions

View File

@@ -36,6 +36,8 @@ class TreeList implements Countable, IteratorAggregate
private const ICON_BOOL_FALSE = "\u{f630}";
private const ICON_NULL = "\u{f141}";
public array $searchResults = [];
public function __construct(private Tree $tree)
{
}
@@ -219,16 +221,20 @@ class TreeList implements Countable, IteratorAggregate
default => self::ICON_STRING,
}." ";
}
$keyStyle = "36";
if (in_array($entry->node, $this->searchResults)) {
$keyStyle = "1;97";
}
echo (is_int($entry->key)
?(Settings::$highlightIndices
?"\e[36;2m\u{e0b6}\e[7m#{$entry->key}\e[27m\u{e0b4}\e[22;37m "
:"\e[36;2m#{$entry->key}\e[22;37m "
?"\e[{$keyStyle};2m\u{e0b6}\e[7m#{$entry->key}\e[27m\u{e0b4}\e[22;37m "
:"\e[{$keyStyle};2m#{$entry->key}\e[22;37m "
)
:(Settings::$editorQuotedKeys
? "\e[36m\"{$entry->key}\":\e[37m "
: "\e[36m{$entry->key}:\e[37m "
? "\e[{$keyStyle}m\"{$entry->key}\""
: "\e[{$keyStyle}m{$entry->key}"
));
echo ($selected?"\e[22;44;97m":"\e[0;37m").": ";
}
$node = $entry->node;
if ($node instanceof ArrayNode) {