Better message reading using arrow keys.

This commit is contained in:
Andrew Pamment 2016-11-30 21:45:23 +10:00
parent e9b84728f8
commit 51e130db00
2 changed files with 124 additions and 88 deletions

View File

@ -184,3 +184,4 @@ Login Name:
\r\n-------------------------------------\r\n \r\n-------------------------------------\r\n
Is this Correct? (Y/N) Is this Correct? (Y/N)
\e[1;37mPress any key to continue...\e[0m \e[1;37mPress any key to continue...\e[0m
\e[24;1H\e[1;37;44mUp / Down to Scroll, Left / Right Change Message, R reply, Q quit\e[K\e[0m

View File

@ -765,7 +765,12 @@ void read_message(struct user_record *user, struct msg_headers *msghs, int mailn
int chars = 0; int chars = 0;
int ansi; int ansi;
int sem_fd; int sem_fd;
char **msg_lines;
int msg_line_count;
int start_line;
int should_break;
int position;
jb = open_jam_base(conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); jb = open_jam_base(conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path);
if (!jb) { if (!jb) {
dolog("Error opening JAM base.. %s", conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); dolog("Error opening JAM base.. %s", conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path);
@ -844,92 +849,104 @@ void read_message(struct user_record *user, struct msg_headers *msghs, int mailn
lines = 0; lines = 0;
chars = 0; chars = 0;
for (z=0;z<z2;z++) {
if (body[z] == '\r' || chars == 79) { msg_line_count = 0;
chars = 0; start_line = 0;
if (body[z] == '\r') {
s_printf("\r\n"); // count the number of lines...
} else { for (z=0;z<z2;z++) {
s_putchar(body[z]); if (body[z] == '\r' || chars == 79) {
} if (msg_line_count == 0) {
lines++; msg_lines = (char **)malloc(sizeof(char *));
if (lines >= 17) { } else {
s_printf(get_string(185)); msg_lines = (char **)realloc(msg_lines, sizeof(char *) * (msg_line_count + 1));
s_getc(); }
lines = 0;
s_printf("\e[7;1H\e[0J"); msg_lines[msg_line_count] = (char *)malloc(sizeof(char) * (z - start_line + 1));
}
} else if (body[z] == '\e' && body[z + 1] == '[') { if (z == start_line) {
ansi = z; msg_lines[msg_line_count][0] = '\0';
while (strchr("ABCDEFGHIGJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", body[z]) == NULL) } else {
z++; strncpy(msg_lines[msg_line_count], &body[start_line], z - start_line);
if (body[z] == 'm') { msg_lines[msg_line_count][z-start_line] = '\0';
strncpy(buffer, &body[ansi], (z - ansi) + 1); }
buffer[z - ansi + 1] = '\0'; msg_line_count++;
s_printf("%s", buffer); if (body[z] == '\r') {
} else if (body[z] == 'A') { start_line = z + 1;
j = atoi(&body[ansi + 2]); } else {
if (j == 0 && ansi + 2 == z) { start_line = z;
j = 1; }
} chars = 0;
for (i=0;i<j;i++) { } else {
if (lines - 1 >= 0) { if (body[z] == '\e') {
s_printf("\e[A"); ansi = z;
lines--; while (strchr("ABCDEFGHIGJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", body[z]) == NULL)
} else { z++;
break; if (body[z] == 'm') {
} // do nothing
} } else if (body[z] == 'C') {
} else if (body[z] == 'C') { chars += atoi(&body[ansi + 2]);
j = atoi(&body[ansi + 2]); } else {
if (j == 0 && ansi + 2 == z) { i = strlen(body);
j = 1; for (j=ansi;j<i;j++) {
} body[ansi++] = body[j];
for (i=0;i<j;i++) { }
if (chars + 1 <= 79) { }
s_printf("\e[C");
chars++; } else {
} else { chars ++;
break; }
} }
} }
} else if (body[z] == 'B') {
j = atoi(&body[ansi + 2]); lines = 0;
if (j == 0 && ansi + 2 == z) {
j = 1; position = 0;
} should_break = 0;
for (i=0;i<j;i++) {
if (lines + 1 < 17) { while (!should_break) {
s_printf("\e[B"); s_printf("\e[7;1H\e[0J");
lines++; for (z=position;z<msg_line_count;z++) {
} else {
break; s_printf("%s\e[K\r\n", msg_lines[z]);
}
} if (z - position >= 16) {
} else if (body[z] == 'D') { break;
j = atoi(&body[ansi + 2]); }
if (j == 0 && ansi + 2 == z) { }
j = 1; s_printf(get_string(186));
} c = s_getc();
for (i=0;i<j;i++) {
if (chars - 1 >= 0) { if (c == 'r') {
s_printf("\e[D"); should_break = 1;
chars--; } else if (c == 'q') {
} else { should_break = 1;
break; } else if (c == '\e') {
} c = s_getc();
} if (c == 91) {
} c = s_getc();
} else { if (c == 65) {
chars++; position--;
s_putchar(body[z]); if (position < 0) {
} position = 0;
} }
} else if (c == 66) {
s_printf(get_string(112)); position++;
if (position + 16 > msg_line_count) {
c = s_getc(); position--;
}
} else if (c == 67) {
c = ' ';
should_break = 1;
} else if (c == 68) {
c = 'b';
should_break = 1;
}
}
}
}
if (tolower(c) == 'r') { if (tolower(c) == 'r') {
JAM_CloseMB(jb); JAM_CloseMB(jb);
@ -1003,6 +1020,10 @@ void read_message(struct user_record *user, struct msg_headers *msghs, int mailn
free(subject); free(subject);
free(to); free(to);
free(from); free(from);
for (i=0;i<msg_line_count;i++) {
free(msg_lines[i]);
}
free(msg_lines);
return; return;
} }
@ -1172,6 +1193,10 @@ void read_message(struct user_record *user, struct msg_headers *msghs, int mailn
free(to); free(to);
free(from); free(from);
dolog("Failed to lock msg base!"); dolog("Failed to lock msg base!");
for (i=0;i<msg_line_count;i++) {
free(msg_lines[i]);
}
free(msg_lines);
return; return;
} }
} }
@ -1216,6 +1241,7 @@ void read_message(struct user_record *user, struct msg_headers *msghs, int mailn
} }
} else if (tolower(c) == 'q') { } else if (tolower(c) == 'q') {
free(body);
doquit = 1; doquit = 1;
} else if (c == ' ') { } else if (c == ' ') {
mailno++; mailno++;
@ -1223,11 +1249,20 @@ void read_message(struct user_record *user, struct msg_headers *msghs, int mailn
s_printf(get_string(118)); s_printf(get_string(118));
doquit = 1; doquit = 1;
} }
free(body);
} else if (tolower(c) == 'b') { } else if (tolower(c) == 'b') {
if (mailno > 0) { if (mailno > 0) {
mailno--; mailno--;
} }
} free(body);
} else {
free(body);
}
for (i=0;i<msg_line_count;i++) {
free(msg_lines[i]);
}
free(msg_lines);
msg_line_count = 0;
} }
} }