Fix incorrect width calculation

This commit is contained in:
Blargian 2024-06-04 14:09:32 +02:00
parent 6a8adb6d48
commit 8b9bb1d473
2 changed files with 10 additions and 15 deletions

View File

@ -116,6 +116,11 @@ size_t computeWidthImpl(const UInt8 * data, size_t size, size_t prefix, size_t l
while (i + 15 < size)
{
if (isEscapeSequence)
{
break;
}
__m128i bytes = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&data[i]));
const uint16_t non_regular_width_mask = _mm_movemask_epi8(
@ -132,15 +137,8 @@ size_t computeWidthImpl(const UInt8 * data, size_t size, size_t prefix, size_t l
}
else
{
if (isEscapeSequence)
{
break;
}
else
{
i += 16;
width += 16;
}
i += 16;
width += 16;
}
}
#endif
@ -149,7 +147,7 @@ size_t computeWidthImpl(const UInt8 * data, size_t size, size_t prefix, size_t l
{
auto isParameterByte = isCSIParameterByte(data[i]);
auto isIntermediateByte = isCSIIntermediateByte(data[i]);
auto ignore_width = isEscapeSequence & (isParameterByte || isIntermediateByte);
auto ignore_width = isEscapeSequence && (isParameterByte || isIntermediateByte);
if (ignore_width || (data[i] == '[' && isEscapeSequence))
{

View File

@ -1,6 +1,3 @@
SELECT format('\x1b[38;2;{0};{1};{2}m█\x1b[0m', 255, 128, 128) AS x;
SELECT format('\x1b[38;2;{0};{1};{2}m█ test \x1b[0m', 255, 128, 128) AS x;
SELECT format('\x1b[38;2;{0};{1};{2}m█\x1b[0m test', 255, 128, 128) AS x;
SELECT format('test \x1b[38;2;{0};{1};{2}m█\x1b[0m', 255, 128, 128) AS x;
SELECT format('\x1b[38;2;{0};{1};{2}m█\x1b[0m test \x1b[38;2;{0};{1};{2}m█\x1b[0m', 255, 128, 128) AS x;
SELECT visibleWidth('0};{1};{2}m█');
SELECT 'Hello', format('\x1b[38;2;{0};{1};{2}m█\x1b[0m test \x1b[38;2;{0};{1};{2}m█\x1b[0m', 255, 128, 128) AS x
SELECT visibleWidth(format('\x1b[38;2;{0};{1};{2}m█\x1b[0m',255,128,128));