Misc fixes and improvements

This commit is contained in:
Chris 2024-10-05 21:20:21 +02:00
parent f389e5985f
commit 7a37ebe234
3 changed files with 19 additions and 10 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "noccylabs/jsonedit", "name": "noccylabs/jsonedit",
"description": "JSON/YAML editor for terminal junkies", "description": "A JSON/YAML editor for terminal junkies",
"type": "application", "type": "application",
"license": "GPL-3.0-or-later", "license": "GPL-3.0-or-later",
"autoload": { "autoload": {

View File

@ -350,7 +350,10 @@ class Editor
[$w,$h] = $this->term->getSize(); [$w,$h] = $this->term->getSize();
$readFrom = $this->ask("\e[33mRead from:\e[0m ", ""); $readFrom = $this->ask("\e[33mRead from:\e[0m ", "");
if ($readFrom === null) {
$this->redrawInfoBar();
return;
}
if (!file_exists($readFrom)) { if (!file_exists($readFrom)) {
$this->showMessage("\e[97;41mFile does not exist"); $this->showMessage("\e[97;41mFile does not exist");
return; return;
@ -525,14 +528,15 @@ class Editor
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
EOT;
EOT."\n/ Built on: ".APP_BUILDDATE;
$width = 60; $width = 60;
$height = 20; $height = 21;
$left = round(($w / 2) - ($width / 2)); $left = round(($w / 2) - ($width / 2));
$top = round(($h / 2) - ($height / 2)); $top = round(($h / 2) - ($height / 2));
$msg = new MessageBox($this->term, $text, "About JSONEdit"); $msg = new MessageBox($this->term, $text, "About JSONEdit ".APP_VERSION);
$this->redrawInfoBar([ '↑/↓' => 'Scroll', '^C' => 'Close' ]); $this->redrawInfoBar([ '↑/↓' => 'Scroll', '^C' => 'Close' ]);
$msg->display($left, $top, $width, $height); $msg->display($left, $top, $width, $height);
$this->redrawEditor(); $this->redrawEditor();
@ -776,7 +780,7 @@ class Editor
} }
$cursorOffs = $cursorPos - $scrollPos; $cursorOffs = $cursorPos - $scrollPos;
$this->term->setCursor(1, $h); $this->term->setCursor(1, $h);
echo $prompt."\e[0m\e[K".mb_substr($value, $scrollPos, $available); echo "\e[0m".$prompt."\e[0m\e[K".mb_substr($value, $scrollPos, $available);
$this->term->setCursor($promptLen+$cursorOffs+1, $h, true); $this->term->setCursor($promptLen+$cursorOffs+1, $h, true);
while (null === ($ch = $this->term->readKey())) { while (null === ($ch = $this->term->readKey())) {
usleep(10000); usleep(10000);
@ -921,7 +925,7 @@ class Editor
]; ];
} }
$keys = [ ...$keys, $keys = [ ...$keys,
'^R' => 'Read', '^O' => 'Open',
'^X' => 'Exit', '^X' => 'Exit',
]; ];
} }
@ -971,8 +975,10 @@ Enter Edit string/number, toggle booleans
D Delete selected key D Delete selected key
c Toggle compact list view c Toggle compact list view
q Toggle quoted keys in list view q Toggle quoted keys in list view
^W Write to file g Toggle indentation guide lines visibility
^R Read from file t Toggle tail line visibility
^W Write to a file
^R Read from a file
^O Open file browser ^O Open file browser
^N New document with empty object ^N New document with empty object
^X Exit ^X Exit

View File

@ -117,7 +117,7 @@ class MessageBox
$scrollTop = $this->scroll; $scrollTop = $this->scroll;
$scrollBottom = $scrollTop + $visibleItems - 1; $scrollBottom = $scrollTop + $visibleItems - 1;
$thumbTop = round(($visibleItems - 1) / count($wrapped) * $scrollTop); $thumbTop = round(($visibleItems - 1) / count($wrapped) * $scrollTop);
$thumbBottom = round(($visibleItems - 1) / count($wrapped) * $scrollBottom); $thumbBottom = round($visibleItems / count($wrapped) * $scrollBottom);
echo "\e[40;37m"; echo "\e[40;37m";
$this->terminal $this->terminal
@ -139,6 +139,9 @@ class MessageBox
} elseif (str_starts_with($line, "### ")) { } elseif (str_starts_with($line, "### ")) {
$item = " " . mb_substr($line, 4); $item = " " . mb_substr($line, 4);
$pre = "\e[1;3m"; $post = "\e[23m"; $pre = "\e[1;3m"; $post = "\e[23m";
} elseif (str_starts_with($line, "/ ")) {
$item = " " . mb_substr($line, 2);
$pre = "\e[3m"; $post = "\e[23m";
} else { } else {
$item = " " . $line; $item = " " . $line;
$pre = null; $post = null; $pre = null; $post = null;