Skip to content

Commit

Permalink
Add full Unicode support to non-ansi consoles. Correct detection of W…
Browse files Browse the repository at this point in the history
…indows Terminal.
  • Loading branch information
okibcn authored and Bill-Gray committed May 9, 2023
1 parent 3ec63c9 commit 75b62ea
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
22 changes: 15 additions & 7 deletions wincon/pdcdisp.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ static void _show_run_of_ansi_characters( const attr_t attr,
const int lineno, const int x, const chtype *srcp, const int len)
{
#ifdef PDC_WIDE
WCHAR buffer[MAX_PACKET_SIZE];
WCHAR buffer[MAX_PACKET_SIZE*2];
#else
char buffer[MAX_PACKET_SIZE];
#endif
Expand All @@ -169,9 +169,9 @@ static void _show_run_of_ansi_characters( const attr_t attr,
ch = ' ';

#ifdef PDC_WIDE
chtype uc = ch & A_CHARTEXT; //o//
if( uc != DUMMY_CHAR_NEXT_TO_FULLWIDTH){
if (uc & 0xFF0000){
chtype uc = ch & A_CHARTEXT;
if( uc < 0x110000){
if (uc & 0x1F0000){
buffer[n_out++] = (WCHAR)((uc - 0x10000) >> 10 | 0xD800); /* first UTF-16 unit */
buffer[n_out++] = (WCHAR)(uc & 0x3FF) | 0xDC00; /* second UTF-16 unit */
}else
Expand Down Expand Up @@ -228,10 +228,18 @@ static void _show_run_of_nonansi_characters( attr_t attr,

buffer[n_out].Attributes = mapped_attr;
#ifdef PDC_WIDE
if( (ch & A_CHARTEXT) != DUMMY_CHAR_NEXT_TO_FULLWIDTH)
chtype uc = ch & A_CHARTEXT;
if( uc < 0x110000){
if (uc & 0x1F0000){
buffer[n_out++].Char.UnicodeChar = (WCHAR)((uc - 0x10000) >> 10 | 0xD800); /* first UTF-16 unit */
buffer[n_out].Attributes = mapped_attr;
buffer[n_out++].Char.UnicodeChar = (WCHAR)(uc & 0x3FF) | 0xDC00; /* second UTF-16 unit */
}else
buffer[n_out++].Char.UnicodeChar = (WCHAR)uc;
}
#else
buffer[n_out++].Char.UnicodeChar = (WCHAR)( ch & A_CHARTEXT);
#endif
buffer[n_out++].Char.UnicodeChar = (WCHAR)( ch & A_CHARTEXT);
}

bufPos.X = bufPos.Y = 0;
bufSize.X = (SHORT)n_out;
Expand Down
6 changes: 1 addition & 5 deletions wincon/pdcscrn.c
Original file line number Diff line number Diff line change
Expand Up @@ -413,11 +413,7 @@ int PDC_scr_open(void)
pdc_wt = !!getenv("WT_SESSION");
str = pdc_wt ? NULL : getenv("ConEmuANSI");
pdc_conemu = !!str;
pdc_ansi =
#ifdef PDC_WIDE
pdc_wt ? TRUE :
#endif
pdc_conemu ? !strcmp(str, "ON") : FALSE;
pdc_ansi = !pdc_wt && pdc_conemu && !strcmp(str, "ON");

GetConsoleScreenBufferInfo(pdc_con_out, &csbi);
GetConsoleScreenBufferInfo(pdc_con_out, &orig_scr);
Expand Down

0 comments on commit 75b62ea

Please sign in to comment.