| 101 |
} |
} |
| 102 |
} |
} |
| 103 |
|
|
| 104 |
static int _str_input(char *buffer, int buffer_length, int echo_mode) |
static int _str_input(char *buffer, int buf_size, int echo_mode) |
| 105 |
{ |
{ |
| 106 |
int c, offset = 0, i, hz = 0; |
int c; |
| 107 |
|
int offset = 0; |
| 108 |
|
int hz = 0; |
| 109 |
|
|
| 110 |
for (i = 0; i < buffer_length && buffer[i] != '\0'; i++) |
buffer[buf_size - 1] = '\0'; |
| 111 |
{ |
for (offset = 0; offset < buf_size - 1 && buffer[offset] != '\0'; offset++); |
|
offset++; |
|
|
} |
|
| 112 |
|
|
| 113 |
while ((c = igetch_t(60))) |
while ((c = igetch_t(60))) |
| 114 |
{ |
{ |
| 148 |
} |
} |
| 149 |
if (c > 127 && c <= 255) |
if (c > 127 && c <= 255) |
| 150 |
{ |
{ |
| 151 |
if (!hz && offset + 2 > buffer_length) // No enough space for Chinese character |
if (!hz && offset + 2 > buf_size - 1) // No enough space for Chinese character |
| 152 |
{ |
{ |
| 153 |
igetch(1); // Cleanup remaining input |
igetch(1); // Cleanup remaining input |
| 154 |
outc('\a'); |
outc('\a'); |
| 157 |
} |
} |
| 158 |
hz = (!hz); |
hz = (!hz); |
| 159 |
} |
} |
| 160 |
if (offset >= buffer_length) |
if (offset + 1 > buf_size - 1) |
| 161 |
{ |
{ |
| 162 |
outc('\a'); |
outc('\a'); |
| 163 |
iflush(); |
iflush(); |
| 183 |
return offset; |
return offset; |
| 184 |
} |
} |
| 185 |
|
|
| 186 |
int str_input(char *buffer, int buffer_length, int echo_mode) |
int str_input(char *buffer, int buf_size, int echo_mode) |
| 187 |
{ |
{ |
| 188 |
int len; |
int len; |
| 189 |
|
|
| 190 |
buffer[0] = '\0'; |
buffer[0] = '\0'; |
| 191 |
|
|
| 192 |
len = _str_input(buffer, buffer_length, echo_mode); |
len = _str_input(buffer, buf_size, echo_mode); |
| 193 |
|
|
| 194 |
prints("\r\n"); |
prints("\r\n"); |
| 195 |
iflush(); |
iflush(); |
| 197 |
return len; |
return len; |
| 198 |
}; |
}; |
| 199 |
|
|
| 200 |
int get_data(int row, int col, char *prompt, char *buffer, int buffer_length, int echo_mode) |
int get_data(int row, int col, char *prompt, char *buffer, int buf_size, int echo_mode) |
| 201 |
{ |
{ |
| 202 |
int len; |
int len; |
| 203 |
|
|
| 208 |
prints(buffer); |
prints(buffer); |
| 209 |
iflush(); |
iflush(); |
| 210 |
|
|
| 211 |
len = _str_input(buffer, buffer_length, echo_mode); |
len = _str_input(buffer, buf_size, echo_mode); |
| 212 |
|
|
| 213 |
return len; |
return len; |
| 214 |
} |
} |
| 298 |
} |
} |
| 299 |
|
|
| 300 |
moveto(screen_rows, 0); |
moveto(screen_rows, 0); |
| 301 |
prints("\033[1;44;32m%s (%d%%)%s\033[33m │ 结束 ← <q> │ ↑/↓/PgUp/PgDn 移动 │ ? 辅助说明 │ \033[m", |
prints("\033[1;44;32m%s (%d%%)%s\033[33m │ 结束 ← <q> │ ↑/↓/PgUp/PgDn 移动 │ ? 辅助说明 │ \033[m", |
| 302 |
(percentile < 100 ? "下面还有喔" : "没有更多了"), percentile, |
(percentile < 100 ? "下面还有喔" : "没有更多了"), percentile, |
| 303 |
(percentile < 10 ? " " : (percentile < 100 ? " " : ""))); |
(percentile < 10 ? " " : (percentile < 100 ? " " : ""))); |
| 304 |
iflush(); |
iflush(); |
| 317 |
} |
} |
| 318 |
c_line_current -= line; |
c_line_current -= line; |
| 319 |
line = begin_line; |
line = begin_line; |
| 320 |
max_lines = begin_line + 1; |
// max_lines = begin_line + 1; |
| 321 |
prints("\033[T"); // Scroll down 1 line |
// prints("\033[T"); // Scroll down 1 line |
| 322 |
// max_lines = screen_rows - 1; // Legacy Fterm only works with this line |
max_lines = screen_rows - 1; // Legacy Fterm only works with this line |
| 323 |
break; |
break; |
| 324 |
case KEY_DOWN: |
case KEY_DOWN: |
| 325 |
case CR: |
case CR: |
| 428 |
|
|
| 429 |
int show_top(char *status) |
int show_top(char *status) |
| 430 |
{ |
{ |
| 431 |
char buffer[LINE_BUFFER_LEN]; |
int end_of_line; |
| 432 |
|
int display_len; |
| 433 |
|
unsigned int len; |
| 434 |
|
|
| 435 |
|
char space1[LINE_BUFFER_LEN]; |
| 436 |
|
char space2[LINE_BUFFER_LEN]; |
| 437 |
|
|
| 438 |
str_space(buffer, 20 - (int)strnlen(BBS_current_section_name, sizeof(BBS_current_section_name))); |
len = split_line(status, 20, &end_of_line, &display_len); |
| 439 |
|
if (end_of_line) |
| 440 |
|
{ |
| 441 |
|
status[len] = '\0'; |
| 442 |
|
} |
| 443 |
|
str_space(space1, 31 - display_len); |
| 444 |
|
|
| 445 |
|
len = split_line(BBS_current_section_name, 20, &end_of_line, &display_len); |
| 446 |
|
if (end_of_line) |
| 447 |
|
{ |
| 448 |
|
status[len] = '\0'; |
| 449 |
|
} |
| 450 |
|
str_space(space2, 30 - display_len); |
| 451 |
|
|
| 452 |
moveto(1, 0); |
moveto(1, 0); |
| 453 |
clrtoeol(); |
clrtoeol(); |
| 454 |
prints("\033[1;44;33m%-20s \033[37m%20s" |
prints("\033[1;44;33m%s \033[37m%s%s%s\033[33m 讨论区 [%s]\033[m", |
| 455 |
" %s\033[33m讨论区 [%s]\033[m", |
status, space1, BBS_name, space2, BBS_current_section_name); |
|
status, BBS_name, buffer, BBS_current_section_name); |
|
| 456 |
iflush(); |
iflush(); |
| 457 |
|
|
| 458 |
return 0; |
return 0; |
| 461 |
int show_bottom(char *msg) |
int show_bottom(char *msg) |
| 462 |
{ |
{ |
| 463 |
char str_time[LINE_BUFFER_LEN]; |
char str_time[LINE_BUFFER_LEN]; |
| 464 |
char buffer[LINE_BUFFER_LEN]; |
char space[LINE_BUFFER_LEN]; |
| 465 |
time_t time_online; |
time_t time_online; |
| 466 |
struct tm *tm_online; |
struct tm *tm_online; |
| 467 |
|
|
| 468 |
get_time_str(str_time, sizeof(str_time)); |
get_time_str(str_time, sizeof(str_time)); |
| 469 |
str_space(buffer, 33 - (int)strnlen(BBS_username, sizeof(BBS_username))); |
str_space(space, 34 - (int)strnlen(BBS_username, sizeof(BBS_username))); |
| 470 |
|
|
| 471 |
time_online = time(0) - BBS_login_tm; |
time_online = time(0) - BBS_login_tm; |
| 472 |
tm_online = gmtime(&time_online); |
tm_online = gmtime(&time_online); |
| 473 |
|
|
| 474 |
moveto(screen_rows, 0); |
moveto(screen_rows, 0); |
| 475 |
clrtoeol(); |
clrtoeol(); |
| 476 |
prints("\033[1;44;33m[\033[36m%s\033[33m]" |
prints("\033[1;44;33m[\033[36m%s\033[33m]%s帐号[\033[36m%s\033[33m]" |
|
"%s帐号[\033[36m%s\033[33m]" |
|
| 477 |
"[\033[36m%1d\033[33m:\033[36m%2d\033[33m:\033[36m%2d\033[33m]\033[m", |
"[\033[36m%1d\033[33m:\033[36m%2d\033[33m:\033[36m%2d\033[33m]\033[m", |
| 478 |
str_time, buffer, BBS_username, tm_online->tm_mday - 1, |
str_time, space, BBS_username, tm_online->tm_mday - 1, |
| 479 |
tm_online->tm_hour, tm_online->tm_min); |
tm_online->tm_hour, tm_online->tm_min); |
| 480 |
iflush(); |
iflush(); |
| 481 |
|
|
| 490 |
static int line; |
static int line; |
| 491 |
unsigned int len; |
unsigned int len; |
| 492 |
int end_of_line; |
int end_of_line; |
| 493 |
|
int display_len; |
| 494 |
|
|
| 495 |
clrline(3, 2 + ACTIVE_BOARD_HEIGHT); |
clrline(3, 2 + ACTIVE_BOARD_HEIGHT); |
| 496 |
|
|
| 518 |
break; |
break; |
| 519 |
} |
} |
| 520 |
line++; |
line++; |
| 521 |
len = split_line(buffer, screen_cols, &end_of_line); |
len = split_line(buffer, screen_cols, &end_of_line, &display_len); |
| 522 |
buffer[len] = '\0'; // Truncate over-length line |
buffer[len] = '\0'; // Truncate over-length line |
| 523 |
moveto(3 + i, 0); |
moveto(3 + i, 0); |
| 524 |
prints("%s", buffer); |
prints("%s", buffer); |