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); }
/* Displays contents read from the fp in the other pane starting from the second * line and second column. The wrapped parameter determines whether lines * should be wrapped. */ static void view_file(FILE *fp, int wrapped) { const size_t max_width = other_view->window_width - 1; const size_t max_y = other_view->window_rows - 1; const col_scheme_t *cs = ui_view_get_cs(other_view); char line[PREVIEW_LINE_BUF_LEN]; int line_continued = 0; int y = LINE; const char *res = get_line(fp, line, sizeof(line)); esc_state state; esc_state_init(&state, &cs->color[WIN_COLOR]); while(res != NULL && y <= max_y) { int offset; int printed; const size_t len = add_to_line(fp, max_width, line, sizeof(line)); if(!wrapped && line[len - 1] != '\n') { skip_until_eol(fp); } offset = esc_print_line(line, other_view->win, COL, y, max_width, 0, &state, &printed); y += !wrapped || (!line_continued || printed); line_continued = line[len - 1] != '\n'; if(!wrapped || shift_line(line, len, offset)) { res = get_line(fp, line, sizeof(line)); } } }