Skip to content

Commit

Permalink
Fix issue when truncating unicode text (php-tui#215)
Browse files Browse the repository at this point in the history
* Fix issue when truncating unicode text

* Update CHANGELOG.md
  • Loading branch information
KennedyTedesco authored Dec 3, 2023
1 parent 2c5b673 commit 2da2df8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ Refactoring:
Bug fixes:

- Fix block adjacent border renderering #201
- Fix `StyledGrapheme` symbol width #214
- Fix `StyledGrapheme` symbol width #214 @KennedyTedesco
- Fix issue when truncating unicode text #215 @KennedyTedesco

## 0.1.0

Expand Down
2 changes: 1 addition & 1 deletion src/Text/LineComposer/LineTruncator.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function nextLine(): Generator
);

$currentLine[] = new StyledGrapheme($symbol, $styledGrapheme->style);
$currentLineWidth += mb_strlen($symbol);
$currentLineWidth += mb_strwidth($symbol);
}
yield [
$currentLine,
Expand Down
10 changes: 9 additions & 1 deletion tests/Unit/Extension/Core/Widget/ParagraphRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function testFromMultilineString(): void
'Goodbye ',
], $buffer->toLines());
}

/**
* @dataProvider provideParagraph
*/
Expand All @@ -46,8 +47,8 @@ public function testParagraph(
$buffer = Buffer::empty($area);
$this->render($buffer, $paragraph);
self::assertEquals($expected, $buffer->toString());

}

/**
* @return Generator<string,array{Area,ParagraphWidget,string}>
*/
Expand Down Expand Up @@ -85,5 +86,12 @@ public static function provideParagraph(): Generator
'1/1 ',
' About',
];
yield 'unicode' => [
Area::fromDimensions(14, 1),
ParagraphWidget::fromText(
Text::fromString('こんにちは, 世界! 😃')
),
'こんにちは, 世',
];
}
}

0 comments on commit 2da2df8

Please sign in to comment.