Misc fixes

This commit is contained in:
2024-10-07 00:30:09 +02:00
parent 46bf135446
commit 0e1354bd47
6 changed files with 33 additions and 32 deletions

View File

@@ -403,7 +403,7 @@ class Editor
/**
* Handler for the write file command (ctrl-W)
*
* @return void
* @return bool
*/
private function doWriteFile(): bool
{
@@ -501,7 +501,7 @@ class Editor
})
->setItems($items)
->setTitle($wd)
->display(0, 0, 70, 20, $this->filename);
->display(0, 0, 70, 0, $this->filename);
if ($sel === null) {
$this->redrawEditor();
return;
@@ -536,8 +536,8 @@ class Editor
$width = min(90, $w - 10);
$height = min(40, $h - 6);
$left = round(($w / 2) - ($width / 2));
$top = round(($h / 2) - ($height / 2));
$left = (int)round(($w / 2) - ($width / 2));
$top = (int)round(($h / 2) - ($height / 2));
$msg = new MessageBox($this->term, self::$helpText, "Help");
$this->redrawInfoBar([ '↑/↓' => 'Scroll', '^C' => 'Close' ]);
@@ -562,9 +562,9 @@ class Editor
EOT."\n/ Version: ".APP_VERSION."\n/ Built at: ".APP_BUILDDATE;
$width = 60;
$height = 22;
$left = round(($w / 2) - ($width / 2));
$top = round(($h / 2) - ($height / 2));
$height = 0; // 22;
$left = 0; // (int)round(($w / 2) - ($width / 2));
$top = 0; // (int)round(($h / 2) - ($height / 2));
$msg = new MessageBox($this->term, $text, "About JSONEdit ".APP_VERSION);
$this->redrawInfoBar([ '↑/↓' => 'Scroll', '^C' => 'Close' ]);
@@ -654,7 +654,7 @@ class Editor
$deleteKey = basename($path);
$collNode = $this->list->getNodeForPath($parentPath);
if ($collNode instanceof ArrayNode) {
$collNode->removeIndex($deleteKey);
$collNode->removeIndex(intval($deleteKey));
$this->list->parseTree();
$this->redrawEditor();
$this->modified = true;

View File

@@ -83,12 +83,12 @@ class Menu
* @param string|int|null $value
* @return mixed
*/
public function display(int $left, int $top, int $width, int $height = 0, string|int|null $value): mixed
public function display(int $left, int $top, int $width, int $height = 0, string|int|null $value = null): mixed
{
//$this->index = 0;
$keys = array_keys($this->items);
$this->index = array_search($value, $keys) ?? 0;
$this->index = array_search($value, $keys) ?: 0;
[$w,$h] = $this->terminal->getSize();
if ($height == 0) {
@@ -187,7 +187,7 @@ class Menu
$thumbTop = round(($visibleItems - 1) / count($this->items) * $scrollTop);
$thumbBottom = round(($visibleItems) / count($this->items) * $scrollBottom);
$tleft = round(($width / 2) - ((mb_strlen($this->title) + 2) / 2));
$tleft = (int)round(($width / 2) - ((mb_strlen($this->title) + 2) / 2));
// draw head
echo "\e[40;37m";

View File

@@ -53,13 +53,15 @@ class MessageBox
[$w,$h] = $this->terminal->getSize();
if ($height == 0) {
$height = min($h - 5, count($wrapped) + 4);
$height = min($h - $top - 2, count($wrapped) + 4);
}
// again? oh well..
$height = min($height, $h - $top - 2);
if ($left == 0) {
$left = round(($w - $width) / 2);
}
if ($top == 0) {
$top = round(($h - $height) / 2);
$top = (int)round(($h - $height) / 2);
}
$maxScroll = (count($wrapped) > $height) ? count($wrapped) - $height + 4 : 0;
@@ -127,6 +129,7 @@ class MessageBox
* @return void
*/
private function redraw(int $left, int $top, int $width, int $height, array $wrapped, string $title, int $maxScroll) {
$visibleItems = $height - 4;
// calculate scrollbar thumb positions
@@ -150,6 +153,8 @@ class MessageBox
->writeAt($left, $top + $height - 1, self::U_CORNER_BOTTOMLEFT.str_repeat(self::U_EDGE_HORIZONTAL,$width - 2).self::U_CORNER_BOTTOMRIGHT)
;
for ($n = 0; $n < $visibleItems; $n++) {
$pre = '';
$post = '';
if (isset($wrapped[$n+$this->scroll])) {
$line = $wrapped[$n+$this->scroll]??null;
if (str_starts_with($line, "# ")) {