Patch 8.0.0982
Problem: When 'encoding' is set to a multi-byte encoding other than utf-8
the characters from ther terminal are messed up.
Solution: Convert displayed text from utf-8 to 'encoding' for MS-Windows.
(Yasuhiro Matsumoto, close #2000)
Files: src/terminal.c
*** ../vim-8.0.0981/src/terminal.c 2017-08-21 21:39:23.386697504 +0200
--- src/terminal.c 2017-08-21 21:57:56.019721577 +0200
***************
*** 49,56 ****
"err_io", "err_name", "err_buf", "err_modifiable", "err_msg"
* Check that something is connected to the terminal.
* Test: "cat" reading from a file or buffer
! * "ls" writing stdout to a file or buffer
! * shell writing stderr to a file or buffer
* - For the GUI fill termios with default values, perhaps like pangoterm:
*
http://bazaar.launchpad.net/~leonerd/pangoterm/trunk/view/head:/main.c#L134
* - support ":term NONE" to open a terminal with a pty but not running a job
--- 49,56 ----
"err_io", "err_name", "err_buf", "err_modifiable", "err_msg"
* Check that something is connected to the terminal.
* Test: "cat" reading from a file or buffer
! * "ls" writing stdout to a file or buffer
! * shell writing stderr to a file or buffer
* - For the GUI fill termios with default values, perhaps like pangoterm:
*
http://bazaar.launchpad.net/~leonerd/pangoterm/trunk/view/head:/main.c#L134
* - support ":term NONE" to open a terminal with a pty but not running a job
***************
*** 845,851 ****
int empty = (buf->b_ml.ml_flags & ML_EMPTY);
linenr_T lnum = buf->b_ml.ml_line_count;
! ml_append_buf(term->tl_buffer, lnum, text, len + 1, FALSE);
if (empty)
{
/* Delete the empty line that was in the empty buffer. */
--- 845,870 ----
int empty = (buf->b_ml.ml_flags & ML_EMPTY);
linenr_T lnum = buf->b_ml.ml_line_count;
! #ifdef _WIN32
! if (!enc_utf8 && enc_codepage > 0)
! {
! WCHAR *ret = NULL;
! int length = 0;
!
! MultiByteToWideChar_alloc(CP_UTF8, 0, (char*)text, len + 1,
! &ret, &length);
! if (ret != NULL)
! {
! WideCharToMultiByte_alloc(enc_codepage, 0,
! ret, length, (char **)&text, &len, 0, 0);
! vim_free(ret);
! ml_append_buf(term->tl_buffer, lnum, text, len, FALSE);
! vim_free(text);
! }
! }
! else
! #endif
! ml_append_buf(term->tl_buffer, lnum, text, len + 1, FALSE);
if (empty)
{
/* Delete the empty line that was in the empty buffer. */
***************
*** 936,942 ****
int c;
for (i = 0; (c = cell.chars[i]) > 0 || i == 0; ++i)
! ga.ga_len += mb_char2bytes(c == NUL ? ' ' : c,
(char_u *)ga.ga_data + ga.ga_len);
}
}
--- 955,961 ----
int c;
for (i = 0; (c = cell.chars[i]) > 0 || i == 0; ++i)
! ga.ga_len += utf_char2bytes(c == NUL ? ' ' : c,
(char_u *)ga.ga_data + ga.ga_len);
}
}
***************
*** 1468,1473 ****
--- 1487,1504 ----
goto theend;
}
}
+ # ifdef _WIN32
+ if (!enc_utf8 && has_mbyte && c >= 0x80)
+ {
+ WCHAR wc;
+ char_u mb[3];
+
+ mb[0] = (unsigned)c >> 8;
+ mb[1] = c;
+ if (MultiByteToWideChar(GetACP(), 0, (char*)mb, 2, &wc, 1) > 0)
+ c = wc;
+ }
+ # endif
if (send_keys_to_term(curbuf->b_term, c, TRUE) != OK)
{
ret = OK;
***************
*** 1627,1633 ****
/* 216-color cube */
return 17 + ((red + 25) / 0x33) * 36
! + ((green + 25) / 0x33) * 6
+ (blue + 25) / 0x33;
}
return 0;
--- 1658,1664 ----
/* 216-color cube */
return 17 + ((red + 25) / 0x33) * 36
! + ((green + 25) / 0x33) * 6
+ (blue + 25) / 0x33;
}
return 0;
***************
*** 2076,2095 ****
else
{
#if defined(FEAT_MBYTE)
! if (enc_utf8 && c >= 0x80)
{
! ScreenLines[off] = ' ';
! ScreenLinesUC[off] = c;
}
! else
{
! ScreenLines[off] = c;
! if (enc_utf8)
! ScreenLinesUC[off] = NUL;
}
! #else
! ScreenLines[off] = c;
#endif
}
ScreenAttrs[off] = cell2attr(cell.attrs, cell.fg, cell.bg);
--- 2107,2145 ----
else
{
#if defined(FEAT_MBYTE)
! if (enc_utf8)
{
! if (c >= 0x80)
! {
! ScreenLines[off] = ' ';
! ScreenLinesUC[off] = c;
! }
! else
! {
! ScreenLines[off] = c;
! ScreenLinesUC[off] = NUL;
! }
}
! # ifdef _WIN32
! else if (has_mbyte && c >= 0x80)
{
! char_u mb[MB_MAXBYTES+1];
! WCHAR wc = c;
!
! if (WideCharToMultiByte(GetACP(), 0, &wc, 1,
! (char*)mb, 2, 0, 0) > 1)
! {
! ScreenLines[off] = mb[0];
! ScreenLines[off+1] = mb[1];
! cell.width = mb_ptr2cells(mb);
! }
! else
! ScreenLines[off] = c;
}
! # endif
! else
#endif
+ ScreenLines[off] = c;
}
ScreenAttrs[off] = cell2attr(cell.attrs, cell.fg, cell.bg);
***************
*** 2097,2107 ****
++off;
if (cell.width == 2)
{
- ScreenLines[off] = NUL;
#if defined(FEAT_MBYTE)
if (enc_utf8)
ScreenLinesUC[off] = NUL;
#endif
++pos.col;
++off;
}
--- 2147,2158 ----
++off;
if (cell.width == 2)
{
#if defined(FEAT_MBYTE)
if (enc_utf8)
ScreenLinesUC[off] = NUL;
+ else if (!has_mbyte)
#endif
+ ScreenLines[off] = NUL;
++pos.col;
++off;
}
*** ../vim-8.0.0981/src/version.c 2017-08-21 21:39:23.390697480 +0200
--- src/version.c 2017-08-21 21:50:12.202679199 +0200
***************
*** 771,772 ****
--- 771,774 ----
{ /* Add new patch number below this line */
+ /**/
+ 982,
/**/
--
An alien life briefly visits earth. Just before departing it leaves a
message in the dust on the back of a white van. The world is shocked
and wants to know what it means. After months of studies the worlds
best linguistic scientists are able to decipher the message: "Wash me!".
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.