Fix viewport width issues in thinking selector and text rendering

Thinking selector fix:
- Replace hardcoded 50-character borders with DynamicBorder component
  that adjusts to viewport width
- Prevents crash when terminal is resized narrow

Text/Markdown rendering fixes:
- Fix Markdown wrapSingleLine to check if adding next character would
  exceed width BEFORE adding it (was checking AFTER, causing lines to
  be 1 character too long)
- Add word truncation in Text component for words longer than
  contentWidth (prevents long unbreakable words from exceeding width)

These fixes prevent "Rendered line exceeds terminal width" errors.
This commit is contained in:
Mario Zechner 2025-11-11 23:52:18 +01:00
parent a3b3849188
commit 02a21dd936
3 changed files with 37 additions and 11 deletions

View file

@ -84,13 +84,27 @@ export class Text implements Component {
const currentVisible = visibleWidth(currentLine);
const wordVisible = visibleWidth(word);
// If word is too long, truncate it
let finalWord = word;
if (wordVisible > contentWidth) {
// Truncate word to fit
let truncated = "";
for (const char of word) {
if (visibleWidth(truncated + char) > contentWidth) {
break;
}
truncated += char;
}
finalWord = truncated;
}
if (currentVisible === 0) {
currentLine = word;
} else if (currentVisible + 1 + wordVisible <= contentWidth) {
currentLine += " " + word;
currentLine = finalWord;
} else if (currentVisible + 1 + visibleWidth(finalWord) <= contentWidth) {
currentLine += " " + finalWord;
} else {
lines.push(currentLine);
currentLine = word;
currentLine = finalWord;
}
}