Author: koen.aers(a)jboss.com
Date: 2011-09-21 08:04:49 -0400 (Wed, 21 Sep 2011)
New Revision: 34924
Modified:
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/io/ForgeAnsiCommandFilter.java
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/ForgeTextViewer.java
Log:
JBIDE-9759
Modified:
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/io/ForgeAnsiCommandFilter.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/io/ForgeAnsiCommandFilter.java 2011-09-21
07:54:11 UTC (rev 34923)
+++
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/io/ForgeAnsiCommandFilter.java 2011-09-21
12:04:49 UTC (rev 34924)
@@ -50,7 +50,9 @@
private boolean isAnsiEnd(char c) {
return c == 'G' ||
c == 'K' ||
- c == 'm';
+ c == 'm' ||
+ c == 'H' ||
+ c == 'J';
}
}
Modified:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/ForgeTextViewer.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/ForgeTextViewer.java 2011-09-21
07:54:11 UTC (rev 34923)
+++
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/ForgeTextViewer.java 2011-09-21
12:04:49 UTC (rev 34924)
@@ -28,7 +28,9 @@
private static String BACKSPACE = new Character('\b').toString();
private static String UP_ARROW = new Character((char)16).toString();
private static String DOWN_ARROW = new Character((char)14).toString();
-
+ private static String LEFT_ARROW = new Character((char)2).toString();
+ private static String RIGHT_ARROW = new Character((char)6).toString();
+
private class RuntimeStopListener implements PropertyChangeListener {
@Override
public void propertyChange(PropertyChangeEvent evt) {
@@ -43,13 +45,15 @@
@Override
public void keyPressed(KeyEvent e) {
if (e.keyCode == SWT.BS) {
- handleBackspace();
+ runtime.sendInput(BACKSPACE);
} else if (e.keyCode == SWT.ARROW_UP) {
- handleArrowUp();
+ runtime.sendInput(UP_ARROW);
} else if (e.keyCode == SWT.ARROW_DOWN) {
- handleArrowDown();
- } else if (e.keyCode == SWT.F1) {
- handleF1Down();
+ runtime.sendInput(DOWN_ARROW);
+ } else if (e.keyCode == SWT.ARROW_LEFT) {
+ runtime.sendInput(LEFT_ARROW);
+ } else if (e.keyCode == SWT.ARROW_RIGHT) {
+ runtime.sendInput(RIGHT_ARROW);
}
}
@Override
@@ -81,7 +85,10 @@
private ForgeOutputListener outputListener;
private ForgeRuntime runtime;
private ForgeDocument document;
+ private StyleRange currentStyleRange = null;
+
+
public ForgeTextViewer(Composite parent, ForgeRuntime runtime) {
super(parent, SWT.WRAP | SWT.V_SCROLL | SWT.H_SCROLL);
this.runtime = runtime;
@@ -95,7 +102,7 @@
initOutputListener();
initStopListener();
}
-
+
private void initDocument() {
document = new ForgeDocument();
document.addDocumentListener(new DocumentListener());
@@ -166,38 +173,43 @@
e.doit = false;
}
- private void handleBackspace() {
- runtime.sendInput(BACKSPACE);
+ protected void handleVerifyKeyEvent(VerifyEvent e) {
+ if (e.keyCode == SWT.BS) {
+ runtime.sendInput(BACKSPACE);
+ e.doit = false;
+ } else if (e.keyCode == SWT.ARROW_UP) {
+ runtime.sendInput(UP_ARROW);
+ e.doit = false;
+ } else if (e.keyCode == SWT.ARROW_DOWN) {
+ runtime.sendInput(DOWN_ARROW);
+ e.doit = false;
+ } else if (e.keyCode == SWT.ARROW_LEFT) {
+ runtime.sendInput(LEFT_ARROW);
+ e.doit = false;
+ } else if (e.keyCode == SWT.ARROW_RIGHT) {
+ runtime.sendInput(RIGHT_ARROW);
+ e.doit = false;
+ }
}
-
- private void handleArrowUp() {
- runtime.sendInput(UP_ARROW);
- }
-
- private void handleArrowDown() {
- runtime.sendInput(DOWN_ARROW);
- }
-
- private void handleF1Down() {
- runtime.sendInput(new Character((char)31).toString() + "hidden
command!\n");
- }
-
+
private void executeAnsiCommand(final String command) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
char c = command.charAt(command.length() - 1);
switch (c) {
- case 'G' : moveCursorAbsolute(command); break;
+ case 'G' : moveCursorAbsoluteInLine(command); break;
case 'K' : clearCurrentLine(command); break;
case 'm' : changeColor(command); break;
+ case 'H' : setCursorPosition(command); break;
+ case 'J' : clearCurrentScreenPage(command); break;
default : ForgeUIPlugin.log(new RuntimeException("Unhandled Ansi control
sequence in ForgeTextViewer: "+ command));
}
}
});
}
- private void moveCursorAbsolute(final String command) {
+ private void moveCursorAbsoluteInLine(final String command) {
try {
int column = Integer.valueOf(command.substring(2, command.length() - 1));
int lineStart =
document.getLineOffset(document.getLineOfOffset(getTextWidget().getCaretOffset()));
@@ -216,8 +228,6 @@
}
}
- private StyleRange currentStyleRange = null;
-
private void changeColor(String command) {
String str = command.substring(2, command.length() - 1);
Color newColor = null;
@@ -245,4 +255,28 @@
}
}
+ private void setCursorPosition(String command) {
+ String str = command.substring(2, command.length() - 1);
+ int i = str.indexOf(';');
+ int line = 0, column = 0;
+ if (i != -1) {
+ line = Integer.valueOf(str.substring(0, i));
+ column = Integer.valueOf(str.substring(i + 1));
+ } else if (str.length() > 0) {
+ line = Integer.valueOf(str);
+ }
+ StyledText textWidget = getTextWidget();
+ int offset = textWidget.getOffsetAtLine(line);
+ int maxColumn = textWidget.getLine(line).length();
+ offset += Math.min(maxColumn, column);
+ getTextWidget().setCaretOffset(offset);
+ }
+
+ private void clearCurrentScreenPage(String command) {
+ String str = command.substring(2, command.length() - 1);
+ if ("2".equals(str)) {
+ getDocument().set("");
+ }
+ }
+
}
Show replies by date