Add icons to items in before mode, ask to save changes
This commit is contained in:
parent
ddfefa124b
commit
0abca3d3a8
@ -210,7 +210,34 @@ class Editor
|
||||
break;
|
||||
|
||||
case "\x18": // ctrl-x
|
||||
$this->running = false;
|
||||
|
||||
if ($this->modified) {
|
||||
$menu = new Menu($this->term, [
|
||||
'cancel' => "Return to editor",
|
||||
'save' => "Save changes",
|
||||
'discard' => "Discard changes",
|
||||
//'sep0' => "---",
|
||||
//'__paste' => "Paste from clipboard",
|
||||
], 'Insert');
|
||||
$this->redrawInfoBar([ '^C' => 'Cancel', '↑/↓' => 'Select option', 'Enter' => 'Accept' ]);
|
||||
$sel = $menu->display(0, 0, 30, 0, "value");
|
||||
$this->redrawEditor();
|
||||
switch ($sel) {
|
||||
case 'cancel':
|
||||
break;
|
||||
case 'save':
|
||||
if ($this->doWriteFile()) {
|
||||
$this->running = false;
|
||||
}
|
||||
break;
|
||||
case 'discard':
|
||||
$this->running = false;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$this->running = false;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case "g":
|
||||
@ -265,6 +292,10 @@ class Editor
|
||||
$this->showMessage("Toggle compact groups (c)");
|
||||
break;
|
||||
|
||||
case "\x03": // ctrl-c
|
||||
$this->showMessage("\e[30;43mPress Ctrl-X to exit.");
|
||||
break;
|
||||
|
||||
case "\x0e": // ctrl-n
|
||||
$this->document->load((object)[]);
|
||||
$this->list->parseTree();
|
||||
@ -350,11 +381,14 @@ class Editor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function doWriteFile(): void
|
||||
private function doWriteFile(): bool
|
||||
{
|
||||
[$w,$h] = $this->term->getSize();
|
||||
|
||||
$saveTo = $this->ask("\e[33mWrite to:\e[0m ", $this->filename);
|
||||
if (!$saveTo) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$doc = $this->document->save();
|
||||
|
||||
@ -371,6 +405,7 @@ class Editor
|
||||
break;
|
||||
default:
|
||||
$this->showMessage("\e[97;41mUnable to write format: {$ext}");
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->filename = $saveTo;
|
||||
@ -379,7 +414,7 @@ class Editor
|
||||
$this->redrawEditor();
|
||||
|
||||
$this->showMessage("\e[97;42mWrote to {$saveTo}");
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,11 @@ class TreeList implements Countable
|
||||
private const TREE_INDENT_GUIDE = "\u{258f} ";
|
||||
private const TREE_INDENT = " ";
|
||||
|
||||
private const ICON_NUMERIC = "\u{f89f}";
|
||||
private const ICON_STRING = "\u{f475}";
|
||||
private const ICON_BOOL = "\u{f657}";
|
||||
private const ICON_NULL = "\u{2400}";
|
||||
|
||||
public function __construct(private Tree $tree)
|
||||
{
|
||||
}
|
||||
@ -186,6 +191,16 @@ class TreeList implements Countable
|
||||
}
|
||||
|
||||
if (!is_null($entry->key)) {
|
||||
if (Settings::$collapseBefore && $entry->node instanceof ValueNode) {
|
||||
echo match (gettype($entry->node->value)) {
|
||||
'string' => self::ICON_STRING,
|
||||
'integer' => self::ICON_NUMERIC,
|
||||
'double' => self::ICON_NUMERIC,
|
||||
'boolean' => self::ICON_BOOL,
|
||||
'NULL' => self::ICON_NULL,
|
||||
default => self::ICON_STRING,
|
||||
}." ";
|
||||
}
|
||||
echo (is_int($entry->key)
|
||||
?"\e[36;2m\u{e0b6}\e[7m#{$entry->key}\e[27m\u{e0b4}\e[22;37m "
|
||||
:(Settings::$editorQuotedKeys
|
||||
|
Loading…
Reference in New Issue
Block a user