|
49 | 49 | "err_io", "err_name", "err_buf", "err_modifiable", "err_msg" |
50 | 50 | * Check that something is connected to the terminal. |
51 | 51 | * Test: "cat" reading from a file or buffer |
52 | | - * "ls" writing stdout to a file or buffer |
53 | | - * shell writing stderr to a file or buffer |
| 52 | + * "ls" writing stdout to a file or buffer |
| 53 | + * shell writing stderr to a file or buffer |
54 | 54 | * - For the GUI fill termios with default values, perhaps like pangoterm: |
55 | 55 | * http://bazaar.launchpad.net/~leonerd/pangoterm/trunk/view/head:/main.c#L134 |
56 | 56 | * - support ":term NONE" to open a terminal with a pty but not running a job |
@@ -845,7 +845,26 @@ add_scrollback_line_to_buffer(term_T *term, char_u *text, int len) |
845 | 845 | int empty = (buf->b_ml.ml_flags & ML_EMPTY); |
846 | 846 | linenr_T lnum = buf->b_ml.ml_line_count; |
847 | 847 |
|
848 | | - ml_append_buf(term->tl_buffer, lnum, text, len + 1, FALSE); |
| 848 | +#ifdef _WIN32 |
| 849 | + if (!enc_utf8 && enc_codepage > 0) |
| 850 | + { |
| 851 | + WCHAR *ret = NULL; |
| 852 | + int length = 0; |
| 853 | + |
| 854 | + MultiByteToWideChar_alloc(CP_UTF8, 0, (char*)text, len + 1, |
| 855 | + &ret, &length); |
| 856 | + if (ret != NULL) |
| 857 | + { |
| 858 | + WideCharToMultiByte_alloc(enc_codepage, 0, |
| 859 | + ret, length, (char **)&text, &len, 0, 0); |
| 860 | + vim_free(ret); |
| 861 | + ml_append_buf(term->tl_buffer, lnum, text, len, FALSE); |
| 862 | + vim_free(text); |
| 863 | + } |
| 864 | + } |
| 865 | + else |
| 866 | +#endif |
| 867 | + ml_append_buf(term->tl_buffer, lnum, text, len + 1, FALSE); |
849 | 868 | if (empty) |
850 | 869 | { |
851 | 870 | /* Delete the empty line that was in the empty buffer. */ |
@@ -936,7 +955,7 @@ move_terminal_to_buffer(term_T *term) |
936 | 955 | int c; |
937 | 956 |
|
938 | 957 | for (i = 0; (c = cell.chars[i]) > 0 || i == 0; ++i) |
939 | | - ga.ga_len += mb_char2bytes(c == NUL ? ' ' : c, |
| 958 | + ga.ga_len += utf_char2bytes(c == NUL ? ' ' : c, |
940 | 959 | (char_u *)ga.ga_data + ga.ga_len); |
941 | 960 | } |
942 | 961 | } |
@@ -1468,6 +1487,18 @@ terminal_loop(void) |
1468 | 1487 | goto theend; |
1469 | 1488 | } |
1470 | 1489 | } |
| 1490 | +# ifdef _WIN32 |
| 1491 | + if (!enc_utf8 && has_mbyte && c >= 0x80) |
| 1492 | + { |
| 1493 | + WCHAR wc; |
| 1494 | + char_u mb[3]; |
| 1495 | + |
| 1496 | + mb[0] = (unsigned)c >> 8; |
| 1497 | + mb[1] = c; |
| 1498 | + if (MultiByteToWideChar(GetACP(), 0, (char*)mb, 2, &wc, 1) > 0) |
| 1499 | + c = wc; |
| 1500 | + } |
| 1501 | +# endif |
1471 | 1502 | if (send_keys_to_term(curbuf->b_term, c, TRUE) != OK) |
1472 | 1503 | { |
1473 | 1504 | ret = OK; |
@@ -1627,7 +1658,7 @@ color2index(VTermColor *color, int fg, int *boldp) |
1627 | 1658 |
|
1628 | 1659 | /* 216-color cube */ |
1629 | 1660 | return 17 + ((red + 25) / 0x33) * 36 |
1630 | | - + ((green + 25) / 0x33) * 6 |
| 1661 | + + ((green + 25) / 0x33) * 6 |
1631 | 1662 | + (blue + 25) / 0x33; |
1632 | 1663 | } |
1633 | 1664 | return 0; |
@@ -2076,32 +2107,52 @@ term_update_window(win_T *wp) |
2076 | 2107 | else |
2077 | 2108 | { |
2078 | 2109 | #if defined(FEAT_MBYTE) |
2079 | | - if (enc_utf8 && c >= 0x80) |
| 2110 | + if (enc_utf8) |
2080 | 2111 | { |
2081 | | - ScreenLines[off] = ' '; |
2082 | | - ScreenLinesUC[off] = c; |
| 2112 | + if (c >= 0x80) |
| 2113 | + { |
| 2114 | + ScreenLines[off] = ' '; |
| 2115 | + ScreenLinesUC[off] = c; |
| 2116 | + } |
| 2117 | + else |
| 2118 | + { |
| 2119 | + ScreenLines[off] = c; |
| 2120 | + ScreenLinesUC[off] = NUL; |
| 2121 | + } |
2083 | 2122 | } |
2084 | | - else |
| 2123 | +# ifdef _WIN32 |
| 2124 | + else if (has_mbyte && c >= 0x80) |
2085 | 2125 | { |
2086 | | - ScreenLines[off] = c; |
2087 | | - if (enc_utf8) |
2088 | | - ScreenLinesUC[off] = NUL; |
| 2126 | + char_u mb[MB_MAXBYTES+1]; |
| 2127 | + WCHAR wc = c; |
| 2128 | + |
| 2129 | + if (WideCharToMultiByte(GetACP(), 0, &wc, 1, |
| 2130 | + (char*)mb, 2, 0, 0) > 1) |
| 2131 | + { |
| 2132 | + ScreenLines[off] = mb[0]; |
| 2133 | + ScreenLines[off+1] = mb[1]; |
| 2134 | + cell.width = mb_ptr2cells(mb); |
| 2135 | + } |
| 2136 | + else |
| 2137 | + ScreenLines[off] = c; |
2089 | 2138 | } |
2090 | | -#else |
2091 | | - ScreenLines[off] = c; |
| 2139 | +# endif |
| 2140 | + else |
2092 | 2141 | #endif |
| 2142 | + ScreenLines[off] = c; |
2093 | 2143 | } |
2094 | 2144 | ScreenAttrs[off] = cell2attr(cell.attrs, cell.fg, cell.bg); |
2095 | 2145 |
|
2096 | 2146 | ++pos.col; |
2097 | 2147 | ++off; |
2098 | 2148 | if (cell.width == 2) |
2099 | 2149 | { |
2100 | | - ScreenLines[off] = NUL; |
2101 | 2150 | #if defined(FEAT_MBYTE) |
2102 | 2151 | if (enc_utf8) |
2103 | 2152 | ScreenLinesUC[off] = NUL; |
| 2153 | + else if (!has_mbyte) |
2104 | 2154 | #endif |
| 2155 | + ScreenLines[off] = NUL; |
2105 | 2156 | ++pos.col; |
2106 | 2157 | ++off; |
2107 | 2158 | } |
|
0 commit comments