| 76 |
|
|
| 77 |
int press_any_key() |
int press_any_key() |
| 78 |
{ |
{ |
|
igetch(1); |
|
|
|
|
| 79 |
moveto(screen_rows, 0); |
moveto(screen_rows, 0); |
| 80 |
clrtoeol(); |
clrtoeol(); |
| 81 |
|
|
| 104 |
|
|
| 105 |
static int _str_input(char *buffer, int buffer_length, int echo_mode) |
static int _str_input(char *buffer, int buffer_length, int echo_mode) |
| 106 |
{ |
{ |
| 107 |
char buf[256], ch; |
int c, offset = 0, i, hz = 0; |
|
int c, offset = 0, len, loop = 1, i, hz = 0; |
|
| 108 |
|
|
| 109 |
for (i = 0; i < buffer_length && buffer[i] != '\0'; i++) |
for (i = 0; i < buffer_length && buffer[i] != '\0'; i++) |
| 110 |
{ |
{ |
| 111 |
offset++; |
offset++; |
| 112 |
} |
} |
| 113 |
|
|
| 114 |
igetch(1); |
while ((c = igetch_t(60))) |
|
|
|
|
while (c = igetch_t(60)) |
|
| 115 |
{ |
{ |
| 116 |
if (c == KEY_NULL || c == KEY_TIMEOUT || c == CR) |
if (c == KEY_NULL || c == KEY_TIMEOUT || c == CR) |
| 117 |
{ |
{ |
| 118 |
|
igetch(1); // Cleanup remaining '\n' in the buffer |
| 119 |
break; |
break; |
| 120 |
} |
} |
| 121 |
if (c == LF) |
if (c == LF) |
| 126 |
{ |
{ |
| 127 |
if (offset > 0) |
if (offset > 0) |
| 128 |
{ |
{ |
| 129 |
buffer[--offset] = '\0'; |
offset--; |
| 130 |
prints("\b \b"); |
if (buffer[offset] < 0 || buffer[offset] > 127) |
| 131 |
// clrtoeol (); |
{ |
| 132 |
|
prints("\033[D \033[D"); |
| 133 |
|
offset--; |
| 134 |
|
if (offset < 0) // should not happen |
| 135 |
|
{ |
| 136 |
|
log_error("Offset of buffer is negative\n"); |
| 137 |
|
offset = 0; |
| 138 |
|
} |
| 139 |
|
} |
| 140 |
|
buffer[offset] = '\0'; |
| 141 |
|
prints("\033[D \033[D"); |
| 142 |
iflush(); |
iflush(); |
| 143 |
} |
} |
| 144 |
continue; |
continue; |
| 149 |
} |
} |
| 150 |
if (c > 127 && c <= 255) |
if (c > 127 && c <= 255) |
| 151 |
{ |
{ |
| 152 |
|
if (!hz && offset + 2 > buffer_length) // No enough space for Chinese character |
| 153 |
|
{ |
| 154 |
|
igetch(1); // Clear remaining input |
| 155 |
|
outc('\a'); |
| 156 |
|
iflush(); |
| 157 |
|
continue; |
| 158 |
|
} |
| 159 |
hz = (!hz); |
hz = (!hz); |
| 160 |
} |
} |
| 161 |
if (offset >= buffer_length) |
if (offset >= buffer_length) |
| 162 |
{ |
{ |
| 163 |
outc('\a'); |
outc('\a'); |
| 164 |
|
iflush(); |
| 165 |
continue; |
continue; |
| 166 |
} |
} |
| 167 |
buffer[offset++] = (char)c; |
buffer[offset++] = (char)c; |
| 243 |
int display_file_ex(const char *filename, int begin_line, int wait) |
int display_file_ex(const char *filename, int begin_line, int wait) |
| 244 |
{ |
{ |
| 245 |
char buffer[LINE_BUFFER_LEN]; |
char buffer[LINE_BUFFER_LEN]; |
|
char temp[LINE_BUFFER_LEN]; |
|
| 246 |
int ch = 0; |
int ch = 0; |
| 247 |
int input_ok, line, max_lines; |
int input_ok, line, max_lines; |
| 248 |
long int c_line_current = 0, c_line_total = 0; |
long int c_line_current = 0, c_line_total = 0; |
| 249 |
FILE *fin; |
FILE *fin; |
|
struct stat f_stat; |
|
| 250 |
long *p_line_offsets; |
long *p_line_offsets; |
| 251 |
int len; |
int len; |
| 252 |
int percentile; |
int percentile; |
| 253 |
|
int loop = 1; |
| 254 |
|
|
| 255 |
if ((fin = fopen(filename, "r")) == NULL) |
if ((fin = fopen(filename, "r")) == NULL) |
| 256 |
{ |
{ |
| 266 |
line = begin_line; |
line = begin_line; |
| 267 |
max_lines = screen_rows - 1; |
max_lines = screen_rows - 1; |
| 268 |
|
|
| 269 |
while (c_line_current < c_line_total) |
while (loop) |
| 270 |
{ |
{ |
| 271 |
if (line >= max_lines) |
if (c_line_current >= c_line_total && c_line_total <= screen_rows - 2) |
| 272 |
{ |
{ |
| 273 |
percentile = (c_line_current - (line - 1) + (screen_rows - 2)) * 100 / c_line_total; |
if (wait) |
| 274 |
|
{ |
| 275 |
|
ch = press_any_key(); |
| 276 |
|
} |
| 277 |
|
else |
| 278 |
|
{ |
| 279 |
|
iflush(); |
| 280 |
|
} |
| 281 |
|
|
| 282 |
|
loop = 0; |
| 283 |
|
break; |
| 284 |
|
} |
| 285 |
|
|
| 286 |
|
if (c_line_current >= c_line_total || line >= max_lines) |
| 287 |
|
{ |
| 288 |
|
if (c_line_current - (line - 1) + (screen_rows - 2) < c_line_total) |
| 289 |
|
{ |
| 290 |
|
percentile = (c_line_current - (line - 1) + (screen_rows - 2)) * 100 / c_line_total; |
| 291 |
|
} |
| 292 |
|
else |
| 293 |
|
{ |
| 294 |
|
percentile = 100; |
| 295 |
|
} |
| 296 |
|
|
| 297 |
moveto(screen_rows, 0); |
moveto(screen_rows, 0); |
| 298 |
prints("\033[1;44;32m下面还有喔 (%d%%)\033[33m │ 结束 ← <q> │ ↑/↓/PgUp/PgDn 移动 │ ? 辅助说明 │ \033[m", |
prints("\033[1;44;32m%s (%d%%)%s\033[33m │ 结束 ← <q> │ ↑/↓/PgUp/PgDn 移动 │ ? 辅助说明 │ \033[m", |
| 299 |
percentile); |
(percentile < 100 ? "下面还有喔" : "没有更多了"), percentile, |
| 300 |
|
(percentile < 10 ? " " : (percentile < 100 ? " " : ""))); |
| 301 |
iflush(); |
iflush(); |
| 302 |
|
|
| 303 |
input_ok = 0; |
input_ok = 0; |
| 315 |
c_line_current -= line; |
c_line_current -= line; |
| 316 |
line = begin_line; |
line = begin_line; |
| 317 |
max_lines = begin_line + 1; |
max_lines = begin_line + 1; |
| 318 |
prints("\033[1T"); // Scroll down 1 line |
prints("\033[T"); // Scroll down 1 line |
| 319 |
|
// max_lines = screen_rows - 1; // Legacy Fterm only works with this line |
| 320 |
break; |
break; |
| 321 |
case KEY_DOWN: |
case KEY_DOWN: |
| 322 |
case CR: |
case CR: |
| 329 |
max_lines = screen_rows - 1; |
max_lines = screen_rows - 1; |
| 330 |
moveto(screen_rows, 0); |
moveto(screen_rows, 0); |
| 331 |
clrtoeol(); |
clrtoeol(); |
| 332 |
prints("\033[1S"); // Scroll up 1 line |
prints("\033[S"); // Scroll up 1 line |
| 333 |
break; |
break; |
| 334 |
case KEY_PGUP: |
case KEY_PGUP: |
| 335 |
case Ctrl('B'): |
case Ctrl('B'): |
| 368 |
case KEY_LEFT: |
case KEY_LEFT: |
| 369 |
case 'q': |
case 'q': |
| 370 |
case 'Q': |
case 'Q': |
| 371 |
c_line_current = c_line_total; |
loop = 0; |
|
wait = 0; |
|
| 372 |
break; |
break; |
| 373 |
case '?': |
case '?': |
| 374 |
case 'h': |
case 'h': |
| 375 |
case 'H': |
case 'H': |
| 376 |
// Display help information |
// Display help information |
| 377 |
strcpy(temp, app_home_dir); |
display_file_ex(DATA_READ_HELP, begin_line, 1); |
|
strcat(temp, "data/read_help.txt"); |
|
|
display_file_ex(temp, begin_line, 1); |
|
| 378 |
|
|
| 379 |
// Refresh after display help information |
// Refresh after display help information |
| 380 |
c_line_current -= (line - 1); |
c_line_current -= (line - 1); |
| 410 |
line++; |
line++; |
| 411 |
} |
} |
| 412 |
|
|
|
iflush(); |
|
|
|
|
|
if (wait) |
|
|
{ |
|
|
ch = press_any_key(); |
|
|
} |
|
|
|
|
| 413 |
free(p_line_offsets); |
free(p_line_offsets); |
| 414 |
fclose(fin); |
fclose(fin); |
| 415 |
|
|
| 435 |
int show_bottom(char *msg) |
int show_bottom(char *msg) |
| 436 |
{ |
{ |
| 437 |
char str_time[LINE_BUFFER_LEN]; |
char str_time[LINE_BUFFER_LEN]; |
|
char str_time_onine[20]; |
|
| 438 |
char buffer[LINE_BUFFER_LEN]; |
char buffer[LINE_BUFFER_LEN]; |
| 439 |
time_t time_online; |
time_t time_online; |
| 440 |
struct tm *tm_online; |
struct tm *tm_online; |
| 466 |
int len; |
int len; |
| 467 |
int end_of_line; |
int end_of_line; |
| 468 |
|
|
|
sprintf(filename, "%sdata/active_board.txt", app_home_dir); |
|
|
|
|
| 469 |
clrline(3, 2 + ACTIVE_BOARD_HEIGHT); |
clrline(3, 2 + ACTIVE_BOARD_HEIGHT); |
| 470 |
|
|
| 471 |
if ((fin = fopen(filename, "r")) == NULL) |
if ((fin = fopen(DATA_ACTIVE_BOARD, "r")) == NULL) |
| 472 |
{ |
{ |
| 473 |
log_error("Unable to open file %s\n", filename); |
log_error("Unable to open file %s\n", filename); |
| 474 |
return -1; |
return -1; |