diff --git a/src/channel.c b/src/channel.c index 6208d4dc27..d952e5bb6e 100644 --- a/src/channel.c +++ b/src/channel.c @@ -140,7 +140,7 @@ ch_log_active(void) } static void -ch_log_lead(char *what, channel_T *ch) +ch_log_lead(const char *what, channel_T *ch) { if (log_fd != NULL) { @@ -1834,12 +1834,11 @@ channel_save(channel_T *channel, ch_part_T part, char_u *buf, int len, head->rq_prev = node; } - if (log_fd != NULL && lead != NULL) + if (ch_log_active() && lead != NULL) { ch_log_lead(lead, channel); fprintf(log_fd, "'"); - if (fwrite(buf, len, 1, log_fd) != 1) - return FAIL; + ignored = (int)fwrite(buf, len, 1, log_fd); fprintf(log_fd, "'\n"); } return OK; @@ -3410,7 +3409,7 @@ channel_read_block(channel_T *channel, ch_part_T part, int timeout) channel_consume(channel, part, (int)(nl - buf) + 1); } } - if (log_fd != NULL) + if (ch_log_active()) ch_log(channel, "Returning %d bytes", (int)STRLEN(msg)); return msg; } @@ -3695,7 +3694,7 @@ channel_send( return FAIL; } - if (log_fd != NULL) + if (ch_log_active()) { ch_log_lead("SEND ", channel); fprintf(log_fd, "'"); diff --git a/src/mbyte.c b/src/mbyte.c index fb28789306..0fd15e7324 100644 --- a/src/mbyte.c +++ b/src/mbyte.c @@ -4907,19 +4907,92 @@ im_preedit_window_set_position(void) im_preedit_window_open() { char *preedit_string; +#if !GTK_CHECK_VERSION(3,16,0) char buf[8]; +#endif PangoAttrList *attr_list; PangoLayout *layout; +#if GTK_CHECK_VERSION(3,0,0) +# if !GTK_CHECK_VERSION(3,16,0) + GdkRGBA color; +# endif +#else GdkColor color; +#endif gint w, h; if (preedit_window == NULL) { preedit_window = gtk_window_new(GTK_WINDOW_POPUP); + gtk_window_set_transient_for(GTK_WINDOW(preedit_window), + GTK_WINDOW(gui.mainwin)); preedit_label = gtk_label_new(""); + gtk_widget_set_name(preedit_label, "vim-gui-preedit-area"); gtk_container_add(GTK_CONTAINER(preedit_window), preedit_label); } +#if GTK_CHECK_VERSION(3,16,0) + { + GtkStyleContext * const context + = gtk_widget_get_style_context(gui.drawarea); + GtkCssProvider * const provider = gtk_css_provider_new(); + gchar *css = NULL; + const char * const fontname + = pango_font_description_get_family(gui.norm_font); + gint fontsize + = pango_font_description_get_size(gui.norm_font) / PANGO_SCALE; + gchar *fontsize_propval = NULL; + + if (!pango_font_description_get_size_is_absolute(gui.norm_font)) + { + /* fontsize was given in points. Convert it into that in pixels + * to use with CSS. */ + GdkScreen * const screen + = gdk_window_get_screen(gtk_widget_get_window(gui.mainwin)); + const gdouble dpi = gdk_screen_get_resolution(screen); + fontsize = dpi * fontsize / 72; + } + if (fontsize > 0) + fontsize_propval = g_strdup_printf("%dpx", fontsize); + else + fontsize_propval = g_strdup_printf("inherit"); + + css = g_strdup_printf( + "widget#vim-gui-preedit-area {\n" + " font-family: %s,monospace;\n" + " font-size: %s;\n" + " color: #%.2lx%.2lx%.2lx;\n" + " background-color: #%.2lx%.2lx%.2lx;\n" + "}\n", + fontname != NULL ? fontname : "inherit", + fontsize_propval, + (gui.norm_pixel >> 16) & 0xff, + (gui.norm_pixel >> 8) & 0xff, + gui.norm_pixel & 0xff, + (gui.back_pixel >> 16) & 0xff, + (gui.back_pixel >> 8) & 0xff, + gui.back_pixel & 0xff); + + gtk_css_provider_load_from_data(provider, css, -1, NULL); + gtk_style_context_add_provider(context, + GTK_STYLE_PROVIDER(provider), G_MAXUINT); + + g_free(css); + g_free(fontsize_propval); + g_object_unref(provider); + } +#elif GTK_CHECK_VERSION(3,0,0) + gtk_widget_override_font(preedit_label, gui.norm_font); + + vim_snprintf(buf, sizeof(buf), "#%06X", gui.norm_pixel); + gdk_rgba_parse(&color, buf); + gtk_widget_override_color(preedit_label, GTK_STATE_FLAG_NORMAL, &color); + + vim_snprintf(buf, sizeof(buf), "#%06X", gui.back_pixel); + gdk_rgba_parse(&color, buf); + gtk_widget_override_background_color(preedit_label, GTK_STATE_FLAG_NORMAL, + &color); +#else gtk_widget_modify_font(preedit_label, gui.norm_font); vim_snprintf(buf, sizeof(buf), "#%06X", gui.norm_pixel); @@ -4929,6 +5002,7 @@ im_preedit_window_open() vim_snprintf(buf, sizeof(buf), "#%06X", gui.back_pixel); gdk_color_parse(buf, &color); gtk_widget_modify_bg(preedit_window, GTK_STATE_NORMAL, &color); +#endif gtk_im_context_get_preedit_string(xic, &preedit_string, &attr_list, NULL); diff --git a/src/proto/screen.pro b/src/proto/screen.pro index b40e0dadca..39424b485b 100644 --- a/src/proto/screen.pro +++ b/src/proto/screen.pro @@ -10,7 +10,7 @@ int redraw_asap(int type); void redraw_after_callback(int call_update_screen); void redrawWinline(linenr_T lnum, int invalid); void update_curbuf(int type); -void update_screen(int type_arg); +int update_screen(int type_arg); int conceal_cursor_line(win_T *wp); void conceal_check_cursur_line(void); void update_single_line(win_T *wp, linenr_T lnum); diff --git a/src/proto/syntax.pro b/src/proto/syntax.pro index 7247c5174f..0f64ceaf8c 100644 --- a/src/proto/syntax.pro +++ b/src/proto/syntax.pro @@ -52,6 +52,7 @@ int syn_namen2id(char_u *linep, int len); int syn_check_group(char_u *pp, int len); int syn_id2attr(int hl_id); int syn_id2colors(int hl_id, guicolor_T *fgp, guicolor_T *bgp); +void syn_id2cterm_bg(int hl_id, int *fgp, int *bgp); int syn_get_final_id(int hl_id); void highlight_gui_started(void); int highlight_changed(void); diff --git a/src/screen.c b/src/screen.c index 26d064a2d7..451ced7be0 100644 --- a/src/screen.c +++ b/src/screen.c @@ -538,8 +538,9 @@ update_curbuf(int type) /* * Based on the current value of curwin->w_topline, transfer a screenfull * of stuff from Filemem to ScreenLines[], and update curwin->w_botline. + * Return OK when the screen was updated, FAIL if it was not done. */ - void + int update_screen(int type_arg) { int type = type_arg; @@ -557,7 +558,7 @@ update_screen(int type_arg) /* Don't do anything if the screen structures are (not yet) valid. */ if (!screen_valid(TRUE)) - return; + return FAIL; if (type == VALID_NO_UPDATE) { @@ -589,7 +590,7 @@ update_screen(int type_arg) must_redraw = type; if (type > INVERTED_ALL) curwin->w_lines_valid = 0; /* don't use w_lines[].wl_size now */ - return; + return FAIL; } updating_screen = TRUE; @@ -842,6 +843,7 @@ update_screen(int type_arg) gui_update_scrollbars(FALSE); } #endif + return OK; } #if defined(FEAT_SIGNS) || defined(FEAT_GUI) || defined(FEAT_CONCEAL) diff --git a/src/syntax.c b/src/syntax.c index a55daae8de..681026403b 100644 --- a/src/syntax.c +++ b/src/syntax.c @@ -9710,7 +9710,7 @@ syn_id2attr(int hl_id) return attr; } -#ifdef FEAT_GUI +#if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) || defined(PROTO) /* * Get the GUI colors and attributes for a group ID. * NOTE: the colors will be INVALCOLOR when not set, the color otherwise. @@ -9729,6 +9729,19 @@ syn_id2colors(int hl_id, guicolor_T *fgp, guicolor_T *bgp) } #endif +#if defined(FEAT_TERMINAL) || defined(PROT) + void +syn_id2cterm_bg(int hl_id, int *fgp, int *bgp) +{ + struct hl_group *sgp; + + hl_id = syn_get_final_id(hl_id); + sgp = &HL_TABLE()[hl_id - 1]; /* index is ID minus one */ + *fgp = sgp->sg_cterm_fg - 1; + *bgp = sgp->sg_cterm_bg - 1; +} +#endif + /* * Translate a group ID to the final group ID (following links). */ diff --git a/src/terminal.c b/src/terminal.c index 969cfa4362..59ab4ed7fe 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -38,9 +38,10 @@ * in tl_scrollback are no longer used. * * TODO: - * - patch to use GUI or cterm colors for vterm. Yasuhiro, #2067 * - patch to add tmap, jakalope (Jacob Askeland) #2073 - * - Redirecting output does not work on MS-Windows. + * - Redirecting output does not work on MS-Windows, Test_terminal_redir_file() + * is disabled. + * - test_terminal_no_cmd hangs (Christian) * - implement term_setsize() * - add test for giving error for invalid 'termsize' value. * - support minimal size when 'termsize' is "rows*cols". @@ -1548,7 +1549,8 @@ terminal_loop(void) /* TODO: skip screen update when handling a sequence of keys. */ /* Repeat redrawing in case a message is received while redrawing. */ while (curwin->w_redr_type != 0) - update_screen(0); + if (update_screen(0) == FAIL) + break; update_cursor(curbuf->b_term, FALSE); c = term_vgetc(); @@ -1741,7 +1743,7 @@ color2index(VTermColor *color, int fg, int *boldp) else if (red == 128) { if (green == 128 && blue == 128) - return lookup_color(12, fg, boldp) + 1; /* high intensity black / dark grey */ + return lookup_color(12, fg, boldp) + 1; /* dark grey */ } else if (red == 255) { @@ -2387,6 +2389,65 @@ term_get_attr(buf_T *buf, linenr_T lnum, int col) return cell2attr(cellattr->attrs, cellattr->fg, cellattr->bg); } +static VTermColor ansi_table[16] = { + { 0, 0, 0}, /* black */ + {224, 0, 0}, /* dark red */ + { 0, 224, 0}, /* dark green */ + {224, 224, 0}, /* dark yellow / brown */ + { 0, 0, 224}, /* dark blue */ + {224, 0, 224}, /* dark magenta */ + { 0, 224, 224}, /* dark cyan */ + {224, 224, 224}, /* light grey */ + + {128, 128, 128}, /* dark grey */ + {255, 64, 64}, /* light red */ + { 64, 255, 64}, /* light green */ + {255, 255, 64}, /* yellow */ + { 64, 64, 255}, /* light blue */ + {255, 64, 255}, /* light magenta */ + { 64, 255, 255}, /* light cyan */ + {255, 255, 255}, /* white */ +}; + +static int cube_value[] = { + 0x00, 0x33, 0x66, 0x99, 0xCC, 0xFF, +}; + +static int grey_ramp[] = { + 0x00, 0x0B, 0x16, 0x21, 0x2C, 0x37, 0x42, 0x4D, 0x58, 0x63, 0x6E, 0x79, + 0x85, 0x90, 0x9B, 0xA6, 0xB1, 0xBC, 0xC7, 0xD2, 0xDD, 0xE8, 0xF3, 0xFF, +}; + +/* + * Convert a cterm color number 0 - 255 to RGB. + */ + static void +cterm_color2rgb(int nr, VTermColor *rgb) +{ + int idx; + + if (nr < 16) + { + *rgb = ansi_table[nr]; + } + else if (nr < 232) + { + /* 216 color cube */ + idx = nr - 16; + rgb->blue = cube_value[idx % 6]; + rgb->green = cube_value[idx / 6 % 6]; + rgb->red = cube_value[idx / 36 % 6]; + } + else if (nr < 256) + { + /* 24 grey scale ramp */ + idx = nr - 232; + rgb->blue = grey_ramp[nr]; + rgb->green = grey_ramp[nr]; + rgb->red = grey_ramp[nr]; + } +} + /* * Create a new vterm and initialize it. */ @@ -2398,6 +2459,7 @@ create_vterm(term_T *term, int rows, int cols) VTermValue value; VTermColor *fg, *bg; int fgval, bgval; + int id; vterm = vterm_new(rows, cols); term->tl_vterm = vterm; @@ -2406,12 +2468,13 @@ create_vterm(term_T *term, int rows, int cols) /* TODO: depends on 'encoding'. */ vterm_set_utf8(vterm, 1); - /* Vterm uses a default black background. Set it to white when - * 'background' is "light". */ vim_memset(&term->tl_default_color.attrs, 0, sizeof(VTermScreenCellAttrs)); term->tl_default_color.width = 1; fg = &term->tl_default_color.fg; bg = &term->tl_default_color.bg; + + /* Vterm uses a default black background. Set it to white when + * 'background' is "light". */ if (*p_bg == 'l') { fgval = 0; @@ -2424,6 +2487,76 @@ create_vterm(term_T *term, int rows, int cols) } fg->red = fg->green = fg->blue = fgval; bg->red = bg->green = bg->blue = bgval; + + /* The "Terminal" highlight group overrules the defaults. */ + id = syn_name2id((char_u *)"Terminal"); + + /* Use the actual color for the GUI and when 'guitermcolors' is set. */ +#if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) + if (0 +# ifdef FEAT_GUI + || gui.in_use +# endif +# ifdef FEAT_TERMGUICOLORS + || p_tgc +# endif + ) + { + guicolor_T fg_rgb, bg_rgb; + + if (id != 0) + syn_id2colors(id, &fg_rgb, &bg_rgb); + +# ifdef FEAT_GUI + if (gui.in_use) + { + if (fg_rgb == INVALCOLOR) + fg_rgb = gui.norm_pixel; + if (bg_rgb == INVALCOLOR) + bg_rgb = gui.back_pixel; + } +# ifdef FEAT_TERMGUICOLORS + else +# endif +# endif +# ifdef FEAT_TERMGUICOLORS + { + if (fg_rgb == INVALCOLOR) + fg_rgb = cterm_normal_fg_gui_color; + if (bg_rgb == INVALCOLOR) + bg_rgb = cterm_normal_bg_gui_color; + } +# endif + if (fg_rgb != INVALCOLOR) + { + long_u rgb = GUI_MCH_GET_RGB(fg_rgb); + + fg->red = (unsigned)(rgb >> 16); + fg->green = (unsigned)(rgb >> 8) & 255; + fg->blue = (unsigned)rgb & 255; + } + if (bg_rgb != INVALCOLOR) + { + long_u rgb = GUI_MCH_GET_RGB(bg_rgb); + + bg->red = (unsigned)(rgb >> 16); + bg->green = (unsigned)(rgb >> 8) & 255; + bg->blue = (unsigned)rgb & 255; + } + } + else +#endif + if (id != 0 && t_colors >= 16) + { + int cterm_fg, cterm_bg; + + syn_id2cterm_bg(id, &cterm_fg, &cterm_bg); + if (cterm_fg >= 0) + cterm_color2rgb(cterm_fg, fg); + if (cterm_bg >= 0) + cterm_color2rgb(cterm_bg, bg); + } + vterm_state_set_default_colors(vterm_obtain_state(vterm), fg, bg); /* Required to initialize most things. */ diff --git a/src/version.c b/src/version.c index d582666e7d..618174490a 100644 --- a/src/version.c +++ b/src/version.c @@ -784,6 +784,14 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1102, +/**/ + 1101, +/**/ + 1100, +/**/ + 1099, /**/ 1098, /**/