| 126 |
|
|
| 127 |
memcpy(p_editor_data->p_display_lines[i], p_data + line_offsets[i], (size_t)p_editor_data->display_line_lengths[i]); |
memcpy(p_editor_data->p_display_lines[i], p_data + line_offsets[i], (size_t)p_editor_data->display_line_lengths[i]); |
| 128 |
current_data_line_length += p_editor_data->display_line_lengths[i]; |
current_data_line_length += p_editor_data->display_line_lengths[i]; |
| 129 |
|
|
| 130 |
|
// Trim \n from last line |
| 131 |
|
if (i + 1 == p_editor_data->display_line_total && |
| 132 |
|
p_editor_data->display_line_lengths[i] > 0 && |
| 133 |
|
p_editor_data->p_display_lines[i][p_editor_data->display_line_lengths[i] - 1] == '\n') |
| 134 |
|
{ |
| 135 |
|
p_editor_data->display_line_lengths[i]--; |
| 136 |
|
current_data_line_length--; |
| 137 |
|
} |
| 138 |
p_data_line[current_data_line_length] = '\0'; |
p_data_line[current_data_line_length] = '\0'; |
| 139 |
} |
} |
| 140 |
|
|
| 404 |
|
|
| 405 |
if (*p_offset >= p_editor_data->display_line_lengths[*p_display_line]) |
if (*p_offset >= p_editor_data->display_line_lengths[*p_display_line]) |
| 406 |
{ |
{ |
| 407 |
*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 |
|
| 408 |
{ |
{ |
| 409 |
|
*p_offset -= p_editor_data->display_line_lengths[*p_display_line]; |
| 410 |
(*p_display_line)++; |
(*p_display_line)++; |
| 411 |
} |
} |
| 412 |
} |
} |
| 473 |
} |
} |
| 474 |
} |
} |
| 475 |
|
|
| 476 |
|
if (offset_data_line >= len_data_line) // end-of-line |
| 477 |
|
{ |
| 478 |
|
return 0; |
| 479 |
|
} |
| 480 |
|
|
| 481 |
// Check str to be deleted |
// Check str to be deleted |
| 482 |
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) |
| 483 |
{ |
{ |
| 489 |
} |
} |
| 490 |
else |
else |
| 491 |
{ |
{ |
| 492 |
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", |
| 493 |
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]); |
|
| 494 |
str_len = 1; |
str_len = 1; |
| 495 |
} |
} |
| 496 |
|
|
| 560 |
|
|
| 561 |
*p_last_updated_line = display_line + MIN(i, split_line_total - 1); |
*p_last_updated_line = display_line + MIN(i, split_line_total - 1); |
| 562 |
|
|
| 563 |
if (display_line + i < last_display_line) |
if (*p_last_updated_line < last_display_line) |
| 564 |
{ |
{ |
| 565 |
// Remove redundant display line after last_display_line |
// Remove redundant display line after last_display_line |
| 566 |
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++) |
| 567 |
{ |
{ |
| 568 |
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]; |
| 569 |
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]; |
| 570 |
} |
} |
| 571 |
|
|
| 572 |
(p_editor_data->display_line_total) -= (last_display_line - (display_line + i)); |
j = p_editor_data->display_line_total; |
| 573 |
last_display_line = display_line + i; |
(p_editor_data->display_line_total) -= (last_display_line - *p_last_updated_line); |
| 574 |
|
*p_last_updated_line = MAX(j - 1, *p_last_updated_line); |
|
*p_last_updated_line = p_editor_data->display_line_total - 1; |
|
| 575 |
} |
} |
| 576 |
|
|
| 577 |
return str_len; |
return str_len; |
| 583 |
{ |
{ |
| 584 |
case 0: // Set msg |
case 0: // Set msg |
| 585 |
snprintf(p_ctx->msg, sizeof(p_ctx->msg), |
snprintf(p_ctx->msg, sizeof(p_ctx->msg), |
| 586 |
"| Í˳ö[\033[32mCtrl-C\033[33m] | °ïÖú[\033[32mh\033[33m] |"); |
"| Í˳ö[\033[32mCtrl-W\033[33m] | °ïÖú[\033[32mh\033[33m] |"); |
| 587 |
break; |
break; |
| 588 |
} |
} |
| 589 |
|
|
| 746 |
{ |
{ |
| 747 |
if (ch == BACKSPACE) |
if (ch == BACKSPACE) |
| 748 |
{ |
{ |
| 749 |
|
if (line_current - output_current_row + row_pos <= 0 && col_pos <= 1) // Forbidden |
| 750 |
|
{ |
| 751 |
|
input_ok = 0; |
| 752 |
|
continue; |
| 753 |
|
} |
| 754 |
|
|
| 755 |
col_pos--; |
col_pos--; |
| 756 |
if (col_pos < 1 && line_current - output_current_row + row_pos >= 0) |
if (col_pos < 1 && line_current - output_current_row + row_pos >= 0) |
| 757 |
{ |
{ |
| 802 |
row_pos += scroll_rows; |
row_pos += scroll_rows; |
| 803 |
output_current_row = screen_begin_row; |
output_current_row = screen_begin_row; |
| 804 |
output_end_row = SCREEN_ROWS - 1; |
output_end_row = SCREEN_ROWS - 1; |
|
clrline(output_current_row, SCREEN_ROWS); |
|
| 805 |
} |
} |
| 806 |
|
|
| 807 |
|
clrline(output_current_row, output_end_row); |
| 808 |
} |
} |
| 809 |
|
|
| 810 |
continue; |
continue; |
| 815 |
case KEY_NULL: |
case KEY_NULL: |
| 816 |
case KEY_TIMEOUT: |
case KEY_TIMEOUT: |
| 817 |
goto cleanup; |
goto cleanup; |
| 818 |
case Ctrl('C'): |
case Ctrl('W'): |
| 819 |
loop = 0; |
loop = 0; |
| 820 |
break; |
break; |
| 821 |
case Ctrl('S'): // Start of line |
case Ctrl('S'): // Start of line |
| 833 |
break; |
break; |
| 834 |
case Ctrl('B'): // Bottom of screen |
case Ctrl('B'): // Bottom of screen |
| 835 |
case KEY_CTRL_DOWN: |
case KEY_CTRL_DOWN: |
| 836 |
row_pos = SCREEN_ROWS - 1; |
if (p_editor_data->display_line_total < screen_row_total) |
| 837 |
col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - output_current_row + row_pos])); |
{ |
| 838 |
|
row_pos = p_editor_data->display_line_total; |
| 839 |
|
} |
| 840 |
|
else |
| 841 |
|
{ |
| 842 |
|
row_pos = SCREEN_ROWS - 1; |
| 843 |
|
} |
| 844 |
|
if (line_current + (screen_row_total - (output_current_row - screen_begin_row)) >= p_editor_data->display_line_total) // Reach end |
| 845 |
|
{ |
| 846 |
|
// last display line does NOT have \n in the end |
| 847 |
|
col_pos = MIN(col_pos, p_editor_data->display_line_lengths[line_current - output_current_row + row_pos] + 1); |
| 848 |
|
} |
| 849 |
|
else |
| 850 |
|
{ |
| 851 |
|
col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - output_current_row + row_pos])); |
| 852 |
|
} |
| 853 |
break; |
break; |
| 854 |
case KEY_INS: |
case KEY_INS: |
| 855 |
key_insert = !key_insert; |
key_insert = !key_insert; |
| 870 |
if (p_editor_data->display_line_total < screen_row_total) |
if (p_editor_data->display_line_total < screen_row_total) |
| 871 |
{ |
{ |
| 872 |
row_pos = p_editor_data->display_line_total; |
row_pos = p_editor_data->display_line_total; |
| 873 |
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; |
| 874 |
break; |
break; |
| 875 |
} |
} |
| 876 |
line_current = p_editor_data->display_line_total - screen_row_total; |
line_current = p_editor_data->display_line_total - screen_row_total; |
| 877 |
output_current_row = screen_begin_row; |
output_current_row = screen_begin_row; |
| 878 |
output_end_row = SCREEN_ROWS - 1; |
output_end_row = SCREEN_ROWS - 1; |
| 879 |
row_pos = SCREEN_ROWS - 1; |
row_pos = SCREEN_ROWS - 1; |
| 880 |
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; |
| 881 |
clrline(output_current_row, SCREEN_ROWS); |
clrline(output_current_row, SCREEN_ROWS); |
| 882 |
break; |
break; |
| 883 |
case KEY_LEFT: |
case KEY_LEFT: |
| 924 |
} |
} |
| 925 |
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 |
| 926 |
{ |
{ |
| 927 |
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 |
| 928 |
|
col_pos = p_editor_data->display_line_lengths[line_current - output_current_row + row_pos] + 1; |
| 929 |
break; |
break; |
| 930 |
} |
} |
| 931 |
line_current += (screen_row_total - (output_current_row - screen_begin_row)); |
line_current += (screen_row_total - (output_current_row - screen_begin_row)); |