From 6ca055bb25abfd1232279e696e8c573ec67ed927 Mon Sep 17 00:00:00 2001 From: Fredrik Fornwall Date: Thu, 25 Feb 2016 16:33:00 +0100 Subject: [PATCH] Fix tabs to not overwrite cells --- app/build.gradle | 4 +-- .../com/termux/terminal/TerminalEmulator.java | 31 ++++++++++--------- .../termux/terminal/CursorAndScreenTest.java | 7 ++++- .../com/termux/terminal/TerminalTest.java | 5 +++ 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index e5bed900..6cde3610 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -18,8 +18,8 @@ android { applicationId "com.termux" minSdkVersion 21 targetSdkVersion 23 - versionCode 29 - versionName "0.29" + versionCode 30 + versionName "0.30" } buildTypes { diff --git a/app/src/main/java/com/termux/terminal/TerminalEmulator.java b/app/src/main/java/com/termux/terminal/TerminalEmulator.java index 94d2807d..f3cb0456 100644 --- a/app/src/main/java/com/termux/terminal/TerminalEmulator.java +++ b/app/src/main/java/com/termux/terminal/TerminalEmulator.java @@ -425,9 +425,9 @@ public final class TerminalEmulator { processCodePoint((codePoint & 0x7F) + 0x40); } else { switch (Character.getType(codePoint)) { - case Character.UNASSIGNED: - case Character.SURROGATE: - codePoint = UNICODE_REPLACEMENT_CHAR; + case Character.UNASSIGNED: + case Character.SURROGATE: + codePoint = UNICODE_REPLACEMENT_CHAR; } processCodePoint(codePoint); } @@ -474,16 +474,19 @@ public final class TerminalEmulator { else mSession.onBell(); break; - case 8: // BS - setCursorCol(Math.max(mLeftMargin, mCursorCol - 1)); - break; - case 9: // Horizontal tab - move to next tab stop, but not past edge of screen - int nextTabStop = nextTabStop(1); - while (mCursorCol < nextTabStop) { - // Emit newlines to get background color right. - processCodePoint(' '); - } - break; + case 8: // Backspace (BS, ^H). + setCursorCol(Math.max(mLeftMargin, mCursorCol - 1)); + break; + case 9: // Horizontal tab (HT, \t) - move to next tab stop, but not past edge of screen + // XXX: Should perhaps use color if writing to new cells. Try with + // printf "\033[41m\tXX\033[0m\n" + // The OSX Terminal.app colors the spaces from the tab red, but xterm does not. + // Note that Terminal.app only colors on new cells, in e.g. + // printf "\033[41m\t\r\033[42m\tXX\033[0m\n" + // the first cells are created with a red background, but when tabbing over + // them again with a green background they are not overwritten. + mCursorCol = nextTabStop(1); + break; case 10: // Line feed (LF, \n). case 11: // Vertical tab (VT, \v). case 12: // Form feed (FF, \f). @@ -1331,7 +1334,7 @@ public final class TerminalEmulator { continueSequence(ESC_CSI_ARGS_ASTERIX); break; case '@': { - // "CSI{n}@" - Insert ${n} space characters (ICH) - http://www.vt100.net/docs/vt510-rm/ICH. + // "CSI{n}@" - Insert ${n} space characters (ICH) - http://www.vt100.net/docs/vt510-rm/ICH. mAboutToAutoWrap = false; int columnsAfterCursor = mColumns - mCursorCol; int spacesToInsert = Math.min(getArg0(1), columnsAfterCursor); diff --git a/app/src/test/java/com/termux/terminal/CursorAndScreenTest.java b/app/src/test/java/com/termux/terminal/CursorAndScreenTest.java index 0df78fc1..6e39ed19 100644 --- a/app/src/test/java/com/termux/terminal/CursorAndScreenTest.java +++ b/app/src/test/java/com/termux/terminal/CursorAndScreenTest.java @@ -163,7 +163,12 @@ public class CursorAndScreenTest extends TerminalTestCase { } } - public void testHorizontalTabColorsBackground() { + /** + * See comments on horizontal tab handling in TerminalEmulator.java. + * + * We do not want to color already written cells when tabbing over them. + */ + public void DISABLED_testHorizontalTabColorsBackground() { withTerminalSized(10, 3).enterString("\033[48;5;15m").enterString("\t"); assertCursorAt(0, 8); for (int i = 0; i < 10; i++) { diff --git a/app/src/test/java/com/termux/terminal/TerminalTest.java b/app/src/test/java/com/termux/terminal/TerminalTest.java index 9b43676c..f3939cfc 100644 --- a/app/src/test/java/com/termux/terminal/TerminalTest.java +++ b/app/src/test/java/com/termux/terminal/TerminalTest.java @@ -258,4 +258,9 @@ public class TerminalTest extends TerminalTestCase { withTerminalSized(3, 3).enterString("abc\r ").assertLinesAre(" bc", " ", " ").assertCursorAt(0, 1); } + public void testTab() { + withTerminalSized(11, 2).enterString("01234567890\r\tXX").assertLinesAre("01234567XX0", " "); + withTerminalSized(11, 2).enterString("01234567890\033[44m\r\tXX").assertLinesAre("01234567XX0", " "); + } + }