--- lbbs/src/screen.c 2025/10/17 01:25:08 1.111 +++ lbbs/src/screen.c 2025/10/28 05:08:50 1.120 @@ -40,25 +40,16 @@ #define STR_TOP_MIDDLE_MAX_LEN 40 #define STR_TOP_RIGHT_MAX_LEN 80 -static const char *get_time_str(char *s, size_t len) +static size_t get_time_str(char *s, size_t len) { - static const char *weekday[] = { - "天", "一", "二", "三", "四", "五", "六"}; time_t curtime; struct tm local_tm; time(&curtime); localtime_r(&curtime, &local_tm); - 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); - if (j == 0 || j + strlen(weekday[local_tm.tm_wday]) + 1 > len) - { - return NULL; - } - - strncat(s, weekday[local_tm.tm_wday], len - 1 - j); - - return s; + return j; } void moveto(int row, int col) @@ -102,15 +93,32 @@ void clearscr() moveto(0, 0); } -int press_any_key() +inline int press_any_key() { + return press_any_key_ex(" \033[1;33m按任意键继续...\033[m", 60); +} + +int press_any_key_ex(const char *msg, int sec) +{ + int ch = 0; + int duration = 0; + time_t t_begin = time(NULL); + moveto(SCREEN_ROWS, 0); clrtoeol(); - prints(" \033[1;33m按任意键继续...\033[0;37m"); + prints(msg); iflush(); - return igetch_t(MIN(MAX_DELAY_TIME, 60)); + igetch_reset(); + + do + { + ch = igetch_t(sec - duration); + duration = (int)(time(NULL) - t_begin); + } while (!SYS_server_exit && ch == 0 && duration < 60); + + return ch; } void set_input_echo(int echo) @@ -165,7 +173,7 @@ static int _str_input(char *buffer, int offset--; if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8 { - while (offset > 0 && (buffer[offset] & 0b11000000) != 0b11000000) + while (offset > 0 && (buffer[offset] & 0xc0) != 0xc0) { offset--; } @@ -186,14 +194,14 @@ static int _str_input(char *buffer, int else if ((ch & 0xff80) == 0x80) // head of multi-byte character { str_len = 0; - c = (char)(ch & 0b11110000); - while (c & 0b10000000) + c = (char)(ch & 0xf0); + while (c & 0x80) { input_str[str_len] = (char)(ch - 256); str_len++; - c = (c & 0b01111111) << 1; + c = (c & 0x7f) << 1; - if ((c & 0b10000000) == 0) // Input completed + if ((c & 0x80) == 0) // Input completed { break; } @@ -283,7 +291,7 @@ int str_input(char *buffer, int buf_size iflush(); return len; -}; +} int get_data(int row, int col, char *prompt, char *buffer, int buf_size, int max_display_len) { @@ -336,7 +344,7 @@ int get_data(int row, int col, char *pro offset--; if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8 { - while (offset > 0 && (buffer[offset] & 0b11000000) != 0b11000000) + while (offset > 0 && (buffer[offset] & 0xc0) != 0xc0) { str_len++; offset--; @@ -366,11 +374,11 @@ int get_data(int row, int col, char *pro if ((buffer[offset] & 0x80) == 0x80) // head of multi-byte character { str_len = 0; - c = (char)(buffer[offset] & 0b11110000); - while (c & 0b10000000) + c = (char)(buffer[offset] & 0xf0); + while (c & 0x80) { str_len++; - c = (c & 0b01111111) << 1; + c = (c & 0x7f) << 1; } display_len--; } @@ -400,7 +408,7 @@ int get_data(int row, int col, char *pro offset--; if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8 { - while (offset > 0 && (buffer[offset] & 0b11000000) != 0b11000000) + while (offset > 0 && (buffer[offset] & 0xc0) != 0xc0) { str_len++; offset--; @@ -421,11 +429,11 @@ int get_data(int row, int col, char *pro str_len = 0; if ((buffer[offset] & 0x80) == 0x80) // head of multi-byte character { - c = (char)(buffer[offset] & 0b11110000); - while (c & 0b10000000) + c = (char)(buffer[offset] & 0xf0); + while (c & 0x80) { str_len++; - c = (c & 0b01111111) << 1; + c = (c & 0x7f) << 1; } col_cur++; } @@ -473,14 +481,14 @@ int get_data(int row, int col, char *pro else if ((ch & 0xff80) == 0x80) // head of multi-byte character { str_len = 0; - c = (char)(ch & 0b11110000); - while (c & 0b10000000) + c = (char)(ch & 0xf0); + while (c & 0x80) { input_str[str_len] = (char)(ch - 256); str_len++; - c = (c & 0b01111111) << 1; + c = (c & 0x7f) << 1; - if ((c & 0b10000000) == 0) // Input completed + if ((c & 0x80) == 0) // Input completed { break; } @@ -699,7 +707,6 @@ int display_data(const void *p_data, lon output_end_row = SCREEN_ROWS - 1; // Legacy Fterm only works with this line break; case CR: - case KEY_SPACE: case KEY_DOWN: if (line_current + (screen_row_total - (output_current_row - screen_begin_row)) >= display_line_total) // Reach end { @@ -727,6 +734,7 @@ int display_data(const void *p_data, lon output_end_row = SCREEN_ROWS - 1; clrline(output_current_row, SCREEN_ROWS); break; + case KEY_SPACE: case KEY_PGDN: if (line_current + screen_row_total - (output_current_row - screen_begin_row) >= display_line_total) // Reach end { @@ -883,24 +891,25 @@ int show_top(const char *str_left, const int show_bottom(const char *msg) { char str_time[LINE_BUFFER_LEN]; + int len_str_time; time_t time_online; struct tm *tm_online; char msg_f[LINE_BUFFER_LEN]; int eol; - int msg_len; + int len_msg; int len; int len_username; char str_tm_online[LINE_BUFFER_LEN]; - get_time_str(str_time, sizeof(str_time)); + len_str_time = (int)get_time_str(str_time, sizeof(str_time)); msg_f[0] = '\0'; - msg_len = 0; + len_msg = 0; if (msg != NULL) { strncpy(msg_f, msg, sizeof(msg_f) - 1); msg_f[sizeof(msg_f) - 1] = '\0'; - len = split_line(msg_f, 23, &eol, &msg_len, 1); + len = split_line(msg_f, 23, &eol, &len_msg, 1); msg_f[len] = '\0'; } @@ -911,20 +920,20 @@ int show_bottom(const char *msg) if (tm_online->tm_mday > 1) { snprintf(str_tm_online, sizeof(str_tm_online), - "\033[36m%2d\033[33m天\033[36m%2d\033[33m时", - tm_online->tm_mday - 1, tm_online->tm_hour); + "\033[36m%d\033[33md \033[36m%d\033[33m:\033[36m%.2d", + tm_online->tm_mday - 1, tm_online->tm_hour, tm_online->tm_min); } else { snprintf(str_tm_online, sizeof(str_tm_online), - "\033[36m%2d\033[33m时\033[36m%2d\033[33m分", + "\033[36m%d\033[33m:\033[36m%.2d", tm_online->tm_hour, tm_online->tm_min); } moveto(SCREEN_ROWS, 0); clrtoeol(); - prints("\033[1;44;33m时间[\033[36m%s\033[33m]%s%*s \033[33m帐号[\033[36m%s\033[33m][%s\033[33m]\033[m", - str_time, msg_f, 38 - msg_len - len_username, "", BBS_username, str_tm_online); + prints("\033[1;44;33m时间[\033[36m%s\033[33m]%s%*s \033[33m用户[\033[36m%s\033[33m][%s\033[33m]\033[m", + str_time, msg_f, 61 - len_str_time - len_msg - len_username, "", BBS_username, str_tm_online); return 0; }