From 73ac4dd3f6d68360c7f9d0b8a417ccf8acde60fd Mon Sep 17 00:00:00 2001 From: Christopher Vagnetoft Date: Mon, 7 Oct 2024 00:58:34 +0200 Subject: [PATCH] Add alternate array index style, with setting --- src/Editor/Editor.php | 5 ++++- src/List/TreeList.php | 6 +++++- src/Settings.php | 4 ++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Editor/Editor.php b/src/Editor/Editor.php index cf0f9cb..e73a147 100644 --- a/src/Editor/Editor.php +++ b/src/Editor/Editor.php @@ -806,7 +806,7 @@ class Editor 'quotedKeys' => (Settings::$editorQuotedKeys?$mark:$clear)."Quoted keys", 'tailLine' => (Settings::$tailLine?$mark:$clear)."Show tail line", 'indentationGuides' => (Settings::$indentationGuides?$mark:$clear)."Show indentation guides", - //'done' => " Done" + 'highlightIndices' => (Settings::$highlightIndices?$mark:$clear)."Highlight array indices", ]; $sel = (new Menu($this->term, $items, "Settings")) ->display(0, 0, 40, 0, $sel); @@ -827,6 +827,9 @@ class Editor case 'indentationGuides': Settings::$indentationGuides = !Settings::$indentationGuides; break; + case 'highlightIndices': + Settings::$highlightIndices = !Settings::$highlightIndices; + break; } } while ($sel); $this->redrawEditor(); diff --git a/src/List/TreeList.php b/src/List/TreeList.php index 65c45da..792256e 100644 --- a/src/List/TreeList.php +++ b/src/List/TreeList.php @@ -195,7 +195,11 @@ class TreeList implements Countable, IteratorAggregate }." "; } echo (is_int($entry->key) - ?"\e[36;2m\u{e0b6}\e[7m#{$entry->key}\e[27m\u{e0b4}\e[22;37m " + + ?(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 " + ) :(Settings::$editorQuotedKeys ? "\e[36m\"{$entry->key}\":\e[37m " : "\e[36m{$entry->key}:\e[37m " diff --git a/src/Settings.php b/src/Settings.php index d0294a8..2ffdec0 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -16,6 +16,8 @@ class Settings public static bool $tailLine = true; + public static bool $highlightIndices = true; + public static function load(string $filename): void { if (file_exists($filename) && is_readable($filename)) { @@ -25,6 +27,7 @@ class Settings self::$indentationGuides = $data->indentationGuides ?? true; self::$collapseBefore = $data->collapseBefore ?? true; self::$tailLine = $data->tailLine ?? true; + self::$highlightIndices = $data->highlightIndices ?? true; } } @@ -37,6 +40,7 @@ class Settings 'collapseBefore' => self::$collapseBefore, 'highlightRow' => self::$highlightRow, 'tailLine' => self::$tailLine, + 'highlightIndices' => self::$highlightIndices, ], JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT)."\n"; @file_put_contents($filename, $data); }