/* Picks window to use for suggestion box and prepares it for displaying data. * Sets *height to number of suggestions to display. Returns picked window. */ static WINDOW * prepare_suggestion_box(int *height) { WINDOW *win; const col_attr_t col = cfg.cs.color[SUGGEST_BOX_COLOR]; const int count = vle_compl_get_count(); if((cfg.sug.flags & SF_OTHERPANE) && curr_stats.number_of_windows == 2) { win = other_view->win; *height = MIN(count, getmaxy(win)); } else { const int max_height = getmaxy(stdscr) - getmaxy(status_bar) - ui_stat_job_bar_height() - 2; *height = MIN(count, max_height); wresize(stat_win, *height, getmaxx(stdscr)); ui_stat_reposition(getmaxy(status_bar), 1); win = stat_win; } /* Clear preview before displaying suggestion for the first time for specific * input if active preview needs special cleanup. */ if(!suggestions_are_visible && curr_stats.preview.on && curr_stats.preview.cleanup_cmd != NULL) { qv_cleanup(other_view, curr_stats.preview.cleanup_cmd); } ui_set_bg(win, &col, -1); werase(win); return win; }
static void draw(void) { int l, vl; const col_scheme_t *cs = ui_view_get_cs(vi->view); const int height = vi->view->window_rows - 1; const int width = vi->view->window_width - 1; const int max_l = MIN(vi->line + height, vi->nlines); const int searched = (vi->last_search_backward != -1); esc_state state; if(vi->graphics) { const char *cmd = gv_get_viewer(vi->filename); cmd = (cmd != NULL) ? ma_get_clean_cmd(cmd) : NULL; qv_cleanup(vi->view, cmd); free_string_array(vi->lines, vi->nlines); (void)get_view_data(vi, vi->filename); return; } esc_state_init(&state, &cs->color[WIN_COLOR]); ui_view_erase(vi->view); for(vl = 0, l = vi->line; l < max_l && vl < height; ++l) { int offset = 0; int t = 0; char *const line = vi->lines[l]; char *p = searched ? esc_highlight_pattern(line, &vi->re) : line; do { int printed; int vis = l != vi->line || vl + t >= vi->linev - vi->widths[vi->line][0]; offset += esc_print_line(p + offset, vi->view->win, COL, 1 + vl, width, !vis, &state, &printed); vl += vis; t++; } while(vi->wrap && p[offset] != '\0' && vl < height); if(searched) { free(p); } } refresh_view_win(vi->view); }