Fix window titles, tweaks
This commit is contained in:
parent
c51355aba7
commit
54b00f5925
@ -56,8 +56,6 @@ class Editor
|
|||||||
*/
|
*/
|
||||||
public function loadFile(string $filename): void
|
public function loadFile(string $filename): void
|
||||||
{
|
{
|
||||||
$this->filename = $filename;
|
|
||||||
$this->shortfilename = basename($filename);
|
|
||||||
$ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
|
$ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
|
||||||
switch ($ext) {
|
switch ($ext) {
|
||||||
case 'json':
|
case 'json':
|
||||||
@ -70,7 +68,7 @@ class Editor
|
|||||||
default:
|
default:
|
||||||
throw new \RuntimeException("Unable to read file of type {$ext}");
|
throw new \RuntimeException("Unable to read file of type {$ext}");
|
||||||
}
|
}
|
||||||
$this->setWindowTitle($this->shortfilename." - JSONEdit");
|
$this->setOpenedFilename($filename);
|
||||||
$this->document->load($doc);
|
$this->document->load($doc);
|
||||||
$this->list->parseTree();
|
$this->list->parseTree();
|
||||||
}
|
}
|
||||||
@ -317,44 +315,7 @@ class Editor
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case "\x13": // ctrl-s
|
case "\x13": // ctrl-s
|
||||||
$sel = null;
|
$this->doSettingsMenu();
|
||||||
$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;
|
break;
|
||||||
|
|
||||||
case "\x0F": // ctrl-o
|
case "\x0F": // ctrl-o
|
||||||
@ -480,13 +441,10 @@ class Editor
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->filename = $saveTo;
|
$this->setOpenedFilename($saveTo);
|
||||||
$this->shortfilename = basename($saveTo);
|
|
||||||
$this->modified = false;
|
$this->modified = false;
|
||||||
$this->redrawEditor();
|
$this->redrawEditor();
|
||||||
|
|
||||||
$this->setWindowTitle($this->shortfilename." - JSONEdit");
|
|
||||||
|
|
||||||
$this->showMessage("\e[97;42mWrote to {$saveTo}");
|
$this->showMessage("\e[97;42mWrote to {$saveTo}");
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@ -566,8 +524,7 @@ class Editor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->filename = $sel;
|
$this->setOpenedFilename($sel);
|
||||||
$this->shortfilename = basename($sel);
|
|
||||||
$this->redrawEditor();
|
$this->redrawEditor();
|
||||||
$this->showMessage("\e[42;97mOpened {$this->shortfilename}");
|
$this->showMessage("\e[42;97mOpened {$this->shortfilename}");
|
||||||
}
|
}
|
||||||
@ -825,6 +782,48 @@ class Editor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function doSettingsMenu(): void
|
||||||
|
{
|
||||||
|
$sel = null;
|
||||||
|
$mark = "\u{f657} ";
|
||||||
|
$clear = "\u{f630} ";
|
||||||
|
|
||||||
|
do {
|
||||||
|
$this->redrawEditor();
|
||||||
|
$this->redrawInfoBar([ "^C" => "Close", "↑↓" => "Navigate", "Enter" => "Toggle/Select" ]);
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
} while ($sel);
|
||||||
|
$this->redrawEditor();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ask for input
|
* Ask for input
|
||||||
*
|
*
|
||||||
@ -1018,6 +1017,13 @@ class Editor
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function setOpenedFilename(string $filename): void
|
||||||
|
{
|
||||||
|
$this->filename = $filename;
|
||||||
|
$this->shortfilename = basename($filename);
|
||||||
|
$this->setWindowTitle($this->shortfilename." - JSONEdit");
|
||||||
|
}
|
||||||
|
|
||||||
private function setWindowTitle(string $title): void
|
private function setWindowTitle(string $title): void
|
||||||
{
|
{
|
||||||
echo "\e]2;{$title}\x07";
|
echo "\e]2;{$title}\x07";
|
||||||
|
Loading…
Reference in New Issue
Block a user