From c51355aba74afba8fe55dd91bf179eafc51e6203 Mon Sep 17 00:00:00 2001 From: Christopher Vagnetoft Date: Sun, 6 Oct 2024 16:54:41 +0200 Subject: [PATCH] Add settings menu (^S) --- README.md | 4 +++- src/Editor/Editor.php | 43 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1a9cd02..7d4ea97 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,8 @@ unconfigured nginx container. ### Editing a document -1. Run `jsonedit ` from your shell. +1. Run `jsonedit ` from your shell, or run `jsonedit` and press **^O** + to browse for a file to open. 2. Find the value you want to edit and press **e**. 3. Enter the value usng valid JSON value encoding, for example `"1234"` for the string 1234, and `1234` for the integer 1234. Unparsable JSON will be used @@ -88,6 +89,7 @@ exists. - **t** - Toggle tail line guide - **b** - Toggle icons before keys - **c** - Toggle compact mode +- **^S** - Open settings menu ## Caveats diff --git a/src/Editor/Editor.php b/src/Editor/Editor.php index 0c5fc31..db56156 100644 --- a/src/Editor/Editor.php +++ b/src/Editor/Editor.php @@ -315,7 +315,48 @@ class Editor $this->modified = false; $this->redrawEditor(); break; - + + case "\x13": // ctrl-s + $sel = null; + $mark = "\u{f657} "; + $clear = "\u{f630} "; + + do { + $this->redrawEditor(); + $items = [ + 'collapseBefore' => (Settings::$collapseBefore?$mark:$clear)."Collapse before key", + 'compactGroups' => (Settings::$compactGroups?$mark:$clear)."Compact groups", + '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" + ]; + $sel = (new Menu($this->term, $items, "Settings")) + ->display(0, 0, 40, 0, $sel); + switch ($sel) { + case 'collapseBefore': + Settings::$collapseBefore = !Settings::$collapseBefore; + break; + case 'compactGroups': + Settings::$compactGroups = !Settings::$compactGroups; + $this->list->parseTree(); + break; + case 'quotedKeys': + Settings::$editorQuotedKeys = !Settings::$editorQuotedKeys; + break; + case 'tailLine': + Settings::$tailLine = !Settings::$tailLine; + break; + case 'indentationGuides': + Settings::$indentationGuides = !Settings::$indentationGuides; + break; + case null: + break(2); + } + } while ($sel != 'done'); + $this->redrawEditor(); + break; + case "\x0F": // ctrl-o $this->doOpenFile(); break;