/* Dump character history to a file, which we assume is already open. */ void dump_history(ang_file *file) { size_t i; char buf[90]; /* We use either ascii or system-specific encoding */ int encoding = OPT(xchars_to_file) ? SYSTEM_SPECIFIC : ASCII; file_putf(file, "============================================================\n"); file_putf(file, " CHAR.\n"); file_putf(file, "| TURN | DEPTH |LEVEL| EVENT\n"); file_putf(file, "============================================================\n"); for (i = 0; i < (last_printable_item() + 1); i++) { /* Skip not-yet-IDd artifacts */ if (history_masked(i)) continue; strnfmt(buf, sizeof(buf), "%10d%7d\'%5d %s", history_list[i].turn, history_list[i].dlev * 50, history_list[i].clev, history_list[i].event); if (history_list[i].type & HISTORY_ARTIFACT_LOST) my_strcat(buf, " (LOST)", sizeof(buf)); x_file_putf(file, encoding, "%s", buf); file_put(file, "\n"); } return; }
/* Handles all of the display functionality for the history list. */ void history_display(void) { int row, wid, hgt, page_size; char buf[90]; static size_t first_item = 0; size_t max_item = last_printable_item(); size_t i; Term_get_size(&wid, &hgt); /* Six lines provide space for the header and footer */ page_size = hgt - 6; screen_save(); while (1) { char ch; Term_clear(); /* Print everything to screen */ print_history_header(); row = 0; for (i = first_item; row <= page_size && i < history_ctr; i++) { /* Skip messages about artifacts not yet IDed. */ if (history_masked(i)) continue; strnfmt(buf, sizeof(buf), "%10d%7d\'%5d %s", history_list[i].turn, history_list[i].dlev * 50, history_list[i].clev, history_list[i].event); if (history_list[i].type & HISTORY_ARTIFACT_LOST) my_strcat(buf, " (LOST)", sizeof(buf)); /* Size of header = 5 lines */ prt(buf, row + 5, 0); row++; } prt("[Arrow keys scroll, p for previous page, n for next page, ESC to exit.]", hgt - 1, 0); ch = inkey(); if (ch == 'n') { size_t scroll_to = first_item + page_size; while (history_masked(scroll_to) && scroll_to < history_ctr - 1) scroll_to++; first_item = (scroll_to < max_item ? scroll_to : max_item); } else if (ch == 'p') { int scroll_to = first_item - page_size; while (history_masked(scroll_to) && scroll_to > 0) scroll_to--; first_item = (scroll_to >= 0 ? scroll_to : 0); } else if (ch == ARROW_DOWN) { size_t scroll_to = first_item + 1; while (history_masked(scroll_to) && scroll_to < history_ctr - 1) scroll_to++; first_item = (scroll_to < max_item ? scroll_to : max_item); } else if (ch == ARROW_UP) { int scroll_to = first_item - 1; while (history_masked(scroll_to) && scroll_to > 0) scroll_to--; first_item = (scroll_to >= 0 ? scroll_to : 0); } else if (ch == ESCAPE) break; } screen_load(); return; }
/* Dump character history to a file, which we assume is already open. */ void dump_history(char_attr_line *line, int *curr_line, bool *dead) { size_t i; char buf[90]; /* Dump notes */ for (i = 0; i < (last_printable_item() + 1); i++) { int length, length_info; char info_note[43]; char place[32]; byte attr = history_colour(history_list[i].type); /* Skip not-yet-IDd artifacts */ if (history_masked(i)) continue; /* Divider before death */ if ((history_list[i].type & HISTORY_PLAYER_DEATH) && !(*dead)) { *dead = TRUE; dump_put_str(TERM_WHITE, "============================================================", 0); (*curr_line)++; dump_ptr = (char_attr *) & line[*curr_line]; } /* Get the note */ strnfmt(buf, sizeof(buf), "%s", history_list[i].event); if (history_list[i].type & HISTORY_ARTIFACT_LOST) my_strcat(buf, " (LOST)", sizeof(buf)); /* Get the location name */ history_get_place(place, sizeof(place), i); /* Make preliminary part of note */ strnfmt(info_note, sizeof(info_note), "%10d%22s%5d ", history_list[i].turn, place, history_list[i].clev); /* Write the info note */ dump_put_str(TERM_WHITE, info_note, 0); /* Get the length of the history_list */ length_info = strlen(info_note); length = strlen(buf); /* Break up long notes */ if ((length + length_info) > LINEWRAP) { bool keep_going = TRUE; int startpoint = 0; int endpoint, n; while (keep_going) { /* Don't print more than the set linewrap amount */ endpoint = startpoint + LINEWRAP - strlen(info_note) + 1; /* Find a breaking point */ while (TRUE) { /* Are we at the end of the line? */ if (endpoint >= length) { /* Print to the end */ endpoint = length; keep_going = FALSE; break; } /* Mark the most recent space or dash in the string */ else if ((buf[endpoint] == ' ') || (buf[endpoint] == '-')) break; /* No spaces in the line, so break in the middle of text */ else if (endpoint == startpoint) { endpoint = startpoint + LINEWRAP - strlen(info_note) + 1; break; } /* check previous char */ endpoint--; } /* Make a continued note if applicable */ if (startpoint) dump_put_str(TERM_WHITE, " continued... ", 0); /* Write that line */ for (n = startpoint; n <= endpoint; n++) { char ch; char buf1[5]; /* Ensure the character is printable */ ch = (isprint(buf[n]) ? buf[n] : ' '); /* Write out the character */ sprintf(buf1, "%c", ch); dump_put_str(attr, buf1, strlen(info_note) + n - startpoint); } /* Break the line */ (*curr_line)++; dump_ptr = (char_attr *) & line[*curr_line]; /* Prepare for the next line */ startpoint = endpoint + 1; } } /* Add note to buffer */ else { /* Print the note */ dump_put_str(attr, buf, strlen(info_note)); /* Break the line */ (*curr_line)++; dump_ptr = (char_attr *) & line[*curr_line]; } } return; }