From 9ffe33a27a8720aba2f066fef0b0bdb3efcbea72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Javier=20Merino=20Mor=C3=A1n?= Date: Thu, 25 Feb 2021 18:56:42 +0100 Subject: [PATCH] Fix appending characters at end of line in double width lines Since double-width/double-height lines have room for just half the characters, take that into account. Can be tested with: perl -E '$r=join "", map{$_%10}1..80; say "\e<\e[?40h\e[?3l\e[?7h$r"; $s="L"."X"x38 ."RL"; say "\e#6$s"' The above tests that appending characters to double-width lines in DECAWM (Auto Wrap Mode) wraps at the correct last column. There should appear a second line (single-width) with a single "L". perl -E '$r=join "", map{$_%10}1..80; say "\e<\e[?40h\e[?3l\e[?7l$r"; $s="L"."X"x42 ." TEST FAILED OUTOFBOUNDS R"; say "\e#6$s"' The above tests that appending characters to double-width lines in non-DECAWM (Auto Wrap Mode) doesn't write past the last column (visible on repaints - switch to another window and back). The last column (below columns 79 and 80 of prev line) should have an "R". --- src/Screen.cpp | 15 +++++++++++++-- src/Screen.h | 4 ++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Screen.cpp b/src/Screen.cpp index 78d6df4b..00f1d63e 100644 --- a/src/Screen.cpp +++ b/src/Screen.cpp @@ -716,6 +716,17 @@ QVector Screen::getLineProperties(int startLine , int endLine) con return result; } +int Screen::getScreenLineColumns(const int line) const +{ + const int doubleWidthLine = _lineProperties[line] & LINE_DOUBLEWIDTH; + + if (doubleWidthLine) { + return _columns / 2; + } + + return _columns; +} + void Screen::reset() { // Clear screen, but preserve the current line @@ -891,12 +902,12 @@ void Screen::displayCharacter(uint c) return; } - if (_cuX + w > _columns) { + if (_cuX + w > getScreenLineColumns(_cuY)) { if (getMode(MODE_Wrap)) { _lineProperties[_cuY] = static_cast(_lineProperties[_cuY] | LINE_WRAPPED); nextLine(); } else { - _cuX = qMax(_columns - w, 0); + _cuX = qMax(getScreenLineColumns(_cuY) - w, 0); } } diff --git a/src/Screen.h b/src/Screen.h index f6052d4f..0927851d 100644 --- a/src/Screen.h +++ b/src/Screen.h @@ -666,6 +666,10 @@ private: int getLineLength(const int line) const; + // returns the width in columns of the specified screen line, + // taking DECDWL/DECDHL (double width/height modes) into account. + int getScreenLineColumns(const int line) const; + // screen image ---------------- int _lines; int _columns;