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",
"description": "JSON/YAML editor for terminal junkies",
"description": "A JSON/YAML editor for terminal junkies",
"type": "application",
"license": "GPL-3.0-or-later",
"autoload": {

View File

@ -350,7 +350,10 @@ class Editor
[$w,$h] = $this->term->getSize();
$readFrom = $this->ask("\e[33mRead from:\e[0m ", "");
if ($readFrom === null) {
$this->redrawInfoBar();
return;
}
if (!file_exists($readFrom)) {
$this->showMessage("\e[97;41mFile does not exist");
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 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;
$height = 20;
$height = 21;
$left = round(($w / 2) - ($width / 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' ]);
$msg->display($left, $top, $width, $height);
$this->redrawEditor();
@ -776,7 +780,7 @@ class Editor
}
$cursorOffs = $cursorPos - $scrollPos;
$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);
while (null === ($ch = $this->term->readKey())) {
usleep(10000);
@ -921,7 +925,7 @@ class Editor
];
}
$keys = [ ...$keys,
'^R' => 'Read',
'^O' => 'Open',
'^X' => 'Exit',
];
}
@ -971,8 +975,10 @@ Enter Edit string/number, toggle booleans
D Delete selected key
c Toggle compact list view
q Toggle quoted keys in list view
^W Write to file
^R Read from file
g Toggle indentation guide lines visibility
t Toggle tail line visibility
^W Write to a file
^R Read from a file
^O Open file browser
^N New document with empty object
^X Exit

View File

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