| 233 |
return len; |
return len; |
| 234 |
} |
} |
| 235 |
|
|
| 236 |
int display_data(const void *p_data, long line_total, const long *p_line_offsets, int begin_line, int wait, |
int display_data(const void *p_data, long line_total, const long *p_line_offsets, int begin_line, int eof_exit, |
| 237 |
display_data_key_handler key_handler, const char *help_filename) |
display_data_key_handler key_handler, const char *help_filename) |
| 238 |
{ |
{ |
| 239 |
static int show_help = 1; |
static int show_help = 1; |
| 260 |
loop = 1; |
loop = 1; |
| 261 |
while (!SYS_server_exit && loop) |
while (!SYS_server_exit && loop) |
| 262 |
{ |
{ |
| 263 |
if (line_current >= line_total && line_total <= SCREEN_ROWS - 2) |
if (eof_exit > 0 && line_current >= line_total && line_total <= SCREEN_ROWS - 2) |
| 264 |
{ |
{ |
| 265 |
if (wait) |
if (eof_exit == 1) |
| 266 |
{ |
{ |
| 267 |
ch = press_any_key(); |
ch = press_any_key(); |
| 268 |
} |
} |
| 269 |
else |
else // if (eof_exit == 2) |
| 270 |
{ |
{ |
| 271 |
iflush(); |
iflush(); |
| 272 |
} |
} |
| 322 |
case KEY_TIMEOUT: |
case KEY_TIMEOUT: |
| 323 |
goto cleanup; |
goto cleanup; |
| 324 |
case KEY_HOME: |
case KEY_HOME: |
| 325 |
|
if (line_current - line < 0) // Reach top |
| 326 |
|
{ |
| 327 |
|
break; |
| 328 |
|
} |
| 329 |
line_current = 0; |
line_current = 0; |
| 330 |
line = begin_line; |
line = begin_line; |
| 331 |
max_lines = SCREEN_ROWS - 1; |
max_lines = SCREEN_ROWS - 1; |
| 332 |
clrline(begin_line, SCREEN_ROWS); |
clrline(begin_line, SCREEN_ROWS); |
| 333 |
break; |
break; |
| 334 |
case KEY_END: |
case KEY_END: |
| 335 |
|
if (line_total < SCREEN_ROWS - 2) |
| 336 |
|
{ |
| 337 |
|
break; |
| 338 |
|
} |
| 339 |
line_current = line_total - (SCREEN_ROWS - 2); |
line_current = line_total - (SCREEN_ROWS - 2); |
| 340 |
line = begin_line; |
line = begin_line; |
| 341 |
max_lines = SCREEN_ROWS - 1; |
max_lines = SCREEN_ROWS - 1; |
| 453 |
|
|
| 454 |
static int display_file_key_handler(int *key, char *msg, size_t msg_len) |
static int display_file_key_handler(int *key, char *msg, size_t msg_len) |
| 455 |
{ |
{ |
|
static int topic_view = 0; |
|
|
|
|
| 456 |
switch (*key) |
switch (*key) |
| 457 |
{ |
{ |
| 458 |
case 0: // Set msg |
case 0: // Set msg |
| 461 |
"移动[\033[32m↑\033[33m/\033[32m↓\033[33m/\033[32mPgUp\033[33m/\033[32mPgDn\033[33m] │ " |
"移动[\033[32m↑\033[33m/\033[32m↓\033[33m/\033[32mPgUp\033[33m/\033[32mPgDn\033[33m] │ " |
| 462 |
"帮助[\033[32mh\033[33m] |"); |
"帮助[\033[32mh\033[33m] |"); |
| 463 |
break; |
break; |
|
case 'p': |
|
|
break; |
|
|
topic_view = !topic_view; |
|
|
if (topic_view) |
|
|
{ |
|
|
snprintf(msg, msg_len, |
|
|
"| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] │ " |
|
|
"同主题阅读[\033[32m↑\033[33m/\033[32m↓\033[33m] │ " |
|
|
"帮助[\033[32mh\033[33m] |"); |
|
|
} |
|
|
else |
|
|
{ |
|
|
snprintf(msg, msg_len, |
|
|
"| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] │ " |
|
|
"移动[\033[32m↑\033[33m/\033[32m↓\033[33m/\033[32mPgUp\033[33m/\033[32mPgDn\033[33m] │ " |
|
|
"帮助[\033[32mh\033[33m] |"); |
|
|
} |
|
|
*key = 0; |
|
|
break; |
|
| 464 |
case 'H': |
case 'H': |
| 465 |
*key = 'h'; |
*key = 'h'; |
| 466 |
return 0; |
return 0; |
| 469 |
return 0; |
return 0; |
| 470 |
} |
} |
| 471 |
|
|
| 472 |
int display_file(const char *filename, int begin_line, int wait) |
int display_file(const char *filename, int begin_line, int eof_exit) |
| 473 |
{ |
{ |
| 474 |
int ret; |
int ret; |
| 475 |
const void *p_shm; |
const void *p_shm; |
| 484 |
return KEY_NULL; |
return KEY_NULL; |
| 485 |
} |
} |
| 486 |
|
|
| 487 |
ret = display_data(p_data, line_total, p_line_offsets, begin_line, wait, display_file_key_handler, DATA_READ_HELP); |
ret = display_data(p_data, line_total, p_line_offsets, begin_line, eof_exit, display_file_key_handler, DATA_READ_HELP); |
| 488 |
|
|
| 489 |
if (detach_file_shm(p_shm) < 0) |
if (detach_file_shm(p_shm) < 0) |
| 490 |
{ |
{ |