| 3 |
* screen |
* screen |
| 4 |
* - advanced telnet-based user interactive input / output features |
* - advanced telnet-based user interactive input / output features |
| 5 |
* |
* |
| 6 |
* Copyright (C) 2004-2025 by Leaflet <leaflet@leafok.com> |
* Copyright (C) 2004-2025 Leaflet <leaflet@leafok.com> |
| 7 |
*/ |
*/ |
| 8 |
|
|
| 9 |
#include "bbs.h" |
#include "bbs.h" |
| 21 |
#include <string.h> |
#include <string.h> |
| 22 |
#include <stdlib.h> |
#include <stdlib.h> |
| 23 |
#include <unistd.h> |
#include <unistd.h> |
| 24 |
|
#include <wchar.h> |
| 25 |
#include <sys/param.h> |
#include <sys/param.h> |
| 26 |
#include <sys/stat.h> |
#include <sys/stat.h> |
| 27 |
#include <sys/shm.h> |
#include <sys/shm.h> |
| 28 |
#include <sys/types.h> |
#include <sys/types.h> |
| 29 |
|
|
| 30 |
#define ACTIVE_BOARD_HEIGHT 8 |
const char CTRL_SEQ_CLR_LINE[] = "\033[K"; |
| 31 |
|
|
| 32 |
#define STR_TOP_LEFT_MAX_LEN 80 |
static const int ACTIVE_BOARD_HEIGHT = 8; |
| 33 |
#define STR_TOP_MIDDLE_MAX_LEN 40 |
|
| 34 |
#define STR_TOP_RIGHT_MAX_LEN 80 |
static const int STR_TOP_LEFT_MAX_LEN = 80; |
| 35 |
|
static const int STR_TOP_MIDDLE_MAX_LEN = 40; |
| 36 |
|
static const int STR_TOP_RIGHT_MAX_LEN = 80; |
| 37 |
|
|
| 38 |
static size_t get_time_str(char *s, size_t len) |
static size_t get_time_str(char *s, size_t len) |
| 39 |
{ |
{ |
| 130 |
iflush(); |
iflush(); |
| 131 |
} |
} |
| 132 |
|
|
| 133 |
static int _str_input(char *buffer, int buf_size, int max_display_len, int echo_mode) |
static int _str_input(char *buffer, int buf_size, int max_display_len, enum io_echo_t echo_mode) |
| 134 |
{ |
{ |
| 135 |
int ch; |
int ch; |
| 136 |
int offset = 0; |
int offset = 0; |
| 137 |
int eol; |
int eol; |
| 138 |
int display_len; |
int display_len; |
| 139 |
char input_str[4]; |
char input_str[5]; |
| 140 |
int str_len = 0; |
int str_len = 0; |
| 141 |
|
wchar_t wcs[2]; |
| 142 |
char c; |
char c; |
| 143 |
|
|
| 144 |
buffer[buf_size - 1] = '\0'; |
buffer[buf_size - 1] = '\0'; |
| 148 |
|
|
| 149 |
while (!SYS_server_exit) |
while (!SYS_server_exit) |
| 150 |
{ |
{ |
| 151 |
ch = igetch_t(MIN(MAX_DELAY_TIME, 60)); |
ch = igetch_t(MIN(BBS_max_user_idle_time, 60)); |
| 152 |
|
|
| 153 |
if (ch == CR) |
if (ch == CR) |
| 154 |
{ |
{ |
| 213 |
break; |
break; |
| 214 |
} |
} |
| 215 |
} |
} |
| 216 |
|
input_str[str_len] = '\0'; |
| 217 |
|
|
| 218 |
if (str_len == 0) // Incomplete input |
if (str_len == 0) // Incomplete input |
| 219 |
{ |
{ |
| 220 |
continue; |
continue; |
| 221 |
} |
} |
| 222 |
|
|
| 223 |
if (offset + str_len > buf_size - 1 || display_len + 2 > max_display_len) // No enough space for Chinese character |
if (mbstowcs(wcs, input_str, 1) == (size_t)-1) |
| 224 |
|
{ |
| 225 |
|
log_error("mbstowcs() error\n"); |
| 226 |
|
} |
| 227 |
|
if (offset + str_len > buf_size - 1 || display_len + (UTF8_fixed_width ? 2 : wcwidth(wcs[0])) > max_display_len) // No enough space for Chinese character |
| 228 |
{ |
{ |
| 229 |
outc('\a'); |
outc('\a'); |
| 230 |
iflush(); |
iflush(); |
| 280 |
return offset; |
return offset; |
| 281 |
} |
} |
| 282 |
|
|
| 283 |
int str_input(char *buffer, int buf_size, int echo_mode) |
int str_input(char *buffer, int buf_size, enum io_echo_t echo_mode) |
| 284 |
{ |
{ |
| 285 |
int len; |
int len; |
| 286 |
|
|
| 302 |
int offset = 0; |
int offset = 0; |
| 303 |
int eol; |
int eol; |
| 304 |
int display_len; |
int display_len; |
| 305 |
char input_str[4]; |
char input_str[5]; |
| 306 |
|
wchar_t wcs[2]; |
| 307 |
int str_len = 0; |
int str_len = 0; |
| 308 |
char c; |
char c; |
| 309 |
|
|
| 324 |
|
|
| 325 |
while (!SYS_server_exit) |
while (!SYS_server_exit) |
| 326 |
{ |
{ |
| 327 |
ch = igetch_t(MIN(MAX_DELAY_TIME, 60)); |
ch = igetch_t(MIN(BBS_max_user_idle_time, 60)); |
| 328 |
|
|
| 329 |
if (ch == CR) |
if (ch == CR) |
| 330 |
{ |
{ |
| 506 |
break; |
break; |
| 507 |
} |
} |
| 508 |
} |
} |
| 509 |
|
input_str[str_len] = '\0'; |
| 510 |
|
|
| 511 |
if (str_len == 0) // Incomplete input |
if (str_len == 0) // Incomplete input |
| 512 |
{ |
{ |
| 513 |
continue; |
continue; |
| 514 |
} |
} |
| 515 |
|
|
| 516 |
if (len + str_len > buf_size - 1 || display_len + 2 > max_display_len) // No enough space for Chinese character |
if (mbstowcs(wcs, input_str, 1) == (size_t)-1) |
| 517 |
|
{ |
| 518 |
|
log_error("mbstowcs() error\n"); |
| 519 |
|
} |
| 520 |
|
if (len + str_len > buf_size - 1 || display_len + (UTF8_fixed_width ? 2 : wcwidth(wcs[0])) > max_display_len) // No enough space for Chinese character |
| 521 |
{ |
{ |
| 522 |
outc('\a'); |
outc('\a'); |
| 523 |
iflush(); |
iflush(); |
| 605 |
loop = 1; |
loop = 1; |
| 606 |
while (!SYS_server_exit && loop) |
while (!SYS_server_exit && loop) |
| 607 |
{ |
{ |
| 608 |
if (eof_exit > 0 && line_current >= display_line_total && display_line_total <= screen_row_total) |
if (eof_exit > 0 && line_current >= display_line_total) |
| 609 |
{ |
{ |
| 610 |
if (eof_exit == 1) |
if (eof_exit == 1) |
| 611 |
{ |
{ |
| 660 |
input_ok = 0; |
input_ok = 0; |
| 661 |
while (!SYS_server_exit && !input_ok) |
while (!SYS_server_exit && !input_ok) |
| 662 |
{ |
{ |
| 663 |
ch = igetch_t(MAX_DELAY_TIME); |
ch = igetch_t(BBS_max_user_idle_time); |
| 664 |
input_ok = 1; |
input_ok = 1; |
| 665 |
|
|
| 666 |
if (ch != KEY_NULL && ch != KEY_TIMEOUT) |
if (ch != KEY_NULL && ch != KEY_TIMEOUT) |
| 815 |
return ch; |
return ch; |
| 816 |
} |
} |
| 817 |
|
|
| 818 |
static int display_file_key_handler(int *p_key, DISPLAY_CTX *p_ctx) |
int display_file_key_handler(int *p_key, DISPLAY_CTX *p_ctx) |
| 819 |
{ |
{ |
| 820 |
switch (*p_key) |
switch (*p_key) |
| 821 |
{ |
{ |
| 907 |
int len; |
int len; |
| 908 |
int len_username; |
int len_username; |
| 909 |
char str_tm_online[LINE_BUFFER_LEN]; |
char str_tm_online[LINE_BUFFER_LEN]; |
| 910 |
|
int len_str_tm_online; |
| 911 |
|
|
| 912 |
len_str_time = (int)get_time_str(str_time, sizeof(str_time)); |
len_str_time = (int)get_time_str(str_time, sizeof(str_time)); |
| 913 |
|
|
| 937 |
"\033[36m%d\033[33m:\033[36m%.2d", |
"\033[36m%d\033[33m:\033[36m%.2d", |
| 938 |
tm_online->tm_hour, tm_online->tm_min); |
tm_online->tm_hour, tm_online->tm_min); |
| 939 |
} |
} |
| 940 |
|
len_str_tm_online = str_length(str_tm_online, 1); |
| 941 |
|
|
| 942 |
moveto(SCREEN_ROWS, 0); |
moveto(SCREEN_ROWS, 0); |
| 943 |
clrtoeol(); |
clrtoeol(); |
| 944 |
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", |
| 945 |
str_time, msg_f, 61 - len_str_time - len_msg - len_username, "", BBS_username, str_tm_online); |
str_time, msg_f, 65 - len_str_time - len_msg - len_username - len_str_tm_online, |
| 946 |
|
"", BBS_username, str_tm_online); |
| 947 |
|
|
| 948 |
return 0; |
return 0; |
| 949 |
} |
} |