Skip to content

Commit

Permalink
pass max width as a negative number to avoid truncation
Browse files Browse the repository at this point in the history
  • Loading branch information
joetannenbaum committed Oct 21, 2023
1 parent 7ad75f9 commit a242eeb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Concerns/TypedValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ protected function addCursor(string $value, int $cursorPosition, int $maxWidth):

$cursor = mb_strlen($current) && $current !== PHP_EOL ? $current : ' ';

$spaceBefore = $maxWidth - mb_strwidth($cursor) - (mb_strwidth($after) > 0 ? 1 : 0);
$spaceBefore = $maxWidth < 0 ? mb_strwidth($before) : $maxWidth - mb_strwidth($cursor) - (mb_strwidth($after) > 0 ? 1 : 0);
[$truncatedBefore, $wasTruncatedBefore] = mb_strwidth($before) > $spaceBefore
? [$this->trimWidthBackwards($before, 0, $spaceBefore - 1), true]
: [$before, false];

$spaceAfter = $maxWidth - ($wasTruncatedBefore ? 1 : 0) - mb_strwidth($truncatedBefore) - mb_strwidth($cursor);
$spaceAfter = $maxWidth < 0 ? mb_strwidth($after) : $maxWidth - ($wasTruncatedBefore ? 1 : 0) - mb_strwidth($truncatedBefore) - mb_strwidth($cursor);
[$truncatedAfter, $wasTruncatedAfter] = mb_strwidth($after) > $spaceAfter
? [mb_strimwidth($after, 0, $spaceAfter - 1), true]
: [$after, false];
Expand Down
3 changes: 1 addition & 2 deletions src/TextareaPrompt.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ public function valueWithCursor(int $maxWidth): string
return $this->dim($this->addCursor($this->placeholder, 0, 10_000));
}

// TODO: Deal with max width properly, 10_000 is a hack
return $this->addCursor($value, $this->cursorPosition, 10_000);
return $this->addCursor($value, $this->cursorPosition, -1);
}
}

0 comments on commit a242eeb

Please sign in to comment.