From 0d0d522b889ce86860abb229c7cdd4d0299b1127 Mon Sep 17 00:00:00 2001 From: that Date: Tue, 14 Mar 2017 20:58:08 +0100 Subject: gui: fix line wrapping in terminal, issue #876 Apparently we are supposed to delay going to the next line until the next character is printed. Change-Id: I5cd0cc128cc00dcdd0dd2dd9508281f1249db257 --- gui/terminal.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/gui/terminal.cpp b/gui/terminal.cpp index fe80fb097..1744788da 100644 --- a/gui/terminal.cpp +++ b/gui/terminal.cpp @@ -389,6 +389,7 @@ public: lines.clear(); setY(0); unpackLine(0); + linewrap = false; ++updateCounter; } @@ -465,6 +466,7 @@ public: { x = min(width, max(x, 0)); cursorX = x; + linewrap = false; ++updateCounter; } @@ -473,6 +475,7 @@ public: //y = min(height, max(y, 0)); y = max(y, 0); cursorY = y; + linewrap = false; while (lines.size() <= (size_t) y) lines.push_back(Line()); ++updateCounter; @@ -581,21 +584,20 @@ private: void processChar(CodePoint cp) { + if (linewrap) { + down(); + setX(0); + } ensureUnpacked(cursorY); // extend unpackedLine if needed, write ch into cell if (unpackedLine.cells.size() <= (size_t)cursorX) unpackedLine.cells.resize(cursorX+1); unpackedLine.cells[cursorX].cp = cp; - right(); + right(); // also bumps updateCounter + if (cursorX >= width) - { - // TODO: configurable line wrapping - // TODO: don't go down immediately but only on next char? - down(); - setX(0); - } - // TODO: update all GUI objects that display this terminal engine + linewrap = true; } void processEsc(CodePoint cp) @@ -744,6 +746,7 @@ private: private: int cursorX, cursorY; // 0-based, char based. TODO: decide how to handle scrollback + bool linewrap; // true to put next character into next line int width, height; // window size in chars std::vector lines; // the text buffer UnpackedLine unpackedLine; // current line for editing -- cgit v1.2.3