| 395 |
|
|
| 396 |
if (*p_offset >= p_editor_data->display_line_lengths[*p_display_line]) |
if (*p_offset >= p_editor_data->display_line_lengths[*p_display_line]) |
| 397 |
{ |
{ |
| 398 |
*p_offset -= p_editor_data->display_line_lengths[*p_display_line]; |
if (*p_display_line + 1 < p_editor_data->display_line_total) |
|
|
|
|
if (*p_display_line + 1 >= p_editor_data->display_line_total) |
|
|
{ |
|
|
log_error("*p_display_line(%d) >= display_line_total(%d)\n", *p_display_line, p_editor_data->display_line_total); |
|
|
} |
|
|
else |
|
| 399 |
{ |
{ |
| 400 |
|
*p_offset -= p_editor_data->display_line_lengths[*p_display_line]; |
| 401 |
(*p_display_line)++; |
(*p_display_line)++; |
| 402 |
} |
} |
| 403 |
} |
} |
| 464 |
} |
} |
| 465 |
} |
} |
| 466 |
|
|
| 467 |
|
if (offset_data_line >= len_data_line) // end-of-line |
| 468 |
|
{ |
| 469 |
|
return 0; |
| 470 |
|
} |
| 471 |
|
|
| 472 |
// Check str to be deleted |
// Check str to be deleted |
| 473 |
if (p_data_line[offset_data_line] > 0 && p_data_line[offset_data_line] < 127) |
if (p_data_line[offset_data_line] > 0 && p_data_line[offset_data_line] < 127) |
| 474 |
{ |
{ |
| 480 |
} |
} |
| 481 |
else |
else |
| 482 |
{ |
{ |
| 483 |
log_error("Some strange character at display_line %ld, offset %ld: %d %d %d %d\n", |
log_error("Some strange character at display_line %ld, offset %ld: %d %d\n", |
| 484 |
display_line, offset, p_data_line[offset_data_line], p_data_line[offset_data_line + 1], |
display_line, offset, p_data_line[offset_data_line], p_data_line[offset_data_line + 1]); |
|
p_data_line[offset_data_line + 2], p_data_line[offset_data_line + 3]); |
|
| 485 |
str_len = 1; |
str_len = 1; |
| 486 |
} |
} |
| 487 |
|
|
| 551 |
|
|
| 552 |
*p_last_updated_line = display_line + MIN(i, split_line_total - 1); |
*p_last_updated_line = display_line + MIN(i, split_line_total - 1); |
| 553 |
|
|
| 554 |
if (display_line + i < last_display_line) |
if (*p_last_updated_line < last_display_line) |
| 555 |
{ |
{ |
| 556 |
// Remove redundant display line after last_display_line |
// Remove redundant display line after last_display_line |
| 557 |
for (j = last_display_line + 1; j < p_editor_data->display_line_total; j++) |
for (j = last_display_line + 1; j < p_editor_data->display_line_total; j++) |
| 558 |
{ |
{ |
| 559 |
p_editor_data->p_display_lines[j - (last_display_line - (display_line + i))] = p_editor_data->p_display_lines[j]; |
p_editor_data->p_display_lines[j - (last_display_line - *p_last_updated_line)] = p_editor_data->p_display_lines[j]; |
| 560 |
p_editor_data->display_line_lengths[j - (last_display_line - (display_line + i))] = p_editor_data->display_line_lengths[j]; |
p_editor_data->display_line_lengths[j - (last_display_line - *p_last_updated_line)] = p_editor_data->display_line_lengths[j]; |
| 561 |
} |
} |
| 562 |
|
|
| 563 |
(p_editor_data->display_line_total) -= (last_display_line - (display_line + i)); |
j = p_editor_data->display_line_total; |
| 564 |
last_display_line = display_line + i; |
(p_editor_data->display_line_total) -= (last_display_line - *p_last_updated_line); |
| 565 |
|
*p_last_updated_line = MAX(j - 1, *p_last_updated_line); |
|
*p_last_updated_line = p_editor_data->display_line_total - 1; |
|
| 566 |
} |
} |
| 567 |
|
|
| 568 |
return str_len; |
return str_len; |
| 574 |
{ |
{ |
| 575 |
case 0: // Set msg |
case 0: // Set msg |
| 576 |
snprintf(p_ctx->msg, sizeof(p_ctx->msg), |
snprintf(p_ctx->msg, sizeof(p_ctx->msg), |
| 577 |
"| Í˳ö[\033[32mCtrl-C\033[33m] | °ïÖú[\033[32mh\033[33m] |"); |
"| Í˳ö[\033[32mCtrl-W\033[33m] | °ïÖú[\033[32mh\033[33m] |"); |
| 578 |
break; |
break; |
| 579 |
} |
} |
| 580 |
|
|
| 737 |
{ |
{ |
| 738 |
if (ch == BACKSPACE) |
if (ch == BACKSPACE) |
| 739 |
{ |
{ |
| 740 |
|
if (line_current - output_current_row + row_pos <= 0 && col_pos <= 1) // Forbidden |
| 741 |
|
{ |
| 742 |
|
input_ok = 0; |
| 743 |
|
continue; |
| 744 |
|
} |
| 745 |
|
|
| 746 |
col_pos--; |
col_pos--; |
| 747 |
if (col_pos < 1 && line_current - output_current_row + row_pos >= 0) |
if (col_pos < 1 && line_current - output_current_row + row_pos >= 0) |
| 748 |
{ |
{ |
| 793 |
row_pos += scroll_rows; |
row_pos += scroll_rows; |
| 794 |
output_current_row = screen_begin_row; |
output_current_row = screen_begin_row; |
| 795 |
output_end_row = SCREEN_ROWS - 1; |
output_end_row = SCREEN_ROWS - 1; |
|
clrline(output_current_row, SCREEN_ROWS); |
|
| 796 |
} |
} |
| 797 |
|
|
| 798 |
|
clrline(output_current_row, output_end_row); |
| 799 |
} |
} |
| 800 |
|
|
| 801 |
continue; |
continue; |
| 806 |
case KEY_NULL: |
case KEY_NULL: |
| 807 |
case KEY_TIMEOUT: |
case KEY_TIMEOUT: |
| 808 |
goto cleanup; |
goto cleanup; |
| 809 |
case Ctrl('C'): |
case Ctrl('W'): |
| 810 |
loop = 0; |
loop = 0; |
| 811 |
break; |
break; |
| 812 |
case Ctrl('S'): // Start of line |
case Ctrl('S'): // Start of line |
| 824 |
break; |
break; |
| 825 |
case Ctrl('B'): // Bottom of screen |
case Ctrl('B'): // Bottom of screen |
| 826 |
case KEY_CTRL_DOWN: |
case KEY_CTRL_DOWN: |
| 827 |
row_pos = SCREEN_ROWS - 1; |
if (p_editor_data->display_line_total < screen_row_total) |
| 828 |
col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - output_current_row + row_pos])); |
{ |
| 829 |
|
row_pos = p_editor_data->display_line_total; |
| 830 |
|
} |
| 831 |
|
else |
| 832 |
|
{ |
| 833 |
|
row_pos = SCREEN_ROWS - 1; |
| 834 |
|
} |
| 835 |
|
if (line_current + (screen_row_total - (output_current_row - screen_begin_row)) >= p_editor_data->display_line_total) // Reach end |
| 836 |
|
{ |
| 837 |
|
// last display line does NOT have \n in the end |
| 838 |
|
col_pos = MIN(col_pos, p_editor_data->display_line_lengths[line_current - output_current_row + row_pos] + 1); |
| 839 |
|
} |
| 840 |
|
else |
| 841 |
|
{ |
| 842 |
|
col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - output_current_row + row_pos])); |
| 843 |
|
} |
| 844 |
break; |
break; |
| 845 |
case KEY_INS: |
case KEY_INS: |
| 846 |
key_insert = !key_insert; |
key_insert = !key_insert; |
| 861 |
if (p_editor_data->display_line_total < screen_row_total) |
if (p_editor_data->display_line_total < screen_row_total) |
| 862 |
{ |
{ |
| 863 |
row_pos = p_editor_data->display_line_total; |
row_pos = p_editor_data->display_line_total; |
| 864 |
col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - output_current_row + row_pos]); |
col_pos = p_editor_data->display_line_lengths[line_current - output_current_row + row_pos] + 1; |
| 865 |
break; |
break; |
| 866 |
} |
} |
| 867 |
line_current = p_editor_data->display_line_total - screen_row_total; |
line_current = p_editor_data->display_line_total - screen_row_total; |
| 868 |
output_current_row = screen_begin_row; |
output_current_row = screen_begin_row; |
| 869 |
output_end_row = SCREEN_ROWS - 1; |
output_end_row = SCREEN_ROWS - 1; |
| 870 |
row_pos = SCREEN_ROWS - 1; |
row_pos = SCREEN_ROWS - 1; |
| 871 |
col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - output_current_row + row_pos]); |
col_pos = p_editor_data->display_line_lengths[line_current - output_current_row + row_pos] + 1; |
| 872 |
clrline(output_current_row, SCREEN_ROWS); |
clrline(output_current_row, SCREEN_ROWS); |
| 873 |
break; |
break; |
| 874 |
case KEY_LEFT: |
case KEY_LEFT: |
| 915 |
} |
} |
| 916 |
if (line_current + (screen_row_total - (output_current_row - screen_begin_row)) >= p_editor_data->display_line_total) // Reach end |
if (line_current + (screen_row_total - (output_current_row - screen_begin_row)) >= p_editor_data->display_line_total) // Reach end |
| 917 |
{ |
{ |
| 918 |
col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - output_current_row + row_pos]); |
// last display line does NOT have \n in the end |
| 919 |
|
col_pos = p_editor_data->display_line_lengths[line_current - output_current_row + row_pos] + 1; |
| 920 |
break; |
break; |
| 921 |
} |
} |
| 922 |
line_current += (screen_row_total - (output_current_row - screen_begin_row)); |
line_current += (screen_row_total - (output_current_row - screen_begin_row)); |