From a1a63a3c31d55bda9863e175fda7df24889a7e4c Mon Sep 17 00:00:00 2001 From: Anton Leherbauer Date: Mon, 26 Jan 2015 10:12:06 +0100 Subject: [PATCH] Bug 458218 - [terminal] Add support for ANSI insert mode Change-Id: Iee022b7326da07d3df2b04144416e324f7e73496 Signed-off-by: Anton Leherbauer --- .../emulator/VT100EmulatorBackendTest.java | 25 +++++++++++++- .../emulator/IVT100EmulatorBackend.java | 15 +++++++-- .../emulator/VT100BackendTraceDecorator.java | 8 ++++- .../terminal/emulator/VT100Emulator.java | 33 ++++++++++++++++++- .../emulator/VT100EmulatorBackend.java | 10 +++++- 5 files changed, 85 insertions(+), 6 deletions(-) diff --git a/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/emulator/VT100EmulatorBackendTest.java b/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/emulator/VT100EmulatorBackendTest.java index a7b83e988ca..9ed477ffa51 100644 --- a/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/emulator/VT100EmulatorBackendTest.java +++ b/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/emulator/VT100EmulatorBackendTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2014 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2015 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 @@ -9,6 +9,7 @@ * Michael Scharf (Wind River) - initial API and implementation * Martin Oberhuber (Wind River) - [168197] Fix Terminal for CDC-1.1/Foundation-1.1 * Anton Leherbauer (Wind River) - [453393] Add support for copying wrapped lines without line break + * Anton Leherbauer (Wind River) - [458218] Add support for ANSI insert mode *******************************************************************************/ package org.eclipse.tm.internal.terminal.emulator; @@ -1284,4 +1285,26 @@ public class VT100EmulatorBackendTest extends TestCase { assertFalse(term.isWrappedLine(2)); assertTrue(term.isWrappedLine(3)); } + + public void testInsertMode() { + ITerminalTextData term=makeITerminalTextData(); + IVT100EmulatorBackend vt100=makeBakend(term); + term.setMaxHeight(10); + vt100.setDimensions(4, 6); + // replace mode + vt100.appendString("123"); + vt100.setCursorColumn(0); + vt100.appendString("abc"); + assertEquals("abc", new String(term.getChars(0))); + vt100.clearAll(); + // insert mode + vt100.setCursorColumn(0); + vt100.appendString("123"); + vt100.setCursorColumn(0); + vt100.setInsertMode(true); + vt100.appendString("abc"); + vt100.setInsertMode(false); + assertEquals("abc123", new String(term.getChars(0))); + } + } 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 b3604a2c7d2..ef38f82e0a0 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, 2014 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2015 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,11 +8,16 @@ * Contributors: * Michael Scharf (Wind River) - initial API and implementation * Anton Leherbauer (Wind River) - [433751] Add option to enable VT100 line wrapping mode + * Anton Leherbauer (Wind River) - [458218] Add support for ANSI insert mode *******************************************************************************/ package org.eclipse.tm.internal.terminal.emulator; import org.eclipse.tm.terminal.model.Style; +/** + * @author toni + * + */ public interface IVT100EmulatorBackend { /** @@ -186,4 +191,10 @@ public interface IVT100EmulatorBackend { */ boolean isVT100LineWrapping(); -} \ No newline at end of file + /** + * Enables/disables insert mode (IRM). + * + * @param enable whether to enable insert mode + */ + void setInsertMode(boolean enable); +} 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 0c914a54339..c108986e1a8 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, 2014 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2015 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) - [433751] Add option to enable VT100 line wrapping mode + * Anton Leherbauer (Wind River) - [458218] Add support for ANSI insert mode *******************************************************************************/ package org.eclipse.tm.internal.terminal.emulator; @@ -151,4 +152,9 @@ public class VT100BackendTraceDecorator implements IVT100EmulatorBackend { return fBackend.isVT100LineWrapping(); } + public void setInsertMode(boolean enable) { + fWriter.println("setInsertMode("+enable+")"); //$NON-NLS-1$ //$NON-NLS-2$ + fBackend.setInsertMode(enable); + } + } 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 83674515868..6a66ee51425 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, 2014 Wind River Systems, Inc. and others. + * Copyright (c) 2003, 2015 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 @@ -21,6 +21,7 @@ * 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 + * Anton Leherbauer (Wind River) - [458218] Add support for ANSI insert mode *******************************************************************************/ package org.eclipse.tm.internal.terminal.emulator; @@ -476,6 +477,11 @@ public class VT100Emulator implements ControlListener { processAnsiCommand_H(); break; + case 'h': + // Reset Mode. + processAnsiCommand_h(); + break; + case 'J': // Erase part or all of display. Cursor does not move. processAnsiCommand_J(); @@ -491,6 +497,11 @@ public class VT100Emulator implements ControlListener { processAnsiCommand_L(); break; + case 'l': + // Set Mode. + processAnsiCommand_l(); + break; + case 'M': // Delete line(s). processAnsiCommand_M(); @@ -620,6 +631,16 @@ public class VT100Emulator implements ControlListener { moveCursor(getAnsiParameter(0) - 1, getAnsiParameter(1) - 1); } + /** + * This method sets terminal modes. + */ + private void processAnsiCommand_h() { + if (getAnsiParameter(0) == 4) { + // set insert mode + text.setInsertMode(true); + } + } + /** * This method deletes some (or all) of the text on the screen without * moving the cursor. @@ -694,6 +715,16 @@ public class VT100Emulator implements ControlListener { text.insertLines(getAnsiParameter(0)); } + /** + * This method resets terminal modes. + */ + private void processAnsiCommand_l() { + if (getAnsiParameter(0) == 4) { + // reset insert mode + text.setInsertMode(false); + } + } + /** * Delete one or more lines of text. Any lines below the deleted lines move * up, which we implement by appending newlines to the end of the text. 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 47b78f68436..2387d20f666 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, 2014 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2015 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 @@ -9,6 +9,7 @@ * 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 + * Anton Leherbauer (Wind River) - [458218] Add support for ANSI insert mode *******************************************************************************/ package org.eclipse.tm.internal.terminal.emulator; @@ -54,6 +55,7 @@ public class VT100EmulatorBackend implements IVT100EmulatorBackend { /* true if last output occurred on rightmost column * and next output requires line wrap */ private boolean fWrapPending; + private boolean fInsertMode; private Style fDefaultStyle; private Style fStyle; int fLines; @@ -289,6 +291,8 @@ public class VT100EmulatorBackend implements IVT100EmulatorBackend { public void appendString(String buffer) { synchronized (fTerminal) { char[] chars=buffer.toCharArray(); + if (fInsertMode) + insertCharacters(chars.length); int line=toAbsoluteLine(fCursorLine); int i=0; while (i < chars.length) { @@ -432,4 +436,8 @@ public class VT100EmulatorBackend implements IVT100EmulatorBackend { public boolean isVT100LineWrapping() { return fVT100LineWrapping; } + + public void setInsertMode(boolean enable) { + fInsertMode = enable; + } }