Skip to content

Commit 3100182

Browse files
committed
Add support for open a Terminal in the Console View
Currently one needs to create one or more Terminal View instances to open a command prompt or SSH session. With the new Console View Integration it is now possible to offer similar for the Console View to make this more accessible and visible to the users.
1 parent 4fc76e5 commit 3100182

File tree

11 files changed

+161
-26
lines changed

11 files changed

+161
-26
lines changed

debug/org.eclipse.debug.terminal/META-INF/MANIFEST.MF

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ Require-Bundle: org.eclipse.core.runtime,
99
org.eclipse.tm.terminal.control;bundle-version="5.6.0",
1010
org.eclipse.cdt.core.native;bundle-version="[6.4.0,7.0.0)",
1111
org.eclipse.swt;bundle-version="3.130.0",
12-
org.eclipse.ui;bundle-version="3.207.100"
12+
org.eclipse.ui;bundle-version="3.207.100",
13+
org.eclipse.ui.console,
14+
org.eclipse.core.expressions
1315
Bundle-RequiredExecutionEnvironment: JavaSE-21
1416
Bundle-Localization: plugin
1517
Automatic-Module-Name: org.eclipse.debug.terminal

debug/org.eclipse.debug.terminal/build.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ bin.includes = META-INF/,\
66
OSGI-INF/,\
77
about.html,\
88
plugin.properties
9-
src.includes = about.html
9+
src.includes = about.html,\
10+
icons/
452 Bytes
Loading
729 Bytes
Loading

debug/org.eclipse.debug.terminal/plugin.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,13 @@
1616
id="org.eclipse.debug.terminal.processFactory">
1717
</processFactory>
1818
</extension>
19+
<extension
20+
point="org.eclipse.ui.console.consoleFactories">
21+
<consoleFactory
22+
class="org.eclipse.debug.terminal.ui.TerminalConsoleFactory"
23+
icon="icons/console_view.png"
24+
label="Terminal">
25+
</consoleFactory>
26+
</extension>
1927

2028
</plugin>

debug/org.eclipse.debug.terminal/src/org/eclipse/debug/terminal/ui/PageBookAdapter.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@
1313
*******************************************************************************/
1414
package org.eclipse.debug.terminal.ui;
1515

16+
import java.io.IOException;
17+
import java.io.OutputStream;
18+
1619
import org.eclipse.cdt.utils.spawner.Spawner;
1720
import org.eclipse.core.runtime.AdapterTypes;
1821
import org.eclipse.core.runtime.IAdapterFactory;
22+
import org.eclipse.debug.core.model.IBinaryStreamMonitor;
23+
import org.eclipse.debug.core.model.IStreamMonitor;
1924
import org.eclipse.debug.terminal.PtyRuntimeProcess;
2025
import org.eclipse.ui.part.IPageBookViewPage;
2126
import org.osgi.service.component.annotations.Component;
@@ -29,7 +34,19 @@ public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) {
2934
if (adaptableObject instanceof PtyRuntimeProcess rt) {
3035
Spawner spawner = rt.getSpawner();
3136
if (spawner != null) {
32-
return adapterType.cast(new TerminalConsolePage(spawner, rt.getStreamsProxy()));
37+
return adapterType.cast(new TerminalConsolePage(new ConsoleConnector(spawner), terminal -> {
38+
IStreamMonitor streamMonitor = rt.getStreamsProxy().getOutputStreamMonitor();
39+
if (streamMonitor instanceof IBinaryStreamMonitor bin) {
40+
OutputStream outputStream = terminal.getRemoteToTerminalOutputStream();
41+
bin.addBinaryListener((data, monitor) -> {
42+
try {
43+
outputStream.write(data);
44+
} catch (IOException e1) {
45+
e1.printStackTrace();
46+
}
47+
});
48+
}
49+
}));
3350
}
3451
}
3552
return null;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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.ui;
15+
16+
import org.eclipse.tm.internal.terminal.provisional.api.ITerminalConnector;
17+
import org.eclipse.ui.console.AbstractConsole;
18+
import org.eclipse.ui.console.IConsoleView;
19+
import org.eclipse.ui.part.IPageBookViewPage;
20+
21+
class TerminalConsole extends AbstractConsole {
22+
23+
public final static String TYPE = "terminalConsole"; //$NON-NLS-1$
24+
private ITerminalConnector terminalConnector;
25+
26+
TerminalConsole(ITerminalConnector terminalConnector) {
27+
super("Terminal", TYPE, null, true);
28+
this.terminalConnector = terminalConnector;
29+
}
30+
31+
@Override
32+
public IPageBookViewPage createPage(IConsoleView view) {
33+
return new TerminalConsolePage(terminalConnector, null);
34+
}
35+
36+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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.ui;
15+
16+
import java.util.Map;
17+
18+
import org.eclipse.core.commands.Command;
19+
import org.eclipse.core.commands.ParameterizedCommand;
20+
import org.eclipse.core.runtime.ILog;
21+
import org.eclipse.tm.internal.terminal.provisional.api.ITerminalConnector;
22+
import org.eclipse.ui.PlatformUI;
23+
import org.eclipse.ui.commands.ICommandService;
24+
import org.eclipse.ui.console.ConsolePlugin;
25+
import org.eclipse.ui.console.IConsole;
26+
import org.eclipse.ui.console.IConsoleFactory;
27+
import org.eclipse.ui.handlers.IHandlerService;
28+
29+
/**
30+
* A Factory that supports open new Terminal Console.
31+
*/
32+
public class TerminalConsoleFactory implements IConsoleFactory {
33+
34+
@Override
35+
public void openConsole() {
36+
ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class);
37+
IHandlerService handlerService = PlatformUI.getWorkbench().getService(IHandlerService.class);
38+
if (commandService == null || handlerService == null) {
39+
return;
40+
}
41+
Command command = commandService.getCommand("org.eclipse.tm.terminal.view.ui.command.launchConsole");
42+
if (command == null) {
43+
return;
44+
}
45+
ParameterizedCommand parameterizedCommand = ParameterizedCommand.generateCommand(command, Map.of());
46+
try {
47+
Object result = handlerService.executeCommandInContext(parameterizedCommand, null,
48+
handlerService.getCurrentState());
49+
if (result instanceof ITerminalConnector terminalConnector) {
50+
TerminalConsole console = new TerminalConsole(terminalConnector);
51+
ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] { console });
52+
}
53+
} catch (Exception e) {
54+
ILog.get().error("Can't launch terminal console", e);
55+
}
56+
}
57+
58+
}

debug/org.eclipse.debug.terminal/src/org/eclipse/debug/terminal/ui/TerminalConsolePage.java

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,10 @@
1313
*******************************************************************************/
1414
package org.eclipse.debug.terminal.ui;
1515

16-
import java.io.IOException;
17-
import java.io.OutputStream;
1816
import java.nio.charset.Charset;
17+
import java.util.function.Consumer;
1918

20-
import org.eclipse.cdt.utils.spawner.Spawner;
2119
import org.eclipse.core.runtime.IAdaptable;
22-
import org.eclipse.debug.core.model.IBinaryStreamMonitor;
23-
import org.eclipse.debug.core.model.IStreamMonitor;
24-
import org.eclipse.debug.core.model.IStreamsProxy;
2520
import org.eclipse.swt.SWT;
2621
import org.eclipse.swt.layout.FillLayout;
2722
import org.eclipse.swt.widgets.Composite;
@@ -37,15 +32,15 @@
3732

3833
class TerminalConsolePage implements IPageBookViewPage, IAdaptable {
3934

40-
private final Spawner process;
4135
private IPageSite site;
4236
private ITerminalViewControl viewer;
4337
private Composite composite;
44-
private final IStreamsProxy streamsProxy;
38+
private ITerminalConnector connector;
39+
private Consumer<ITerminalControl> terminalControlHandler;
4540

46-
public TerminalConsolePage(Spawner spawner, IStreamsProxy streamsProxy) {
47-
this.process = spawner;
48-
this.streamsProxy = streamsProxy;
41+
public TerminalConsolePage(ITerminalConnector connector, Consumer<ITerminalControl> terminalControlHandler) {
42+
this.connector = connector;
43+
this.terminalControlHandler = terminalControlHandler;
4944
}
5045

5146
@Override
@@ -54,30 +49,23 @@ public void createControl(Composite parent) {
5449
composite.setLayout(new FillLayout());
5550
viewer = TerminalViewControlFactory.makeControl(new ConsoleTerminalListener(), composite,
5651
new ITerminalConnector[] {}, true);
57-
viewer.setConnector(new ConsoleConnector(process));
52+
viewer.setConnector(connector);
5853
viewer.setCharset(Charset.defaultCharset());
5954
viewer.clearTerminal();
6055
viewer.connectTerminal();
6156
if (viewer instanceof ITerminalControl ctrl) {
6257
ctrl.setConnectOnEnterIfClosed(false);
6358
ctrl.setVT100LineWrapping(true);
64-
IStreamMonitor streamMonitor = streamsProxy.getOutputStreamMonitor();
65-
if (streamMonitor instanceof IBinaryStreamMonitor bin) {
66-
OutputStream outputStream = ctrl.getRemoteToTerminalOutputStream();
67-
bin.addBinaryListener((data, monitor) -> {
68-
try {
69-
outputStream.write(data);
70-
} catch (IOException e1) {
71-
e1.printStackTrace();
72-
}
73-
});
59+
if (terminalControlHandler != null) {
60+
terminalControlHandler.accept(ctrl);
7461
}
7562
}
7663
}
7764

7865
@Override
7966
public void dispose() {
8067
viewer.disposeTerminal();
68+
composite.dispose();
8169
}
8270

8371
@Override

terminal/plugins/org.eclipse.tm.terminal.view.ui/plugin.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,12 @@
362362
id="org.eclipse.tm.terminal.view.ui.command.launch"
363363
name="%command.launch.selection.name">
364364
</command>
365+
<command
366+
categoryId="org.eclipse.tm.terminal.view.ui.commands.category"
367+
helpContextId="org.eclipse.tm.terminal.view.ui.command_Launch"
368+
id="org.eclipse.tm.terminal.view.ui.command.launchConsole"
369+
name="%command.launch.selection.name">
370+
</command>
365371
<command
366372
categoryId="org.eclipse.tm.terminal.view.ui.commands.category"
367373
helpContextId="org.eclipse.tm.terminal.view.ui.command_Launch"
@@ -397,6 +403,10 @@
397403
class="org.eclipse.tm.terminal.view.ui.internal.handler.LaunchTerminalCommandHandler"
398404
commandId="org.eclipse.tm.terminal.view.ui.command.launchToolbar">
399405
</handler>
406+
<handler
407+
class="org.eclipse.tm.terminal.view.ui.internal.handler.LaunchTerminalCommandHandler"
408+
commandId="org.eclipse.tm.terminal.view.ui.command.launchConsole">
409+
</handler>
400410
<handler
401411
class="org.eclipse.tm.terminal.view.ui.internal.handler.DisconnectTerminalCommandHandler"
402412
commandId="org.eclipse.tm.terminal.view.ui.command.disconnect">

0 commit comments

Comments
 (0)