| 40 |
#define STR_TOP_MIDDLE_MAX_LEN 20 |
#define STR_TOP_MIDDLE_MAX_LEN 20 |
| 41 |
#define STR_TOP_RIGHT_MAX_LEN 20 |
#define STR_TOP_RIGHT_MAX_LEN 20 |
| 42 |
|
|
| 43 |
|
#define MSG_EXT_MAX_LEN 200 |
| 44 |
|
|
| 45 |
void moveto(int row, int col) |
void moveto(int row, int col) |
| 46 |
{ |
{ |
| 47 |
if (row >= 0) |
if (row >= 0) |
| 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) |
| 238 |
{ |
{ |
| 239 |
static int show_help = 1; |
static int show_help = 1; |
| 240 |
char buffer[LINE_BUFFER_LEN]; |
char buffer[LINE_BUFFER_LEN]; |
| 241 |
int ch = KEY_NULL; |
char msg_ext[MSG_EXT_MAX_LEN]; |
| 242 |
|
int ch = 0; |
| 243 |
int input_ok, line, max_lines; |
int input_ok, line, max_lines; |
| 244 |
long int line_current = 0; |
long int line_current = 0; |
| 245 |
long int len; |
long int len; |
| 251 |
line = begin_line; |
line = begin_line; |
| 252 |
max_lines = SCREEN_ROWS - 1; |
max_lines = SCREEN_ROWS - 1; |
| 253 |
|
|
| 254 |
|
// update msg_ext with extended key handler |
| 255 |
|
if (key_handler(&ch, msg_ext, sizeof(msg_ext)) != 0) |
| 256 |
|
{ |
| 257 |
|
return ch; |
| 258 |
|
} |
| 259 |
|
|
| 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 |
} |
} |
| 287 |
} |
} |
| 288 |
|
|
| 289 |
snprintf(buffer, sizeof(buffer), |
snprintf(buffer, sizeof(buffer), |
| 290 |
"\033[1;44;33m第\033[32m%ld\033[33m-\033[32m%ld\033[33m行 (\033[32m%ld%%\033[33m) │ " |
"\033[1;44;33m第\033[32m%ld\033[33m-\033[32m%ld\033[33m行 (\033[32m%ld%%\033[33m) %s", |
|
"返回[\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] │", |
|
| 291 |
line_current - (line - 1) + 1, |
line_current - (line - 1) + 1, |
| 292 |
MIN(line_current - (line - 1) + (SCREEN_ROWS - 2), line_total), |
MIN(line_current - (line - 1) + (SCREEN_ROWS - 2), line_total), |
| 293 |
percentile); |
percentile, msg_ext); |
| 294 |
|
|
| 295 |
len = split_line(buffer, SCREEN_COLS, &eol, &display_len); |
len = split_line(buffer, SCREEN_COLS, &eol, &display_len); |
| 296 |
for (;display_len < SCREEN_COLS; display_len++) |
for (; display_len < SCREEN_COLS; display_len++) |
| 297 |
{ |
{ |
| 298 |
buffer[len++] = ' '; |
buffer[len++] = ' '; |
| 299 |
} |
} |
| 309 |
{ |
{ |
| 310 |
ch = igetch_t(MAX_DELAY_TIME); |
ch = igetch_t(MAX_DELAY_TIME); |
| 311 |
input_ok = 1; |
input_ok = 1; |
| 312 |
|
|
| 313 |
|
// extended key handler |
| 314 |
|
if (key_handler(&ch, msg_ext, sizeof(msg_ext)) != 0) |
| 315 |
|
{ |
| 316 |
|
goto cleanup; |
| 317 |
|
} |
| 318 |
|
|
| 319 |
switch (ch) |
switch (ch) |
| 320 |
{ |
{ |
| 321 |
case KEY_NULL: |
case KEY_NULL: |
| 329 |
break; |
break; |
| 330 |
case KEY_END: |
case KEY_END: |
| 331 |
line_current = line_total - (SCREEN_ROWS - 2); |
line_current = line_total - (SCREEN_ROWS - 2); |
| 332 |
|
if (line_current < 0) |
| 333 |
|
{ |
| 334 |
|
line_current = 0; |
| 335 |
|
} |
| 336 |
line = begin_line; |
line = begin_line; |
| 337 |
max_lines = SCREEN_ROWS - 1; |
max_lines = SCREEN_ROWS - 1; |
| 338 |
clrline(begin_line, SCREEN_ROWS); |
clrline(begin_line, SCREEN_ROWS); |
| 396 |
loop = 0; |
loop = 0; |
| 397 |
break; |
break; |
| 398 |
case 'h': |
case 'h': |
| 399 |
if (!show_help) |
if (!show_help) // Not reentrant |
| 400 |
{ |
{ |
| 401 |
break; |
break; |
| 402 |
} |
} |
| 403 |
|
|
| 404 |
// Display help information |
// Display help information |
| 405 |
show_help = 0; |
show_help = 0; |
| 406 |
display_file(DATA_READ_HELP, begin_line, 1); |
display_file(help_filename, begin_line, 1); |
| 407 |
show_help = 1; |
show_help = 1; |
| 408 |
|
case KEY_F5: |
| 409 |
// Refresh after display help information |
// Refresh after display help information |
| 410 |
line_current -= (line - 1); |
line_current -= (line - 1); |
| 411 |
line = begin_line; |
line = begin_line; |
| 412 |
max_lines = SCREEN_ROWS - 1; |
max_lines = SCREEN_ROWS - 1; |
| 413 |
clrline(begin_line, SCREEN_ROWS); |
clrline(begin_line, SCREEN_ROWS); |
| 414 |
break; |
break; |
| 415 |
|
case 0: // Refresh bottom line |
| 416 |
|
break; |
| 417 |
default: |
default: |
| 418 |
input_ok = 0; |
input_ok = 0; |
| 419 |
break; |
break; |
| 447 |
return ch; |
return ch; |
| 448 |
} |
} |
| 449 |
|
|
| 450 |
int display_file(const char *filename, int begin_line, int wait) |
static int display_file_key_handler(int *key, char *msg, size_t msg_len) |
| 451 |
{ |
{ |
| 452 |
int ch = KEY_NULL; |
switch (*key) |
| 453 |
|
{ |
| 454 |
|
case 0: // Set msg |
| 455 |
|
snprintf(msg, msg_len, |
| 456 |
|
"| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] │ " |
| 457 |
|
"移动[\033[32m↑\033[33m/\033[32m↓\033[33m/\033[32mPgUp\033[33m/\033[32mPgDn\033[33m] │ " |
| 458 |
|
"帮助[\033[32mh\033[33m] |"); |
| 459 |
|
break; |
| 460 |
|
case 'H': |
| 461 |
|
*key = 'h'; |
| 462 |
|
return 0; |
| 463 |
|
} |
| 464 |
|
|
| 465 |
|
return 0; |
| 466 |
|
} |
| 467 |
|
|
| 468 |
|
int display_file(const char *filename, int begin_line, int eof_exit) |
| 469 |
|
{ |
| 470 |
|
int ret; |
| 471 |
const void *p_shm; |
const void *p_shm; |
| 472 |
size_t data_len; |
size_t data_len; |
| 473 |
long line_total; |
long line_total; |
| 480 |
return KEY_NULL; |
return KEY_NULL; |
| 481 |
} |
} |
| 482 |
|
|
| 483 |
ch = display_data(p_data, line_total, p_line_offsets, begin_line, wait); |
ret = display_data(p_data, line_total, p_line_offsets, begin_line, eof_exit, display_file_key_handler, DATA_READ_HELP); |
| 484 |
|
|
| 485 |
if (detach_file_shm(p_shm) < 0) |
if (detach_file_shm(p_shm) < 0) |
| 486 |
{ |
{ |
| 487 |
log_error("detach_file_shm(%s) error\n", filename); |
log_error("detach_file_shm(%s) error\n", filename); |
| 488 |
} |
} |
| 489 |
|
|
| 490 |
return ch; |
return ret; |
| 491 |
} |
} |
| 492 |
|
|
| 493 |
int show_top(const char *str_left, const char *str_middle, const char *str_right) |
int show_top(const char *str_left, const char *str_middle, const char *str_right) |