Add settings menu (^S)

This commit is contained in:
Chris 2024-10-06 16:54:41 +02:00
parent ed02447161
commit c51355aba7
2 changed files with 45 additions and 2 deletions

View File

@ -59,7 +59,8 @@ unconfigured nginx container.
### Editing a document ### Editing a document
1. Run `jsonedit <filename>` from your shell. 1. Run `jsonedit <filename>` 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**. 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 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 string 1234, and `1234` for the integer 1234. Unparsable JSON will be used
@ -88,6 +89,7 @@ exists.
- **t** - Toggle tail line guide - **t** - Toggle tail line guide
- **b** - Toggle icons before keys - **b** - Toggle icons before keys
- **c** - Toggle compact mode - **c** - Toggle compact mode
- **^S** - Open settings menu
## Caveats ## Caveats

View File

@ -315,7 +315,48 @@ class Editor
$this->modified = false; $this->modified = false;
$this->redrawEditor(); $this->redrawEditor();
break; 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 case "\x0F": // ctrl-o
$this->doOpenFile(); $this->doOpenFile();
break; break;