To: vim_dev@googlegroups.com Subject: Patch 7.4.770 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 7.4.770 (after 7.4.766) Problem: Background color response with transparency is not ignored. Solution: Change the way escape sequences are recognized. (partly by Hirohito Higashi) Files: src/ascii.h, src/term.c *** ../vim-7.4.769/src/ascii.h 2011-12-17 21:38:36.000000000 +0100 --- src/ascii.h 2015-07-10 12:02:02.379313390 +0200 *************** *** 34,43 **** #define ESC_STR_nc "\033" #define DEL 0x7f #define DEL_STR (char_u *)"\177" - #define CSI 0x9b /* Control Sequence Introducer */ - #define CSI_STR "\233" - #define DCS 0x90 /* Device Control String */ - #define STERM 0x9c /* String Terminator */ #define POUND 0xA3 --- 34,39 ---- *************** *** 117,127 **** #define ESC_STR_nc "\x27" #define DEL 0x07 #define DEL_STR (char_u *)"\007" - /* TODO: EBCDIC Code page dependent (here 1047) */ - #define CSI 0x9b /* Control Sequence Introducer */ - #define CSI_STR "\233" - #define DCS 0x90 /* Device Control String */ - #define STERM 0x9c /* String Terminator */ #define POUND 0xB1 --- 113,118 ---- *************** *** 173,178 **** --- 164,176 ---- #endif /* defined EBCDIC */ + /* TODO: EBCDIC Code page dependent (here 1047) */ + #define CSI 0x9b /* Control Sequence Introducer */ + #define CSI_STR "\233" + #define DCS 0x90 /* Device Control String */ + #define OSC 0x9d /* Operating System Command */ + #define STERM 0x9c /* String Terminator */ + /* * Character that separates dir names in a path. * For MS-DOS, WIN32 and OS/2 we use a backslash. A slash mostly works *** ../vim-7.4.769/src/term.c 2015-07-03 13:05:45.833974396 +0200 --- src/term.c 2015-07-10 13:53:28.744975532 +0200 *************** *** 2364,2370 **** if (p[1] == '[') return CSI; if (p[1] == ']') ! return 0x9d; if (p[1] == 'O') return 0x8f; } --- 2364,2370 ---- if (p[1] == '[') return CSI; if (p[1] == ']') ! return OSC; if (p[1] == 'O') return 0x8f; } *************** *** 4261,4278 **** * - Cursor position report: [{row};{col}R * The final byte must be 'R'. It is used for checking the * ambiguous-width character state. - * - * - Background color response: - * ]11;rgb:{rrrr}/{gggg}/{bbbb}\007 - * Or - * ]11;rgb:{rrrr}/{gggg}/{bbbb}ST - * The final byte must be '\007' or ST(0x9c or ESC\). */ ! char_u *argp = tp[0] == CSI ? tp + 1 : tp + 2; ! if ((*T_CRV != NUL || *T_U7 != NUL || *T_RBG != NUL) ! && ((tp[0] == ESC && tp[1] == '[' && len >= 3) ! || (tp[0] == ESC && tp[1] == ']' && len >= 24) || (tp[0] == CSI && len >= 2)) && (VIM_ISDIGIT(*argp) || *argp == '>' || *argp == '?')) { --- 4261,4271 ---- * - Cursor position report: [{row};{col}R * The final byte must be 'R'. It is used for checking the * ambiguous-width character state. */ ! char_u *argp = tp[0] == ESC ? tp + 2 : tp + 1; ! if ((*T_CRV != NUL || *T_U7 != NUL) ! && ((tp[0] == ESC && len >= 3 && tp[1] == '[') || (tp[0] == CSI && len >= 2)) && (VIM_ISDIGIT(*argp) || *argp == '>' || *argp == '?')) { *************** *** 4410,4453 **** key_name[1] = (int)KE_IGNORE; slen = i + 1; } ! else if (*T_RBG != NUL ! && len >= 24 - (tp[0] == CSI) ! && len >= 24 - (tp[0] == CSI) + (argp[21] == ESC) ! && argp[0] == '1' && argp[1] == '1' ! && argp[2] == ';' && argp[3] == 'r' && argp[4] == 'g' ! && argp[5] == 'b' && argp[6] == ':' ! && argp[11] == '/' && argp[16] == '/' ! && (argp[21] == '\007' || argp[21] == STERM ! || (argp[21] == ESC && argp[22] == '\\'))) ! { ! LOG_TR("Received RBG"); ! rbg_status = RBG_GOT; ! if (!option_was_set((char_u *)"bg")) { ! set_option_value((char_u *)"bg", 0L, (char_u *)( ! (3 * '6' < argp[7] + argp[12] + argp[17]) ! ? "light" : "dark"), 0); ! reset_option_was_set((char_u *)"bg"); ! redraw_asap(CLEAR); } ! key_name[0] = (int)KS_EXTRA; ! key_name[1] = (int)KE_IGNORE; ! slen = 24 - (tp[0] == CSI) + (argp[21] == ESC); } } ! /* Check for 'P1+r\'. A "0" instead of the ! * "1" means an invalid request. */ else if (check_for_codes ! && ((tp[0] == ESC && tp[1] == 'P' && len >= 2) || tp[0] == DCS)) { ! j = 1 + (tp[0] != DCS); ! for (i = j; i < len; ++i) ! if ((tp[i] == ESC && tp[i + 1] == '\\' && i + 1 < len) || tp[i] == STERM) { ! if (i - j >= 3 && tp[j + 1] == '+' && tp[j + 2] == 'r') got_code_from_term(tp + j, i); key_name[0] = (int)KS_EXTRA; key_name[1] = (int)KE_IGNORE; --- 4403,4482 ---- key_name[1] = (int)KE_IGNORE; slen = i + 1; } ! } ! ! /* Check for background color response from the terminal: ! * ! * {lead}11;rgb:{rrrr}/{gggg}/{bbbb}{tail} ! * ! * {lead} can be ] or OSC ! * {tail} can be '\007', \ or STERM. ! * ! * Consume any code that starts with "{lead}11;", it's also ! * possible that "rgba" is following. ! */ ! else if (*T_RBG != NUL ! && ((tp[0] == ESC && len >= 2 && tp[1] == ']') ! || tp[0] == OSC)) ! { ! j = 1 + (tp[0] == ESC); ! if (len >= j + 3 && (argp[0] != '1' ! || argp[1] != '1' || argp[2] != ';')) ! i = 0; /* no match */ ! else ! for (i = j; i < len; ++i) ! if (tp[i] == '\007' || (tp[0] == OSC ? tp[i] == STERM ! : (tp[i] == ESC && i + 1 < len && tp[i + 1] == '\\'))) { ! if (i - j >= 21 && STRNCMP(tp + j + 3, "rgb:", 4) == 0 ! && tp[j + 11] == '/' && tp[j + 16] == '/' ! && !option_was_set((char_u *)"bg")) ! {/* TODO: don't set option when already the right value */ ! LOG_TR("Received RBG"); ! rbg_status = RBG_GOT; ! set_option_value((char_u *)"bg", 0L, (char_u *)( ! (3 * '6' < tp[j+7] + tp[j+12] + tp[j+17]) ! ? "light" : "dark"), 0); ! reset_option_was_set((char_u *)"bg"); ! redraw_asap(CLEAR); ! } ! ! /* got finished code: consume it */ ! key_name[0] = (int)KS_EXTRA; ! key_name[1] = (int)KE_IGNORE; ! slen = i + 1 + (tp[i] == ESC); ! break; } ! if (i == len) ! { ! LOG_TR("not enough characters for RB"); ! return -1; } } ! /* Check for key code response from xterm: ! * ! * {lead}{flag}+r<{tail} ! * ! * {lead} can be P or DCS ! * {flag} can be '0' or '1' ! * {tail} can be Esc>\ or STERM ! * ! * Consume any code that starts with "{lead}.+r". ! */ else if (check_for_codes ! && ((tp[0] == ESC && len >= 2 && tp[1] == 'P') || tp[0] == DCS)) { ! j = 1 + (tp[0] == ESC); ! if (len >= j + 3 && (argp[1] != '+' || argp[2] != 'r')) ! i = 0; /* no match */ ! else ! for (i = j; i < len; ++i) ! if ((tp[i] == ESC && i + 1 < len && tp[i + 1] == '\\') || tp[i] == STERM) { ! if (i - j >= 3) got_code_from_term(tp + j, i); key_name[0] = (int)KS_EXTRA; key_name[1] = (int)KE_IGNORE; *************** *** 4457,4464 **** if (i == len) { LOG_TR("not enough characters for XT"); ! return -1; /* not enough characters */ } } } --- 4486,4495 ---- if (i == len) { + /* These codes arrive many together, each code can be + * truncated at any point. */ LOG_TR("not enough characters for XT"); ! return -1; } } } *** ../vim-7.4.769/src/version.c 2015-07-04 15:05:08.606736259 +0200 --- src/version.c 2015-07-10 12:04:22.282011343 +0200 *************** *** 743,744 **** --- 743,746 ---- { /* Add new patch number below this line */ + /**/ + 770, /**/ -- Some of the well known MS-Windows errors: ETIME Wrong time, wait a little while ECRASH Try again... EDETECT Unable to detect errors EOVER You lost! Play another game? ENOCLUE Eh, what did you want? /// Bram Moolenaar -- Bram@Moolenaar.net -- 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 ///