void textui_textblock_place(textblock *tb, region orig_area, const char *header) { const char *text = textblock_text(tb); const byte *attrs = textblock_attrs(tb); /* xxx on resize this should be recalculated */ region area = region_calculate(orig_area); size_t *line_starts = NULL, *line_lengths = NULL; size_t n_lines; n_lines = textblock_calculate_lines(tb, &line_starts, &line_lengths, area.width); area.page_rows--; if (n_lines > (size_t) area.page_rows) n_lines = area.page_rows; c_prt(TERM_L_BLUE, header, area.row, area.col); area.row++; display_area(text, attrs, line_starts, line_lengths, n_lines, area, 0); mem_free(line_starts); mem_free(line_lengths); }
void textblock_dump(textblock *tb, char_attr_line **line, int *current_line, int indent, int wrap) { const char *text = textblock_text(tb); const byte *attrs = textblock_attrs(tb); size_t *line_starts = NULL, *line_lengths = NULL; size_t i, j, n_lines; char_attr_line *lline = *line; n_lines = textblock_calculate_lines(tb, &line_starts, &line_lengths, wrap - indent); for (i = 0; i < n_lines; i++) { for (j = 0; j < line_lengths[i]; j++) { dump_put_str(attrs[line_starts[i] + j], format("%c",text[line_starts[i] + j]), j + indent); } (*current_line)++; dump_ptr = (char_attr *) &lline[*current_line]; } if (!n_lines) (*current_line)--; }
void textui_textblock_show(textblock *tb, region orig_area, const char *header) { const char *text = textblock_text(tb); const byte *attrs = textblock_attrs(tb); /* xxx on resize this should be recalculated */ region area = region_calculate(orig_area); size_t *line_starts = NULL, *line_lengths = NULL; size_t n_lines; n_lines = textblock_calculate_lines(tb, &line_starts, &line_lengths, area.width); screen_save(); /* make room for the header & footer */ area.page_rows -= 3; c_prt(TERM_L_BLUE, header, area.row, area.col); area.row++; if (n_lines > (size_t) area.page_rows) { int start_line = 0; c_prt(TERM_WHITE, "", area.row + area.page_rows, area.col); c_prt(TERM_L_BLUE, "(Up/down or ESCAPE to exit.)", area.row + area.page_rows + 1, area.col); /* Pager mode */ while (1) { struct keypress ch; display_area(text, attrs, line_starts, line_lengths, n_lines, area, start_line); ch = inkey(); if (ch.code == ARROW_UP) start_line--; else if (ch.code== ESCAPE || ch.code == 'q') break; else if (ch.code == ARROW_DOWN) start_line++; else if (ch.code == ' ') start_line += area.page_rows; if (start_line < 0) start_line = 0; if (start_line + (size_t) area.page_rows > n_lines) start_line = n_lines - area.page_rows; } } else { display_area(text, attrs, line_starts, line_lengths, n_lines, area, 0); c_prt(TERM_WHITE, "", area.row + n_lines, area.col); c_prt(TERM_L_BLUE, "(Press any key to continue.)", area.row + n_lines + 1, area.col); inkey(); } mem_free(line_starts); mem_free(line_lengths); screen_load(); return; }