From d5905131ae54731843802b7ac21ad6160a55d29a Mon Sep 17 00:00:00 2001 From: Anton Leherbauer Date: Wed, 30 Apr 2014 11:55:41 +0200 Subject: [PATCH] Terminal: Bug 433751 - Add option to enable VT100 line wrapping mode Change-Id: I6b75db80b8edda518333c6acc59ba461f51932bd Signed-off-by: Anton Leherbauer --- .../TerminalConnectorFactoryTest.java | 10 ++++- .../connector/TerminalConnectorTest.java | 10 ++++- .../emulator/IVT100EmulatorBackend.java | 19 +++++++- .../emulator/VT100BackendTraceDecorator.java | 12 +++++- .../terminal/emulator/VT100Emulator.java | 10 ++++- .../emulator/VT100EmulatorBackend.java | 43 ++++++++++++++++--- .../emulator/VT100TerminalControl.java | 11 ++++- .../provisional/api/ITerminalControl.java | 19 +++++++- 8 files changed, 120 insertions(+), 14 deletions(-) diff --git a/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/connector/TerminalConnectorFactoryTest.java b/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/connector/TerminalConnectorFactoryTest.java index 6a0f6a2dbce..b9c4d3c6a74 100644 --- a/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/connector/TerminalConnectorFactoryTest.java +++ b/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/connector/TerminalConnectorFactoryTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2012 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2014 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,6 +10,7 @@ * Martin Oberhuber (Wind River) - [225853][api] Provide more default functionality in TerminalConnectorImpl * Martin Oberhuber (Wind River) - [204796] Terminal should allow setting the encoding to use * Uwe Stieber (Wind River) - [282996] [terminal][api] Add "hidden" attribute to terminal connector extension point + * Anton Leherbauer (Wind River) - [433751] Add option to enable VT100 line wrapping mode *******************************************************************************/ package org.eclipse.tm.internal.terminal.connector; @@ -83,6 +84,13 @@ public class TerminalConnectorFactoryTest extends TestCase { public void setConnectOnEnterIfClosed(boolean on) { } + + public void setVT100LineWrapping(boolean enable) { + } + + public boolean isVT100LineWrapping() { + return false; + } } static class ConnectorMock extends TerminalConnectorImpl { diff --git a/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/connector/TerminalConnectorTest.java b/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/connector/TerminalConnectorTest.java index 33eadf3089d..10863867a20 100644 --- a/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/connector/TerminalConnectorTest.java +++ b/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/connector/TerminalConnectorTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2012 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2014 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,6 +10,7 @@ * Martin Oberhuber (Wind River) - [225853][api] Provide more default functionality in TerminalConnectorImpl * Martin Oberhuber (Wind River) - [204796] Terminal should allow setting the encoding to use * Uwe Stieber (Wind River) - [282996] [terminal][api] Add "hidden" attribute to terminal connector extension point + * Anton Leherbauer (Wind River) - [433751] Add option to enable VT100 line wrapping mode *******************************************************************************/ package org.eclipse.tm.internal.terminal.connector; @@ -83,6 +84,13 @@ public class TerminalConnectorTest extends TestCase { public void setConnectOnEnterIfClosed(boolean on) { } + + public void setVT100LineWrapping(boolean enable) { + } + + public boolean isVT100LineWrapping() { + return false; + } } static class ConnectorMock extends TerminalConnectorImpl { diff --git a/plugins/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/emulator/IVT100EmulatorBackend.java b/plugins/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/emulator/IVT100EmulatorBackend.java index 362aa26d237..b3604a2c7d2 100644 --- a/plugins/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/emulator/IVT100EmulatorBackend.java +++ b/plugins/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/emulator/IVT100EmulatorBackend.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2014 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * Michael Scharf (Wind River) - initial API and implementation + * Anton Leherbauer (Wind River) - [433751] Add option to enable VT100 line wrapping mode *******************************************************************************/ package org.eclipse.tm.internal.terminal.emulator; @@ -169,4 +170,20 @@ public interface IVT100EmulatorBackend { int getColumns(); + /** + * Enables VT100 line wrapping mode (default is off). + * This corresponds to the VT100 'eat_newline_glitch' terminal capability. + * If enabled, writing to the rightmost column does not cause + * an immediate wrap to the next line. Instead the line wrap occurs on the + * next output character. + * + * @param enable whether to enable or disable VT100 line wrapping mode + */ + void setVT100LineWrapping(boolean enable); + + /** + * @return whether VT100 line wrapping mode is enabled + */ + boolean isVT100LineWrapping(); + } \ No newline at end of file diff --git a/plugins/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/emulator/VT100BackendTraceDecorator.java b/plugins/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/emulator/VT100BackendTraceDecorator.java index c4d57ab98bc..0c914a54339 100644 --- a/plugins/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/emulator/VT100BackendTraceDecorator.java +++ b/plugins/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/emulator/VT100BackendTraceDecorator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2014 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * Michael Scharf (Wind River) - initial API and implementation + * Anton Leherbauer (Wind River) - [433751] Add option to enable VT100 line wrapping mode *******************************************************************************/ package org.eclipse.tm.internal.terminal.emulator; @@ -141,4 +142,13 @@ public class VT100BackendTraceDecorator implements IVT100EmulatorBackend { fBackend.setStyle(style); } + public void setVT100LineWrapping(boolean enable) { + fWriter.println("setVT100LineWrapping("+enable+")"); //$NON-NLS-1$ //$NON-NLS-2$ + fBackend.setVT100LineWrapping(enable); + } + + public boolean isVT100LineWrapping() { + return fBackend.isVT100LineWrapping(); + } + } diff --git a/plugins/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/emulator/VT100Emulator.java b/plugins/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/emulator/VT100Emulator.java index 8aa395d8835..83674515868 100644 --- a/plugins/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/emulator/VT100Emulator.java +++ b/plugins/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/emulator/VT100Emulator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2013 Wind River Systems, Inc. and others. + * Copyright (c) 2003, 2014 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -20,6 +20,7 @@ * Kris De Volder (VMWare) - [392107] Switched interpretation for ESC[0K and ESC[1K sequences * Martin Oberhuber (Wind River) - [401386] Regression: No header on top due to incorrect ESC[K interpretation * Martin Oberhuber (Wind River) - [401480] Handle ESC[39;49m and ESC[G + * Anton Leherbauer (Wind River) - [433751] Add option to enable VT100 line wrapping mode *******************************************************************************/ package org.eclipse.tm.internal.terminal.emulator; @@ -1150,6 +1151,7 @@ public class VT100Emulator implements ControlListener { * Buffer for {@link #pushBackChar(char)}. */ private int fNextChar=-1; + private char getNextChar() throws IOException { int c=-1; if(fNextChar!=-1) { @@ -1189,4 +1191,10 @@ public class VT100Emulator implements ControlListener { public void setCrAfterNewLine(boolean crAfterNewLine) { fCrAfterNewLine = crAfterNewLine; } + void setVT100LineWrapping(boolean enable) { + text.setVT100LineWrapping(enable); + } + boolean isVT100LineWrapping() { + return text.isVT100LineWrapping(); + } } diff --git a/plugins/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/emulator/VT100EmulatorBackend.java b/plugins/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/emulator/VT100EmulatorBackend.java index 3941862adc5..d5958d9c3f6 100644 --- a/plugins/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/emulator/VT100EmulatorBackend.java +++ b/plugins/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/emulator/VT100EmulatorBackend.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2011 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2014 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ * Contributors: * Michael Scharf (Wind River) - initial API and implementation * Anton Leherbauer (Wind River) - [206329] Changing terminal size right after connect does not scroll properly + * Anton Leherbauer (Wind River) - [433751] Add option to enable VT100 line wrapping mode *******************************************************************************/ package org.eclipse.tm.internal.terminal.emulator; @@ -39,19 +40,26 @@ public class VT100EmulatorBackend implements IVT100EmulatorBackend { * When fCursorColumn is N, the next character output to the terminal appears * in column N. When a character is output to the rightmost column on a * given line (column widthInColumns - 1), the cursor moves to column 0 on - * the next line after the character is drawn (this is how line wrapping is - * implemented). If the cursor is in the bottommost line when line wrapping + * the next line after the character is drawn (this is the default line wrapping + * mode). If VT100 line wrapping mode is enabled, the cursor does not move + * to the next line until the next character is printed (this is known as + * the VT100 'eat_newline_glitch'). + * If the cursor is in the bottommost line when line wrapping * occurs, the topmost visible line is scrolled off the top edge of the * screen. *

*/ private int fCursorColumn; private int fCursorLine; + /* true if last output occurred on rightmost column + * and next output requires line wrap */ + private boolean fWrapPending; private Style fDefaultStyle; private Style fStyle; int fLines; int fColumns; final private ITerminalTextData fTerminal; + private boolean fVT100LineWrapping; public VT100EmulatorBackend(ITerminalTextData terminal) { fTerminal=terminal; } @@ -284,15 +292,27 @@ public class VT100EmulatorBackend implements IVT100EmulatorBackend { int line=toAbsoluteLine(fCursorLine); int i=0; while (i < chars.length) { + if(fWrapPending) { + doNewline(); + line=toAbsoluteLine(fCursorLine); + setCursorColumn(0); + } int n=Math.min(fColumns-fCursorColumn,chars.length-i); fTerminal.setChars(line, fCursorColumn, chars, i, n, fStyle); int col=fCursorColumn+n; i+=n; // wrap needed? - if(col>=fColumns) { - doNewline(); - line=toAbsoluteLine(fCursorLine); - setCursorColumn(0); + if(col == fColumns) { + if (fVT100LineWrapping) { + // deferred line wrapping (eat_newline_glitch) + setCursorColumn(col - 1); + fWrapPending = true; + } else { + // immediate line wrapping + doNewline(); + line=toAbsoluteLine(fCursorLine); + setCursorColumn(0); + } } else { setCursorColumn(col); } @@ -357,6 +377,7 @@ public class VT100EmulatorBackend implements IVT100EmulatorBackend { else if(targetColumn>=fColumns) targetColumn=fColumns-1; fCursorColumn=targetColumn; + fWrapPending = false; // We make the assumption that nobody is changing the // terminal cursor except this class! // This assumption gives a huge performance improvement @@ -398,4 +419,12 @@ public class VT100EmulatorBackend implements IVT100EmulatorBackend { return fColumns; } } + + public void setVT100LineWrapping(boolean enable) { + fVT100LineWrapping = enable; + } + + public boolean isVT100LineWrapping() { + return fVT100LineWrapping; + } } diff --git a/plugins/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/emulator/VT100TerminalControl.java b/plugins/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/emulator/VT100TerminalControl.java index 3a0d9618edb..66439ac1892 100644 --- a/plugins/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/emulator/VT100TerminalControl.java +++ b/plugins/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/emulator/VT100TerminalControl.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2012 Wind River Systems, Inc. and others. + * Copyright (c) 2003, 2014 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -32,6 +32,7 @@ * Simon Bernard (Sierra Wireless) - [351424] [terminal] Terminal does not support del and insert key * Martin Oberhuber (Wind River) - [265352][api] Allow setting fonts programmatically * Martin Oberhuber (Wind River) - [378691][api] push Preferences into the Widget + * Anton Leherbauer (Wind River) - [433751] Add option to enable VT100 line wrapping mode *******************************************************************************/ package org.eclipse.tm.internal.terminal.emulator; @@ -1180,6 +1181,14 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC public final boolean isConnectOnEnterIfClosed() { return connectOnEnterIfClosed; } + + public void setVT100LineWrapping(boolean enable) { + getTerminalText().setVT100LineWrapping(enable); + } + + public boolean isVT100LineWrapping() { + return getTerminalText().isVT100LineWrapping(); + } } diff --git a/plugins/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/provisional/api/ITerminalControl.java b/plugins/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/provisional/api/ITerminalControl.java index bf91af569e2..372772cc0c6 100644 --- a/plugins/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/provisional/api/ITerminalControl.java +++ b/plugins/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/provisional/api/ITerminalControl.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2012 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 2014 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,6 +10,7 @@ * Martin Oberhuber (Wind River) - fixed copyright headers and beautified * Martin Oberhuber (Wind River) - [204796] Terminal should allow setting the encoding to use * Martin Oberhuber (Wind River) - [261486][api][cleanup] Mark @noimplement interfaces as @noextend + * Anton Leherbauer (Wind River) - [433751] Add option to enable VT100 line wrapping mode *******************************************************************************/ package org.eclipse.tm.internal.terminal.provisional.api; @@ -140,4 +141,20 @@ public interface ITerminalControl { * @return True the reconnect is enabled, false if disabled. */ boolean isConnectOnEnterIfClosed(); + + /** + * Enables VT100 line wrapping mode (default is off). + * This corresponds to the VT100 'eat_newline_glitch' terminal capability. + * If enabled, writing to the rightmost column does not cause + * an immediate wrap to the next line. Instead the line wrap occurs on the + * next output character. + * + * @param enable whether to enable or disable VT100 line wrapping mode + */ + void setVT100LineWrapping(boolean enable); + + /** + * @return whether VT100 line wrapping mode is enabled + */ + boolean isVT100LineWrapping(); }