Fixed the incorrect display on terminals without UTF-8 character encoding
This commit is contained in:
parent
48a67c4eab
commit
59917ed126
|
@ -1,3 +1,7 @@
|
||||||
|
2021-02-24 Markus Gans <guru.mail@muenster.de>
|
||||||
|
* Fixed the incorrect display on terminals without
|
||||||
|
UTF-8 character encoding
|
||||||
|
|
||||||
2021-02-20 Markus Gans <guru.mail@muenster.de>
|
2021-02-20 Markus Gans <guru.mail@muenster.de>
|
||||||
* Optimize terminal output buffer queue with differencing
|
* Optimize terminal output buffer queue with differencing
|
||||||
for strings, and control characters and control sequences
|
for strings, and control characters and control sequences
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
luit -encoding POSIX ../examples/ui
|
luit -encoding C ../examples/ui $@
|
||||||
|
|
||||||
|
|
|
@ -513,7 +513,11 @@ std::size_t getColumnWidth (const wchar_t wchar)
|
||||||
column_width = wcwidth(wchar);
|
column_width = wcwidth(wchar);
|
||||||
|
|
||||||
if ( (wchar >= UniChar::NF_rev_left_arrow2 && wchar <= UniChar::NF_check_mark)
|
if ( (wchar >= UniChar::NF_rev_left_arrow2 && wchar <= UniChar::NF_check_mark)
|
||||||
|| ! hasFullWidthSupports() )
|
|| FTerm::getEncoding() != Encoding::UTF8 )
|
||||||
|
{
|
||||||
|
column_width = 1;
|
||||||
|
}
|
||||||
|
else if ( ! hasFullWidthSupports() )
|
||||||
{
|
{
|
||||||
column_width = std::min(column_width, 1);
|
column_width = std::min(column_width, 1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -484,6 +484,8 @@ void FTermFunctionsTest::FullWidthHalfWidthTest()
|
||||||
CPPUNIT_ASSERT ( finalcut::getHalfWidth(L"ㄴ") == L"ᄂ" );
|
CPPUNIT_ASSERT ( finalcut::getHalfWidth(L"ㄴ") == L"ᄂ" );
|
||||||
|
|
||||||
// Column width (wchar_t)
|
// Column width (wchar_t)
|
||||||
|
const auto& data = finalcut::FTerm::getFTermData();
|
||||||
|
data->setTermEncoding (finalcut::Encoding::UTF8);
|
||||||
CPPUNIT_ASSERT ( finalcut::getColumnWidth(L"\t") == 0 );
|
CPPUNIT_ASSERT ( finalcut::getColumnWidth(L"\t") == 0 );
|
||||||
CPPUNIT_ASSERT ( finalcut::getColumnWidth(L"\r") == 0 );
|
CPPUNIT_ASSERT ( finalcut::getColumnWidth(L"\r") == 0 );
|
||||||
CPPUNIT_ASSERT ( finalcut::getColumnWidth(L"\n") == 0 );
|
CPPUNIT_ASSERT ( finalcut::getColumnWidth(L"\n") == 0 );
|
||||||
|
@ -502,6 +504,21 @@ void FTermFunctionsTest::FullWidthHalfWidthTest()
|
||||||
CPPUNIT_ASSERT ( finalcut::getColumnWidth(L"\U0000094d") == 0 );
|
CPPUNIT_ASSERT ( finalcut::getColumnWidth(L"\U0000094d") == 0 );
|
||||||
CPPUNIT_ASSERT ( finalcut::getColumnWidth(L"\U00000e37") == 0 );
|
CPPUNIT_ASSERT ( finalcut::getColumnWidth(L"\U00000e37") == 0 );
|
||||||
|
|
||||||
|
// Column width (wchar_t) in latin-1
|
||||||
|
std::setlocale (LC_CTYPE, "C");
|
||||||
|
data->setTermEncoding (finalcut::Encoding::VT100);
|
||||||
|
CPPUNIT_ASSERT ( finalcut::getColumnWidth(L'─') == 1 ); // wcwidth(L'─') == -1 (for LC_CTYPE = C)
|
||||||
|
CPPUNIT_ASSERT ( finalcut::getColumnWidth(L'│') == 1 ); // wcwidth(L'│') == -1 (for LC_CTYPE = C)
|
||||||
|
CPPUNIT_ASSERT ( finalcut::getColumnWidth(L'├') == 1 ); // wcwidth(L'├') == -1 (for LC_CTYPE = C)
|
||||||
|
CPPUNIT_ASSERT ( finalcut::getColumnWidth(L'┤') == 1 ); // wcwidth(L'┤') == -1 (for LC_CTYPE = C)
|
||||||
|
CPPUNIT_ASSERT ( finalcut::getColumnWidth(L'┼') == 1 ); // wcwidth(L'┼') == -1 (for LC_CTYPE = C)
|
||||||
|
CPPUNIT_ASSERT ( finalcut::getColumnWidth(L'┐') == 1 ); // wcwidth(L'┐') == -1 (for LC_CTYPE = C)
|
||||||
|
CPPUNIT_ASSERT ( finalcut::getColumnWidth(L'└') == 1 ); // wcwidth(L'└') == -1 (for LC_CTYPE = C)
|
||||||
|
CPPUNIT_ASSERT ( finalcut::getColumnWidth(L'┌') == 1 ); // wcwidth(L'┌') == -1 (for LC_CTYPE = C)
|
||||||
|
CPPUNIT_ASSERT ( finalcut::getColumnWidth(L'┘') == 1 ); // wcwidth(L'┘') == -1 (for LC_CTYPE = C)
|
||||||
|
std::setlocale (LC_CTYPE, "en_US.UTF-8");
|
||||||
|
data->setTermEncoding (finalcut::Encoding::UTF8);
|
||||||
|
|
||||||
// Column width (FString)
|
// Column width (FString)
|
||||||
CPPUNIT_ASSERT ( finalcut::getColumnWidth(L"\v\t 100") == 4 );
|
CPPUNIT_ASSERT ( finalcut::getColumnWidth(L"\v\t 100") == 4 );
|
||||||
CPPUNIT_ASSERT ( finalcut::getColumnWidth(L"0123456789") == 10 );
|
CPPUNIT_ASSERT ( finalcut::getColumnWidth(L"0123456789") == 10 );
|
||||||
|
@ -733,25 +750,25 @@ void FTermFunctionsTest::FullWidthHalfWidthTest()
|
||||||
std::copy(std::begin(s), std::end(s), std::begin(fchar.ch));
|
std::copy(std::begin(s), std::end(s), std::begin(fchar.ch));
|
||||||
CPPUNIT_ASSERT ( finalcut::getColumnWidth(fchar) == 0 );
|
CPPUNIT_ASSERT ( finalcut::getColumnWidth(fchar) == 0 );
|
||||||
finalcut::addColumnWidth(fchar);
|
finalcut::addColumnWidth(fchar);
|
||||||
CPPUNIT_ASSERT ( finalcut::getColumnWidth(fchar) == 1 );
|
CPPUNIT_ASSERT ( finalcut::getColumnWidth(fchar) == 2 );
|
||||||
fchar.attr.bit.char_width = 0x00 & 0x03;
|
fchar.attr.bit.char_width = 0x00 & 0x03;
|
||||||
s = L"1";
|
s = L"1";
|
||||||
std::copy(std::begin(s), std::end(s), std::begin(fchar.ch));
|
std::copy(std::begin(s), std::end(s), std::begin(fchar.ch));
|
||||||
CPPUNIT_ASSERT ( finalcut::getColumnWidth(fchar) == 0 );
|
CPPUNIT_ASSERT ( finalcut::getColumnWidth(fchar) == 0 );
|
||||||
finalcut::addColumnWidth(fchar);
|
finalcut::addColumnWidth(fchar);
|
||||||
CPPUNIT_ASSERT ( finalcut::getColumnWidth(fchar) == 1 );
|
CPPUNIT_ASSERT ( finalcut::getColumnWidth(fchar) == 2 );
|
||||||
fchar.attr.bit.char_width = 0x00 & 0x03;
|
fchar.attr.bit.char_width = 0x00 & 0x03;
|
||||||
s = L"2";
|
s = L"2";
|
||||||
std::copy(std::begin(s), std::end(s), std::begin(fchar.ch));
|
std::copy(std::begin(s), std::end(s), std::begin(fchar.ch));
|
||||||
CPPUNIT_ASSERT ( finalcut::getColumnWidth(fchar) == 0 );
|
CPPUNIT_ASSERT ( finalcut::getColumnWidth(fchar) == 0 );
|
||||||
finalcut::addColumnWidth(fchar);
|
finalcut::addColumnWidth(fchar);
|
||||||
CPPUNIT_ASSERT ( finalcut::getColumnWidth(fchar) == 1 );
|
CPPUNIT_ASSERT ( finalcut::getColumnWidth(fchar) == 2 );
|
||||||
fchar.attr.bit.char_width = 0x00 & 0x03;
|
fchar.attr.bit.char_width = 0x00 & 0x03;
|
||||||
s = L"3";
|
s = L"3";
|
||||||
std::copy(std::begin(s), std::end(s), std::begin(fchar.ch));
|
std::copy(std::begin(s), std::end(s), std::begin(fchar.ch));
|
||||||
CPPUNIT_ASSERT ( finalcut::getColumnWidth(fchar) == 0 );
|
CPPUNIT_ASSERT ( finalcut::getColumnWidth(fchar) == 0 );
|
||||||
finalcut::addColumnWidth(fchar);
|
finalcut::addColumnWidth(fchar);
|
||||||
CPPUNIT_ASSERT ( finalcut::getColumnWidth(fchar) == 1 );
|
CPPUNIT_ASSERT ( finalcut::getColumnWidth(fchar) == 2 );
|
||||||
fchar.attr.bit.char_width = 0x00 & 0x03;
|
fchar.attr.bit.char_width = 0x00 & 0x03;
|
||||||
s = L"\U00000300";
|
s = L"\U00000300";
|
||||||
std::copy(std::begin(s), std::end(s), std::begin(fchar.ch));
|
std::copy(std::begin(s), std::end(s), std::begin(fchar.ch));
|
||||||
|
@ -779,8 +796,6 @@ void FTermFunctionsTest::FullWidthHalfWidthTest()
|
||||||
fchar.attr.bit.char_width = 0x00 & 0x03;
|
fchar.attr.bit.char_width = 0x00 & 0x03;
|
||||||
|
|
||||||
// Column width (FTermBuffer)
|
// Column width (FTermBuffer)
|
||||||
const auto& data = finalcut::FTerm::getFTermData();
|
|
||||||
data->setTermEncoding (finalcut::Encoding::UTF8);
|
|
||||||
finalcut::FTermBuffer term_buf{};
|
finalcut::FTermBuffer term_buf{};
|
||||||
term_buf << L"\v\t 100";
|
term_buf << L"\v\t 100";
|
||||||
CPPUNIT_ASSERT ( finalcut::getColumnWidth(term_buf) == 4 );
|
CPPUNIT_ASSERT ( finalcut::getColumnWidth(term_buf) == 4 );
|
||||||
|
|
Loading…
Reference in New Issue