| 40 |
#define STR_TOP_MIDDLE_MAX_LEN 40 |
#define STR_TOP_MIDDLE_MAX_LEN 40 |
| 41 |
#define STR_TOP_RIGHT_MAX_LEN 80 |
#define STR_TOP_RIGHT_MAX_LEN 80 |
| 42 |
|
|
| 43 |
static const char *get_time_str(char *s, size_t len) |
static size_t get_time_str(char *s, size_t len) |
| 44 |
{ |
{ |
|
static const char *weekday[] = { |
|
|
"天", "一", "二", "三", "四", "五", "六"}; |
|
| 45 |
time_t curtime; |
time_t curtime; |
| 46 |
struct tm local_tm; |
struct tm local_tm; |
| 47 |
|
|
| 48 |
time(&curtime); |
time(&curtime); |
| 49 |
localtime_r(&curtime, &local_tm); |
localtime_r(&curtime, &local_tm); |
| 50 |
size_t j = strftime(s, len, "%b %d %H:%M 星期", &local_tm); |
size_t j = strftime(s, len, "%m/%d %H:%M %Z", &local_tm); |
| 51 |
|
|
| 52 |
if (j == 0 || j + strlen(weekday[local_tm.tm_wday]) + 1 > len) |
return j; |
|
{ |
|
|
return NULL; |
|
|
} |
|
|
|
|
|
strncat(s, weekday[local_tm.tm_wday], len - 1 - j); |
|
|
|
|
|
return s; |
|
| 53 |
} |
} |
| 54 |
|
|
| 55 |
void moveto(int row, int col) |
void moveto(int row, int col) |
| 707 |
output_end_row = SCREEN_ROWS - 1; // Legacy Fterm only works with this line |
output_end_row = SCREEN_ROWS - 1; // Legacy Fterm only works with this line |
| 708 |
break; |
break; |
| 709 |
case CR: |
case CR: |
|
case KEY_SPACE: |
|
| 710 |
case KEY_DOWN: |
case KEY_DOWN: |
| 711 |
if (line_current + (screen_row_total - (output_current_row - screen_begin_row)) >= display_line_total) // Reach end |
if (line_current + (screen_row_total - (output_current_row - screen_begin_row)) >= display_line_total) // Reach end |
| 712 |
{ |
{ |
| 734 |
output_end_row = SCREEN_ROWS - 1; |
output_end_row = SCREEN_ROWS - 1; |
| 735 |
clrline(output_current_row, SCREEN_ROWS); |
clrline(output_current_row, SCREEN_ROWS); |
| 736 |
break; |
break; |
| 737 |
|
case KEY_SPACE: |
| 738 |
case KEY_PGDN: |
case KEY_PGDN: |
| 739 |
if (line_current + screen_row_total - (output_current_row - screen_begin_row) >= display_line_total) // Reach end |
if (line_current + screen_row_total - (output_current_row - screen_begin_row) >= display_line_total) // Reach end |
| 740 |
{ |
{ |
| 891 |
int show_bottom(const char *msg) |
int show_bottom(const char *msg) |
| 892 |
{ |
{ |
| 893 |
char str_time[LINE_BUFFER_LEN]; |
char str_time[LINE_BUFFER_LEN]; |
| 894 |
|
int len_str_time; |
| 895 |
time_t time_online; |
time_t time_online; |
| 896 |
struct tm *tm_online; |
struct tm *tm_online; |
| 897 |
char msg_f[LINE_BUFFER_LEN]; |
char msg_f[LINE_BUFFER_LEN]; |
| 898 |
int eol; |
int eol; |
| 899 |
int msg_len; |
int len_msg; |
| 900 |
int len; |
int len; |
| 901 |
int len_username; |
int len_username; |
| 902 |
char str_tm_online[LINE_BUFFER_LEN]; |
char str_tm_online[LINE_BUFFER_LEN]; |
| 903 |
|
|
| 904 |
get_time_str(str_time, sizeof(str_time)); |
len_str_time = (int)get_time_str(str_time, sizeof(str_time)); |
| 905 |
|
|
| 906 |
msg_f[0] = '\0'; |
msg_f[0] = '\0'; |
| 907 |
msg_len = 0; |
len_msg = 0; |
| 908 |
if (msg != NULL) |
if (msg != NULL) |
| 909 |
{ |
{ |
| 910 |
strncpy(msg_f, msg, sizeof(msg_f) - 1); |
strncpy(msg_f, msg, sizeof(msg_f) - 1); |
| 911 |
msg_f[sizeof(msg_f) - 1] = '\0'; |
msg_f[sizeof(msg_f) - 1] = '\0'; |
| 912 |
len = split_line(msg_f, 23, &eol, &msg_len, 1); |
len = split_line(msg_f, 23, &eol, &len_msg, 1); |
| 913 |
msg_f[len] = '\0'; |
msg_f[len] = '\0'; |
| 914 |
} |
} |
| 915 |
|
|
| 920 |
if (tm_online->tm_mday > 1) |
if (tm_online->tm_mday > 1) |
| 921 |
{ |
{ |
| 922 |
snprintf(str_tm_online, sizeof(str_tm_online), |
snprintf(str_tm_online, sizeof(str_tm_online), |
| 923 |
"\033[36m%2d\033[33m天\033[36m%2d\033[33m时", |
"\033[36m%d\033[33md \033[36m%d\033[33m:\033[36m%.2d", |
| 924 |
tm_online->tm_mday - 1, tm_online->tm_hour); |
tm_online->tm_mday - 1, tm_online->tm_hour, tm_online->tm_min); |
| 925 |
} |
} |
| 926 |
else |
else |
| 927 |
{ |
{ |
| 928 |
snprintf(str_tm_online, sizeof(str_tm_online), |
snprintf(str_tm_online, sizeof(str_tm_online), |
| 929 |
"\033[36m%2d\033[33m时\033[36m%2d\033[33m分", |
"\033[36m%d\033[33m:\033[36m%.2d", |
| 930 |
tm_online->tm_hour, tm_online->tm_min); |
tm_online->tm_hour, tm_online->tm_min); |
| 931 |
} |
} |
| 932 |
|
|
| 933 |
moveto(SCREEN_ROWS, 0); |
moveto(SCREEN_ROWS, 0); |
| 934 |
clrtoeol(); |
clrtoeol(); |
| 935 |
prints("\033[1;44;33m时间[\033[36m%s\033[33m]%s%*s \033[33m帐号[\033[36m%s\033[33m][%s\033[33m]\033[m", |
prints("\033[1;44;33m时间[\033[36m%s\033[33m]%s%*s \033[33m用户[\033[36m%s\033[33m][%s\033[33m]\033[m", |
| 936 |
str_time, msg_f, 38 - msg_len - len_username, "", BBS_username, str_tm_online); |
str_time, msg_f, 60 - len_str_time - len_msg - len_username, "", BBS_username, str_tm_online); |
| 937 |
|
|
| 938 |
return 0; |
return 0; |
| 939 |
} |
} |