Add icons to items in before mode, ask to save changes
This commit is contained in:
@ -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":
|
||||
@ -264,6 +291,10 @@ class Editor
|
||||
$this->redrawEditor();
|
||||
$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)[]);
|
||||
@ -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;
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user