Joey Hess wrote: > The attached patch is a better approach, it looks for screen clear > sequences and displays the last screen full of data for context when > peeking.
Er, here's the patch. -- see shy jo
diff --git a/ttyplay.c b/ttyplay.c
index 787dfa9..a9b4f6f 100644
--- a/ttyplay.c
+++ b/ttyplay.c
@@ -213,12 +213,56 @@ ttyplay (FILE *fp, double speed, ReadFunc read_func,
}
void
-ttyskipall (FILE *fp)
+ttyskipuntillastscreen (FILE *fp)
{
/*
- * Skip all records.
+ * Skip all records until the first one that contains text shown on the
+ * current screen. This is done by looking for the last record to
+ * contain a clrscr escape sequence.
*/
- ttyplay(fp, 0, ttyread, ttynowrite, ttynowait);
+ char *clrstrs[]={
+ "\e[H\e[J", /* vt100 and compatible (linux console, screen) */
+ "\e[H\e[2J", /* vt300, xterm, rxvt */
+ NULL,
+ };
+
+ long last_screen_record=ftell(fp);
+ if (last_screen_record == -1)
+ return; /* not a seekable file */
+
+ setbuf(fp, NULL);
+
+ while (1) {
+ char *buf;
+ Header h;
+ int i;
+ long current_record=ftell(fp);
+
+ if (ttyread(fp, &h, &buf) == 0) {
+ break;
+ }
+ for (i=0; clrstrs[i]; i++) {
+ char *pos=buf;
+ while ((pos=memchr(pos, clrstrs[i][0], h.len - (pos - buf))) != NULL) {
+ int j;
+ for (j=1; clrstrs[i][j] != '\0'; j++) {
+ if (h.len - (pos - buf) - j < 1 ||
+ pos[j] != clrstrs[i][j]) {
+ goto NEXT;
+ }
+ }
+ last_screen_record=current_record;
+ break;
+
+NEXT: pos++;
+ if (h.len - (pos - buf) < 1)
+ break;
+ }
+ }
+ free(buf);
+ }
+
+ fseek(fp, last_screen_record, SEEK_SET);
}
void ttyplayback (FILE *fp, double speed,
@@ -230,7 +274,7 @@ void ttyplayback (FILE *fp, double speed,
void ttypeek (FILE *fp, double speed,
ReadFunc read_func, WaitFunc wait_func)
{
- ttyskipall(fp);
+ ttyskipuntillastscreen(fp);
ttyplay(fp, speed, ttypread, ttywrite, ttynowait);
}
signature.asc
Description: Digital signature

