Fix another display corruption issue in the terminal output code
This commit is contained in:
parent
5c3b0b7503
commit
65fbabcb86
|
@ -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{}};
|
Vector<Change> changes{Change{}};
|
||||||
auto new_hashes = lines | transform([](auto& line) { return hash_value(line.atoms); }) | gather<Vector>();
|
auto new_hashes = lines | transform([](auto& line) { return hash_value(line.atoms); }) | gather<Vector>();
|
||||||
for_each_diff(hashes.begin(), hashes.size(),
|
for_each_diff(hashes.begin(), hashes.size(),
|
||||||
new_hashes.begin(), new_hashes.size(),
|
new_hashes.begin(), new_hashes.size(),
|
||||||
[&, pos=0](DiffOp op, int len) mutable {
|
[&changes](DiffOp op, int len) mutable {
|
||||||
switch (op)
|
switch (op)
|
||||||
{
|
{
|
||||||
case DiffOp::Keep:
|
case DiffOp::Keep:
|
||||||
pos += len;
|
changes.push_back({len, 0, 0});
|
||||||
if (changes.back().add != 0 || changes.back().del != 0)
|
|
||||||
changes.push_back({pos, 0, 0});
|
|
||||||
break;
|
break;
|
||||||
case DiffOp::Add:
|
case DiffOp::Add:
|
||||||
if (changes.back().add == 0 && changes.back().del == 0)
|
|
||||||
changes.back().pos = pos;
|
|
||||||
changes.back().add += len;
|
changes.back().add += len;
|
||||||
pos += len;
|
|
||||||
break;
|
break;
|
||||||
case DiffOp::Remove:
|
case DiffOp::Remove:
|
||||||
if (changes.back().add == 0 && changes.back().del == 0)
|
|
||||||
changes.back().pos = pos;
|
|
||||||
changes.back().del += len;
|
changes.back().del += len;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
hashes = std::move(new_hashes);
|
hashes = std::move(new_hashes);
|
||||||
|
|
||||||
int offset = 0;
|
int line = 0;
|
||||||
for (auto& change : changes)
|
for (auto& change : changes)
|
||||||
{
|
{
|
||||||
if (change.del > change.add)
|
line += change.keep;
|
||||||
printf("\033[%dH\033[%dM", change.pos - offset + 1, change.del - change.add);
|
if (int del = std::max(change.del - change.add, 0); del > 0)
|
||||||
offset += change.add - change.del;
|
{
|
||||||
|
printf("\033[%dH\033[%dM", line + 1, del);
|
||||||
|
line -= del;
|
||||||
|
}
|
||||||
|
line += change.del;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
line = 0;
|
||||||
for (auto& change : changes)
|
for (auto& change : changes)
|
||||||
{
|
{
|
||||||
|
line += change.keep;
|
||||||
for (int i = 0; i < change.add; ++i)
|
for (int i = 0; i < change.add; ++i)
|
||||||
{
|
{
|
||||||
if (i == 0 and change.add > change.del)
|
if (int add = std::max(0, change.add - change.del); i == 0 and add > 0)
|
||||||
printf("\033[%dH\033[%dL", change.pos + 1, change.add - change.del);
|
printf("\033[%dH\033[%dL", line + 1, add);
|
||||||
else
|
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);
|
fputs("\033[", stdout);
|
||||||
set_attributes(atom.face.attributes);
|
set_attributes(atom.face.attributes);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user