From 80b6ca1582ab1124a5c4833ee7d594088069ee71 Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Fri, 17 Mar 2017 21:18:59 +1000 Subject: [PATCH] Fix for cursor position on mail listings --- email.c | 19 +++++++++++-------- mail_menu.c | 13 ++++++++----- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/email.c b/email.c index 45dcf27..a1cb83d 100644 --- a/email.c +++ b/email.c @@ -199,7 +199,7 @@ void show_email(struct user_record *user, int msgno, int email_count, struct ema } s_printf(get_string(187)); s_printf(get_string(191)); - c = s_getc(); + c = s_getchar(); if (tolower(c) == 'r') { should_break = 1; @@ -209,9 +209,9 @@ void show_email(struct user_record *user, int msgno, int email_count, struct ema } else if (tolower(c) == 'd') { should_break = 1; } else if (c == '\e') { - c = s_getc(); + c = s_getchar(); if (c == 91) { - c = s_getc(); + c = s_getchar(); if (c == 65) { position--; if (position < 0) { @@ -439,15 +439,16 @@ void list_emails(struct user_record *user) { } } s_printf(get_string(190)); + s_printf("\e[%d;5H", position - start + 2); redraw = 0; } - c = s_getc(); + c = s_getchar(); if (tolower(c) == 'q') { closed = 1; } else if (c == 27) { - c = s_getc(); + c = s_getchar(); if (c == 91) { - c = s_getc(); + c = s_getchar(); if (c == 66) { // down position++; @@ -460,6 +461,7 @@ void list_emails(struct user_record *user) { } if (position == email_count) { position--; + s_printf("\e[%d;5H", position - start + 2); } else if (!redraw) { s_printf("\e[%d;1H", position - start + 1); localtime_r((time_t *)&emails[position-1]->date, &msg_date); @@ -474,7 +476,8 @@ void list_emails(struct user_record *user) { s_printf(get_string(192), position + 1, emails[position]->subject, emails[position]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); } else { s_printf(get_string(193), position + 1, emails[position]->subject, emails[position]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); - } + } + s_printf("\e[%d;5H", position - start + 2); } } else if (c == 65) { // up @@ -505,7 +508,7 @@ void list_emails(struct user_record *user) { } else { s_printf(get_string(193), position + 1, emails[position]->subject, emails[position]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); } - + s_printf("\e[%d;5H", position - start + 3); } } } diff --git a/mail_menu.c b/mail_menu.c index 82b7efc..0614c88 100644 --- a/mail_menu.c +++ b/mail_menu.c @@ -2315,15 +2315,16 @@ int mail_menu(struct user_record *user) { } } s_printf(get_string(190)); + s_printf("\e[%d;5H", i - start + 1); redraw = 0; } - c = s_getc(); + c = s_getchar(); if (tolower(c) == 'q') { closed = 1; } else if (c == 27) { - c = s_getc(); + c = s_getchar(); if (c == 91) { - c = s_getc(); + c = s_getchar(); if (c == 66) { // down i++; @@ -2336,6 +2337,7 @@ int mail_menu(struct user_record *user) { } if (i-1 == msghs->msg_count) { i--; + s_printf("\e[%d;5H", i - start + 1); } else if (!redraw) { s_printf("\e[%d;1H", i - start); localtime_r((time_t *)&msghs->msgs[i-2]->msg_h->DateWritten, &msg_date); @@ -2351,7 +2353,7 @@ int mail_menu(struct user_record *user) { } else { s_printf(get_string(189), i, msghs->msgs[i-1]->subject, msghs->msgs[i-1]->from, msghs->msgs[i-1]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); } - + s_printf("\e[%d;5H", i - start + 1); } } else if (c == 65) { // up @@ -2381,7 +2383,8 @@ int mail_menu(struct user_record *user) { s_printf(get_string(188), i, msghs->msgs[i-1]->subject, msghs->msgs[i-1]->from, msghs->msgs[i-1]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); } else { s_printf(get_string(189), i, msghs->msgs[i-1]->subject, msghs->msgs[i-1]->from, msghs->msgs[i-1]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); - } + } + s_printf("\e[%d;5H", i - start + 1); } }