Skip to content

Commit 42f025b

Browse files
committed
Add support for launching Eclipse Process in a system terminal session
Currently processes are launched as a forked process without a terminal session attached to them. Some features of processes require a terminal session (e.g. autocompletion) and currently not work when running from within eclipse (e.g. the gogo-shell). This is an bring terminal session support to Eclipse to support real terminal application similar to what is supported by IntelliJ.
1 parent a02997e commit 42f025b

16 files changed

+523
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21"/>
4+
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
5+
<classpathentry kind="src" path="src"/>
6+
<classpathentry kind="output" path="bin"/>
7+
</classpath>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>org.eclipse.debug.terminal</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.pde.ManifestBuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>org.eclipse.pde.SchemaBuilder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
<buildCommand>
24+
<name>org.eclipse.pde.ds.core.builder</name>
25+
<arguments>
26+
</arguments>
27+
</buildCommand>
28+
</buildSpec>
29+
<natures>
30+
<nature>org.eclipse.pde.PluginNature</nature>
31+
<nature>org.eclipse.jdt.core.javanature</nature>
32+
</natures>
33+
</projectDescription>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
eclipse.preferences.version=1
2+
encoding/<project>=UTF-8
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=21
3+
org.eclipse.jdt.core.compiler.compliance=21
4+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
5+
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
6+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
7+
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
8+
org.eclipse.jdt.core.compiler.release=enabled
9+
org.eclipse.jdt.core.compiler.source=21
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
dsVersion=V1_4
2+
eclipse.preferences.version=1
3+
enabled=true
4+
generateBundleActivationPolicyLazy=true
5+
path=OSGI-INF
6+
validationErrorLevel=error
7+
validationErrorLevel.missingImplicitUnbindMethod=error
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Manifest-Version: 1.0
2+
Bundle-ManifestVersion: 2
3+
Bundle-Name: Terminal Session Support for Eclipse
4+
Bundle-SymbolicName: org.eclipse.debug.terminal;singleton:=true
5+
Bundle-Version: 1.0.0.qualifier
6+
Require-Bundle: org.eclipse.core.runtime,
7+
org.eclipse.debug.core;bundle-version="3.23.0",
8+
org.eclipse.tm.terminal.control;bundle-version="5.6.0",
9+
org.eclipse.cdt.core.native;bundle-version="6.4.0",
10+
org.eclipse.swt;bundle-version="3.130.0",
11+
org.eclipse.ui;bundle-version="3.207.100"
12+
Bundle-RequiredExecutionEnvironment: JavaSE-21
13+
Automatic-Module-Name: org.eclipse.debug.terminal
14+
Bundle-ActivationPolicy: lazy
15+
Service-Component: OSGI-INF/org.eclipse.debug.terminal.ui.PageBookAdapter.xml
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.4.0" name="org.eclipse.debug.terminal.ui.PageBookAdapter">
3+
<property name="adaptableClass" type="String" value="org.eclipse.debug.terminal.PtyRuntimeProcess"/>
4+
<property name="adapterNames" type="String" value="org.eclipse.ui.part.IPageBookViewPage"/>
5+
<service>
6+
<provide interface="org.eclipse.core.runtime.IAdapterFactory"/>
7+
</service>
8+
<implementation class="org.eclipse.debug.terminal.ui.PageBookAdapter"/>
9+
</scr:component>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
source.. = src/
2+
output.. = bin/
3+
bin.includes = META-INF/,\
4+
.,\
5+
plugin.xml,\
6+
OSGI-INF/org.eclipse.debug.terminal.ui.PageBookAdapter.xml
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<?eclipse version="3.4"?>
3+
<plugin>
4+
<extension
5+
point="org.eclipse.debug.core.execFactories">
6+
<execFactory
7+
class="org.eclipse.debug.terminal.PtyExecFactory"
8+
id="org.eclipse.debug.terminal.execFactory"
9+
priority="100">
10+
</execFactory>
11+
</extension>
12+
<extension
13+
point="org.eclipse.debug.core.processFactories">
14+
<processFactory
15+
class="org.eclipse.debug.terminal.PtyProcessFactory"
16+
id="org.eclipse.debug.terminal.processFactory">
17+
</processFactory>
18+
</extension>
19+
20+
</plugin>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 Christoph Läubrich and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* Christoph Läubrich - initial API and implementation
13+
*******************************************************************************/
14+
package org.eclipse.debug.terminal;
15+
16+
import java.io.File;
17+
import java.io.IOException;
18+
import java.util.Map;
19+
import java.util.Optional;
20+
21+
import org.eclipse.cdt.utils.pty.PTY;
22+
import org.eclipse.cdt.utils.pty.PTY.Mode;
23+
import org.eclipse.cdt.utils.spawner.ProcessFactory;
24+
import org.eclipse.core.runtime.CoreException;
25+
import org.eclipse.core.runtime.Status;
26+
import org.eclipse.debug.core.ExecFactory;
27+
28+
public class PtyExecFactory implements ExecFactory {
29+
30+
@Override
31+
public Optional<Process> exec(String[] cmdLine, Optional<File> workingDirectory,
32+
Optional<Map<String, String>> environment, boolean mergeOutput) throws CoreException {
33+
if (mergeOutput || !PTY.isSupported(Mode.TERMINAL)) {
34+
return Optional.empty();
35+
}
36+
try {
37+
PTY pty = new PTY(Mode.TERMINAL);
38+
pty.setTerminalSize(80, 24);
39+
String[] env;
40+
if (environment.isEmpty()) {
41+
env = null;
42+
} else {
43+
env = environment.stream().flatMap(m -> m.entrySet().stream()).map(e -> e.getKey() + "=" + e.getValue())
44+
.toArray(String[]::new);
45+
}
46+
File wd = workingDirectory.orElse(null);
47+
return Optional.of(ProcessFactory.getFactory().exec(cmdLine, env, wd, pty));
48+
} catch (IOException e) {
49+
throw new CoreException(Status.error("Execution failed", e));
50+
}
51+
}
52+
53+
}

0 commit comments

Comments
 (0)