Print only relevant lines while inserting/deleting lines
This commit is contained in:
parent
5642cfc408
commit
aa2f6e2260
1 changed files with 14 additions and 8 deletions
22
main.cpp
22
main.cpp
|
@ -51,19 +51,25 @@ bool save(string filename) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Print line
|
// Clear line
|
||||||
void print_line(int pos) {
|
void clear_line(int pos) {
|
||||||
move(pos, 0);
|
move(pos, 0);
|
||||||
clrtoeol();
|
clrtoeol();
|
||||||
|
}
|
||||||
|
// Print line
|
||||||
|
void print_line(int pos) {
|
||||||
|
clear_line(pos);
|
||||||
move(pos, 0);
|
move(pos, 0);
|
||||||
adds(get_line(pos));
|
adds(get_line(pos));
|
||||||
move(row, col);
|
move(row, col);
|
||||||
}
|
}
|
||||||
// Print file content
|
// Print file content
|
||||||
void print_file() {
|
void print_file(int start = 0) {
|
||||||
clear();
|
for(int i = start; i < LINES; i++)
|
||||||
for(int i = 0; i < LINES && file_offset+i < file.size(); i++)
|
if(file_offset+i < file.size())
|
||||||
print_line(i);
|
print_line(i);
|
||||||
|
else
|
||||||
|
clear_line(i);
|
||||||
move(row, col);
|
move(row, col);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,7 +159,7 @@ int main(int argc, char* argv[]) {
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
remove_line(row);
|
remove_line(row);
|
||||||
print_file();
|
print_file(row);
|
||||||
break;
|
break;
|
||||||
case 'x':
|
case 'x':
|
||||||
remove_char(row, col);
|
remove_char(row, col);
|
||||||
|
@ -161,7 +167,7 @@ int main(int argc, char* argv[]) {
|
||||||
break;
|
break;
|
||||||
case 'o':
|
case 'o':
|
||||||
add_line(row);
|
add_line(row);
|
||||||
print_file();
|
print_file(row);
|
||||||
break;
|
break;
|
||||||
case 'q':
|
case 'q':
|
||||||
run = false;
|
run = false;
|
||||||
|
|
Loading…
Reference in a new issue