Skip to content

Commit 5c7f96e

Browse files
author
angelozerr
committed
Clean endCommand.
1 parent b735488 commit 5c7f96e

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

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

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void onContentReadFromStream(byte[] byteBuffer, int bytesRead) {
6767
if (processingCommand) {
6868
// Enter was done
6969
if (cmd == null) {
70-
endCommand();
70+
endCommand(null);
7171
} else {
7272
// Initialize interpreter if needed
7373
if (interpreter == null) {
@@ -82,34 +82,25 @@ public void onContentReadFromStream(byte[] byteBuffer, int bytesRead) {
8282
}
8383
}
8484

85-
List<String> l = lines.getLines();
8685
String lastLine = lines.getLastLine();
87-
if (isEndCommand(lastLine)) {
88-
for (int i = 0; i < l.size() - 1; i++) {
89-
interpreter.onTrace(l.get(i));
90-
}
91-
boolean workingDirChanged = !this.lineInput.equals(lastLine);
92-
if (workingDirChanged) {
93-
String workingDir = getWorkingDir(lineInput);
94-
List<String> parameters = getParameters(cmdWithParameters);
95-
new CdCommandInterpreter(parameters, workingDir).execute();
96-
}
97-
endCommand();
98-
this.lineInput = lastLine;
86+
if (isEndCommand(lastLine)) {
87+
trace(lines.getLines(), 1);
88+
endCommand(lastLine);
9989
} else {
100-
for (String line : lines.getLines()) {
101-
interpreter.onTrace(line);
102-
}
90+
trace(lines.getLines(), 0);
10391
}
10492
}
10593
} else {
106-
// Terminal was opened, get the last lines which is the working
107-
// dir.
94+
// Terminal was opened, get the last lines which is the line
95+
// input : "workingDir" concat with ('>' for Windows, '$' for
96+
// Linux)
10897
if (lineInput == null) {
10998
this.lineInput = lines.getLastLine();
11099
if (lineInput != null) {
111100
String originalWorkingDir = getOriginalWorkingDir();
112101
if (lineInput.startsWith(originalWorkingDir)) {
102+
// retrieve the character used for line input ('>'
103+
// for Windows, '$' for Linux)
113104
this.workingDirEnd = lineInput.substring(originalWorkingDir.length(), lineInput.length());
114105
}
115106
}
@@ -132,6 +123,12 @@ public void onContentReadFromStream(byte[] byteBuffer, int bytesRead) {
132123
}
133124
}
134125

126+
private void trace(List<String> lines, int index) {
127+
for (int i = 0; i < lines.size() - index; i++) {
128+
interpreter.onTrace(lines.get(i));
129+
}
130+
}
131+
135132
private boolean isEndCommand(String line) {
136133
if (line == null) {
137134
return false;
@@ -150,10 +147,19 @@ private boolean isEndCommand(String line) {
150147
}
151148
}
152149

153-
private void endCommand() {
150+
private void endCommand(String lastLine) {
154151
if (interpreter != null) {
155152
interpreter.execute();
156153
}
154+
if (lastLine != null) {
155+
boolean workingDirChanged = !this.lineInput.equals(lastLine);
156+
if (workingDirChanged) {
157+
String workingDir = getWorkingDir(lineInput);
158+
List<String> parameters = getParameters(cmdWithParameters);
159+
new CdCommandInterpreter(parameters, workingDir).execute();
160+
}
161+
this.lineInput = lastLine;
162+
}
157163
processingCommand = false;
158164
cmd = null;
159165
cmdWithParameters = null;

0 commit comments

Comments
 (0)