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;
|
break;
|
||||||
|
|
||||||
case "\x18": // ctrl-x
|
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;
|
break;
|
||||||
|
|
||||||
case "g":
|
case "g":
|
||||||
@ -264,6 +291,10 @@ class Editor
|
|||||||
$this->redrawEditor();
|
$this->redrawEditor();
|
||||||
$this->showMessage("Toggle compact groups (c)");
|
$this->showMessage("Toggle compact groups (c)");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "\x03": // ctrl-c
|
||||||
|
$this->showMessage("\e[30;43mPress Ctrl-X to exit.");
|
||||||
|
break;
|
||||||
|
|
||||||
case "\x0e": // ctrl-n
|
case "\x0e": // ctrl-n
|
||||||
$this->document->load((object)[]);
|
$this->document->load((object)[]);
|
||||||
@ -350,11 +381,14 @@ class Editor
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function doWriteFile(): void
|
private function doWriteFile(): bool
|
||||||
{
|
{
|
||||||
[$w,$h] = $this->term->getSize();
|
[$w,$h] = $this->term->getSize();
|
||||||
|
|
||||||
$saveTo = $this->ask("\e[33mWrite to:\e[0m ", $this->filename);
|
$saveTo = $this->ask("\e[33mWrite to:\e[0m ", $this->filename);
|
||||||
|
if (!$saveTo) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$doc = $this->document->save();
|
$doc = $this->document->save();
|
||||||
|
|
||||||
@ -371,6 +405,7 @@ class Editor
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$this->showMessage("\e[97;41mUnable to write format: {$ext}");
|
$this->showMessage("\e[97;41mUnable to write format: {$ext}");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->filename = $saveTo;
|
$this->filename = $saveTo;
|
||||||
@ -379,7 +414,7 @@ class Editor
|
|||||||
$this->redrawEditor();
|
$this->redrawEditor();
|
||||||
|
|
||||||
$this->showMessage("\e[97;42mWrote to {$saveTo}");
|
$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_GUIDE = "\u{258f} ";
|
||||||
private const TREE_INDENT = " ";
|
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)
|
public function __construct(private Tree $tree)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -186,6 +191,16 @@ class TreeList implements Countable
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!is_null($entry->key)) {
|
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)
|
echo (is_int($entry->key)
|
||||||
?"\e[36;2m\u{e0b6}\e[7m#{$entry->key}\e[27m\u{e0b4}\e[22;37m "
|
?"\e[36;2m\u{e0b6}\e[7m#{$entry->key}\e[27m\u{e0b4}\e[22;37m "
|
||||||
:(Settings::$editorQuotedKeys
|
:(Settings::$editorQuotedKeys
|
||||||
|
Loading…
Reference in New Issue
Block a user