Fix crash with wide character in last column

Ignore wide character outputs instead of crashing when the cursor
is in the last column with autowrap disabled.
This commit is contained in:
Fredrik Fornwall
2015-11-29 10:04:50 +01:00
parent 4ccc703fcf
commit b54c7909bd
2 changed files with 22 additions and 7 deletions

View File

@@ -2156,15 +2156,22 @@ public final class TerminalEmulator {
final boolean autoWrap = isDecsetInternalBitSet(DECSET_BIT_AUTOWRAP); final boolean autoWrap = isDecsetInternalBitSet(DECSET_BIT_AUTOWRAP);
final int displayWidth = WcWidth.width(codePoint); final int displayWidth = WcWidth.width(codePoint);
final boolean cursorInLastColumn = mCursorCol == mRightMargin - 1;
if (autoWrap && (mCursorCol == mRightMargin - 1 && ((mAboutToAutoWrap && displayWidth == 1) || displayWidth == 2))) { if (autoWrap) {
mScreen.setLineWrap(mCursorRow); if (cursorInLastColumn && ((mAboutToAutoWrap && displayWidth == 1) || displayWidth == 2)) {
mCursorCol = mLeftMargin; mScreen.setLineWrap(mCursorRow);
if (mCursorRow + 1 < mBottomMargin) { mCursorCol = mLeftMargin;
mCursorRow++; if (mCursorRow + 1 < mBottomMargin) {
} else { mCursorRow++;
scrollDownOneLine(); } else {
scrollDownOneLine();
}
} }
} else if (cursorInLastColumn && displayWidth == 2) {
// The behaviour when a wide character is output with cursor in the last column when
// autowrap is disabled is not obvious - it's ignored here.
return;
} }
if (mInsertMode && displayWidth > 0) { if (mInsertMode && displayWidth > 0) {

View File

@@ -84,4 +84,12 @@ public class UnicodeInputTest extends TerminalTestCase {
assertLineIs(0, "\uFFFDY "); assertLineIs(0, "\uFFFDY ");
} }
public void testWideCharacterWithoutWrapping() throws Exception {
// With wraparound disabled. The behaviour when a wide character is output with cursor in
// the last column when autowrap is disabled is not obvious, but we expect the wide
// character to be ignored here.
withTerminalSized(3, 3).enterString("\033[?7l").enterString("枝枝枝").assertLinesAre("", " ", " ");
enterString("a枝").assertLinesAre("枝a", " ", " ");
}
} }