Add alternate array index style, with setting

This commit is contained in:
Chris 2024-10-07 00:58:34 +02:00
parent 0e1354bd47
commit 73ac4dd3f6
3 changed files with 13 additions and 2 deletions

View File

@ -806,7 +806,7 @@ class Editor
'quotedKeys' => (Settings::$editorQuotedKeys?$mark:$clear)."Quoted keys", 'quotedKeys' => (Settings::$editorQuotedKeys?$mark:$clear)."Quoted keys",
'tailLine' => (Settings::$tailLine?$mark:$clear)."Show tail line", 'tailLine' => (Settings::$tailLine?$mark:$clear)."Show tail line",
'indentationGuides' => (Settings::$indentationGuides?$mark:$clear)."Show indentation guides", '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")) $sel = (new Menu($this->term, $items, "Settings"))
->display(0, 0, 40, 0, $sel); ->display(0, 0, 40, 0, $sel);
@ -827,6 +827,9 @@ class Editor
case 'indentationGuides': case 'indentationGuides':
Settings::$indentationGuides = !Settings::$indentationGuides; Settings::$indentationGuides = !Settings::$indentationGuides;
break; break;
case 'highlightIndices':
Settings::$highlightIndices = !Settings::$highlightIndices;
break;
} }
} while ($sel); } while ($sel);
$this->redrawEditor(); $this->redrawEditor();

View File

@ -195,7 +195,11 @@ class TreeList implements Countable, IteratorAggregate
}." "; }." ";
} }
echo (is_int($entry->key) 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 :(Settings::$editorQuotedKeys
? "\e[36m\"{$entry->key}\":\e[37m " ? "\e[36m\"{$entry->key}\":\e[37m "
: "\e[36m{$entry->key}:\e[37m " : "\e[36m{$entry->key}:\e[37m "

View File

@ -16,6 +16,8 @@ class Settings
public static bool $tailLine = true; public static bool $tailLine = true;
public static bool $highlightIndices = true;
public static function load(string $filename): void public static function load(string $filename): void
{ {
if (file_exists($filename) && is_readable($filename)) { if (file_exists($filename) && is_readable($filename)) {
@ -25,6 +27,7 @@ class Settings
self::$indentationGuides = $data->indentationGuides ?? true; self::$indentationGuides = $data->indentationGuides ?? true;
self::$collapseBefore = $data->collapseBefore ?? true; self::$collapseBefore = $data->collapseBefore ?? true;
self::$tailLine = $data->tailLine ?? true; self::$tailLine = $data->tailLine ?? true;
self::$highlightIndices = $data->highlightIndices ?? true;
} }
} }
@ -37,6 +40,7 @@ class Settings
'collapseBefore' => self::$collapseBefore, 'collapseBefore' => self::$collapseBefore,
'highlightRow' => self::$highlightRow, 'highlightRow' => self::$highlightRow,
'tailLine' => self::$tailLine, 'tailLine' => self::$tailLine,
'highlightIndices' => self::$highlightIndices,
], JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT)."\n"; ], JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT)."\n";
@file_put_contents($filename, $data); @file_put_contents($filename, $data);
} }