summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2020-03-24 20:57:56 +1100
committerMaxime Coste <mawww@kakoune.org>2021-07-12 10:25:58 +1000
commit65fbabcb867f0267f8bcf763b8047735d378a3fb (patch)
tree3edb310a20ba70bb5c4b1600666811f673680a5d /src
parent5c3b0b750306473a7aa90feb235c3c41e726b492 (diff)
Fix another display corruption issue in the terminal output code
Diffstat (limited to 'src')
-rw-r--r--src/terminal_ui.cc35
1 files changed, 17 insertions, 18 deletions
diff --git a/src/terminal_ui.cc b/src/terminal_ui.cc
index 998116bc..300abaa3 100644
--- a/src/terminal_ui.cc
+++ b/src/terminal_ui.cc
@@ -189,52 +189,51 @@ void TerminalUI::Screen::output(bool force)
}
};
- struct Change { int pos; int add; int del; };
+ struct Change { int keep; int add; int del; };
Vector<Change> changes{Change{}};
auto new_hashes = lines | transform([](auto& line) { return hash_value(line.atoms); }) | gather<Vector>();
for_each_diff(hashes.begin(), hashes.size(),
new_hashes.begin(), new_hashes.size(),
- [&, pos=0](DiffOp op, int len) mutable {
+ [&changes](DiffOp op, int len) mutable {
switch (op)
{
case DiffOp::Keep:
- pos += len;
- if (changes.back().add != 0 || changes.back().del != 0)
- changes.push_back({pos, 0, 0});
+ changes.push_back({len, 0, 0});
break;
case DiffOp::Add:
- if (changes.back().add == 0 && changes.back().del == 0)
- changes.back().pos = pos;
changes.back().add += len;
- pos += len;
break;
case DiffOp::Remove:
- if (changes.back().add == 0 && changes.back().del == 0)
- changes.back().pos = pos;
changes.back().del += len;
break;
}
});
hashes = std::move(new_hashes);
- int offset = 0;
+ int line = 0;
for (auto& change : changes)
{
- if (change.del > change.add)
- printf("\033[%dH\033[%dM", change.pos - offset + 1, change.del - change.add);
- offset += change.add - change.del;
+ line += change.keep;
+ if (int del = std::max(change.del - change.add, 0); del > 0)
+ {
+ printf("\033[%dH\033[%dM", line + 1, del);
+ line -= del;
+ }
+ line += change.del;
}
+ line = 0;
for (auto& change : changes)
{
+ line += change.keep;
for (int i = 0; i < change.add; ++i)
{
- if (i == 0 and change.add > change.del)
- printf("\033[%dH\033[%dL", change.pos + 1, change.add - change.del);
+ if (int add = std::max(0, change.add - change.del); i == 0 and add > 0)
+ printf("\033[%dH\033[%dL", line + 1, add);
else
- printf("\033[%dH", change.pos + i + 1);
+ printf("\033[%dH", line + 1);
- for (auto& atom : lines[change.pos + i].atoms)
+ for (auto& atom : lines[line++].atoms)
{
fputs("\033[", stdout);
set_attributes(atom.face.attributes);