Skip to content

Commit d0129a1

Browse files
committed
Implement basic Terminal Debug View. See
#161
1 parent 4aaa02a commit d0129a1

File tree

8 files changed

+225
-67
lines changed

8 files changed

+225
-67
lines changed

eclipse/terminal/ts.eclipse.ide.terminal.interpreter.tests/src/ts/eclipse/ide/terminal/interpreter/TrackerTest.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@
1919
*/
2020
public class TrackerTest extends CommandTerminalTracker {
2121

22-
static {
23-
CommandTerminalTracker.DEBUG = false;
24-
}
25-
2622
private final String userHome;
2723
private final StringBuilder result;
2824

eclipse/terminal/ts.eclipse.ide.terminal.interpreter/plugin.properties

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,7 @@ interpreter.del.name=Interpret 'del' commands to refresh the Project Explorer.
1818
interpreter.rd.name=Interpret 'rd' commands to refresh the Project Explorer.
1919

2020
# Local Terminal - Interpreter
21-
terminal.interpreter.name=Local Terminal (Interpreter)
21+
terminal.interpreter.name=Local Terminal (Interpreter)
22+
23+
# Command Terminal Debug
24+
CommandTerminalDebugView.name=Terminal Debug

eclipse/terminal/ts.eclipse.ide.terminal.interpreter/plugin.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,12 @@
5555
class="ts.eclipse.ide.terminal.interpreter.internal.commands.RdCommandInterpreterFactory">
5656
</factory>
5757
</extension>
58+
59+
<extension point="org.eclipse.ui.views">
60+
<view id="com.example.myplugin.view"
61+
name="%CommandTerminalDebugView.name"
62+
class="ts.eclipse.ide.terminal.interpreter.internal.view.CommandTerminalDebugView"
63+
/>
64+
</extension>
65+
5866
</plugin>

eclipse/terminal/ts.eclipse.ide.terminal.interpreter/src/ts/eclipse/ide/terminal/interpreter/CommandTerminalService.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package ts.eclipse.ide.terminal.interpreter;
22

3+
import java.util.ArrayList;
34
import java.util.HashMap;
45
import java.util.List;
56
import java.util.Map;
@@ -17,8 +18,11 @@ public class CommandTerminalService extends TerminalService {
1718

1819
private final Map<String, TerminalConnectorWrapper> connectors;
1920

21+
private final List<ICommandInterpreterListener> listeners;
22+
2023
public CommandTerminalService() {
2124
this.connectors = new HashMap<>();
25+
this.listeners = new ArrayList<>();
2226
}
2327

2428
public static CommandTerminalService getInstance() {
@@ -91,4 +95,22 @@ public void unregisterConnector(TerminalConnectorWrapper connector) {
9195
}
9296
}
9397

98+
public void addCommandTerminalListener(ICommandInterpreterListener listener) {
99+
synchronized (listeners) {
100+
if (!listeners.contains(listener)) {
101+
listeners.add(listener);
102+
}
103+
}
104+
}
105+
106+
public void removeCommandTerminalListener(ICommandInterpreterListener listener) {
107+
synchronized (listeners) {
108+
listeners.remove(listener);
109+
}
110+
}
111+
112+
public List<ICommandInterpreterListener> getInterpreterListeners() {
113+
return listeners;
114+
}
115+
94116
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Copyright (c) 2015-2017 Angelo ZERR.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Angelo Zerr <[email protected]> - initial API and implementation
10+
*/
11+
package ts.eclipse.ide.terminal.interpreter;
12+
13+
/**
14+
* Command interpreter listener.
15+
*
16+
*/
17+
public interface ICommandInterpreterListener {
18+
19+
void onOpenTerminal(String initialWorkingDir, String initialCommand, String userHome);
20+
21+
void onProcessText(String text, int columns);
22+
23+
void onCarriageReturnLineFeed();
24+
25+
}

eclipse/terminal/ts.eclipse.ide.terminal.interpreter/src/ts/eclipse/ide/terminal/interpreter/ICommandTerminalListener.java

Lines changed: 0 additions & 13 deletions
This file was deleted.

eclipse/terminal/ts.eclipse.ide.terminal.interpreter/src/ts/eclipse/ide/terminal/interpreter/internal/CommandTerminalTracker.java

Lines changed: 22 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
import java.io.File;
1515

16+
import ts.eclipse.ide.terminal.interpreter.CommandTerminalService;
17+
import ts.eclipse.ide.terminal.interpreter.ICommandInterpreterListener;
18+
1619
/**
1720
* Command terminal tracker.
1821
*
@@ -21,8 +24,6 @@ public abstract class CommandTerminalTracker extends AnsiHandler {
2124

2225
private static final String TILD = "~";
2326

24-
public static boolean DEBUG = false;
25-
2627
private final String initialWorkingDir;
2728
private final String initialCommand;
2829
private LineCommand lineCommand;
@@ -34,9 +35,7 @@ public CommandTerminalTracker(String initialWorkingDir, String initialCommand) {
3435
this.initialWorkingDir = initialWorkingDir;
3536
this.initialCommand = initialCommand;
3637
this.columns = 80;
37-
if (DEBUG) {
38-
traceTrackerTest(initialWorkingDir, initialCommand, getUserHome());
39-
}
38+
onOpenTerminal(initialWorkingDir, initialCommand, getUserHome());
4039
}
4140

4241
@Override
@@ -45,9 +44,7 @@ protected void processText(String text) {
4544
}
4645

4746
protected void processText(String text, int columns) {
48-
if (DEBUG) {
49-
traceProcessText(text, columns);
50-
}
47+
onProcessText(text, columns);
5148
processLine(text);
5249
}
5350

@@ -56,9 +53,7 @@ protected void processCarriageReturnLineFeed() {
5653
// CRLF is thrown when:
5754
// - User types 'Enter' to submit a command.
5855
// - OR in Windows OS, when a new line is displayed in the DOS Command.
59-
if (DEBUG) {
60-
traceProcessCarriageReturnLineFeed();
61-
}
56+
onCarriageReturnLineFeed();
6257
if (lineCommand == null) {
6358
// Line command was not found in the terminal, ignore the CR event.
6459
return;
@@ -174,7 +169,7 @@ private boolean updateLineCommand(String line) {
174169
}
175170
if (state == LineCommandState.SUBMITTED) {
176171
// Case when command is terminated.
177-
this.newWorkingDir = resolveTild(workinDir);
172+
this.newWorkingDir = resolveTild(workinDir);
178173
this.terminate();
179174
} else {
180175
// Case when user is typing a command, update it.
@@ -231,13 +226,13 @@ private LineCommand tryToCreateLineCommand(String line, String initialWorkingDir
231226
(initialCommandIndex != -1 ? initialCommandIndex : line.length())).trim();
232227
return new LineCommand(initialWorkingDir, initialCommand, beforeWorkingDir, afterWorkingDir);
233228
}
234-
235-
private String resolveTild(String line) {
229+
230+
private String resolveTild(String line) {
236231
if (line.contains(TILD)) {
237232
String home = getUserHome();
238233
return line.replaceFirst("^~", home);
239234
}
240-
return line;
235+
return line;
241236
}
242237

243238
protected String getUserHome() {
@@ -251,50 +246,28 @@ protected String getUserHome() {
251246

252247
// ---------------------- Trace to generate JUnit
253248

254-
private void traceTrackerTest(String initialWorkingDir, String initialCommand, String userHome) {
255-
StringBuilder code = new StringBuilder("TrackerTest test = new TrackerTest(");
256-
if (initialWorkingDir == null) {
257-
code.append("null");
258-
} else {
259-
code.append("\"");
260-
code.append(initialWorkingDir.replaceAll("[\"]", "\\\"").replaceAll("\\\\", "\\\\\\\\"));
261-
code.append("\"");
262-
}
263-
code.append(", ");
264-
if (initialCommand == null) {
265-
code.append("null");
266-
} else {
267-
code.append("\"");
268-
code.append(initialCommand.replaceAll("[\"]", "\\\"").replaceAll("\\\\", "\\\\\\\\"));
269-
code.append("\"");
249+
private void onOpenTerminal(String initialWorkingDir, String initialCommand, String userHome) {
250+
for (ICommandInterpreterListener listener : CommandTerminalService.getInstance().getInterpreterListeners()) {
251+
listener.onOpenTerminal(initialWorkingDir, initialCommand, userHome);
270252
}
271-
code.append(", ");
272-
code.append("\"");
273-
code.append(userHome);
274-
code.append("\"");
275-
code.append(");");
276-
System.err.println(code.toString());
277253
}
278254

279-
private void traceProcessText(String text, int columns) {
280-
StringBuilder code = new StringBuilder("test.processText(");
281-
code.append("\"");
282-
code.append(text.replaceAll("[\"]", "\\\"").replaceAll("\\\\", "\\\\\\\\"));
283-
code.append("\", ");
284-
code.append(columns);
285-
code.append(");");
286-
System.err.println(code.toString());
255+
private void onProcessText(String text, int columns) {
256+
for (ICommandInterpreterListener listener : CommandTerminalService.getInstance().getInterpreterListeners()) {
257+
listener.onProcessText(text, columns);
258+
}
287259
}
288260

289-
private void traceProcessCarriageReturnLineFeed() {
290-
StringBuilder code = new StringBuilder("test.processCarriageReturnLineFeed();");
291-
System.err.println(code.toString());
261+
private void onCarriageReturnLineFeed() {
262+
for (ICommandInterpreterListener listener : CommandTerminalService.getInstance().getInterpreterListeners()) {
263+
listener.onCarriageReturnLineFeed();
264+
}
292265
}
293266

294267
public void setColumns(int columns) {
295268
this.columns = columns;
296269
}
297-
270+
298271
private static String rtrim(String s) {
299272
int i = s.length() - 1;
300273
while (i >= 0 && Character.isWhitespace(s.charAt(i))) {

0 commit comments

Comments
 (0)