Print only relevant lines while inserting/deleting lines

This commit is contained in:
Matúš Púll 2025-04-07 21:05:05 +02:00
parent 5642cfc408
commit aa2f6e2260

View file

@ -51,19 +51,25 @@ bool save(string filename) {
}
// Print line
void print_line(int pos) {
// Clear line
void clear_line(int pos) {
move(pos, 0);
clrtoeol();
}
// Print line
void print_line(int pos) {
clear_line(pos);
move(pos, 0);
adds(get_line(pos));
move(row, col);
}
// Print file content
void print_file() {
clear();
for(int i = 0; i < LINES && file_offset+i < file.size(); i++)
void print_file(int start = 0) {
for(int i = start; i < LINES; i++)
if(file_offset+i < file.size())
print_line(i);
else
clear_line(i);
move(row, col);
}
@ -153,7 +159,7 @@ int main(int argc, char* argv[]) {
break;
case 'd':
remove_line(row);
print_file();
print_file(row);
break;
case 'x':
remove_char(row, col);
@ -161,7 +167,7 @@ int main(int argc, char* argv[]) {
break;
case 'o':
add_line(row);
print_file();
print_file(row);
break;
case 'q':
run = false;