Skip to content

Commit

Permalink
Add ability to prevent terminal title updates from ANSI Escape sequence
Browse files Browse the repository at this point in the history
When a more complete implementation of ANSI Escape sequence for
renaming terminal titles was added in
[CDT 10.2](https://github.com/eclipse-cdt/cdt/blob/main/NewAndNoteworthy/CDT-10.2.md#rename-terminal-tab)
it caused a regression in use cases where extenders of the terminal
wanted to retain control of the terminal's title.

This commit adds a new flag that will prevent the title of the
terminal tab from being updated from ANSI escape sequences.

Fixes #494
  • Loading branch information
maxoleksiv-ifx authored and jonahgraham committed Aug 18, 2023
1 parent c9a38e5 commit 1aa7ce0
Show file tree
Hide file tree
Showing 23 changed files with 200 additions and 30 deletions.
12 changes: 12 additions & 0 deletions NewAndNoteworthy/CHANGELOG-API.md
Original file line number Diff line number Diff line change
Expand Up @@ -604,3 +604,15 @@ spelled BuiltinDetectionArgsGeneric instead.
These APIs will be removed and remote connection for attach launch will be moved in the implementation of `IGDBProcesses.attachDebuggerToProcess()`.

See https://github.com/eclipse-cdt/cdt/pull/336

## API Removals after September 2025

### Terminal Control API for setting title without `requestor` will be removed

These APIs will be removed and are replaced by versions with `requestor` parameter.

- org.eclipse.tm.internal.terminal.control.ITerminalListener.setTerminalTitle(String)
- org.eclipse.tm.internal.terminal.provisional.api.ITerminalControl.setTerminalTitle(String)
- org.eclipse.tm.internal.terminal.control.ITerminalViewControl.setTerminalTitle(String)

See https://github.com/eclipse-cdt/cdt/issues/494
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.tm.terminal.connector.remote;singleton:=true
Bundle-Version: 4.8.0.qualifier
Bundle-Version: 4.8.100.qualifier
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Require-Bundle: org.eclipse.ui,
Expand All @@ -13,8 +13,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.core.resources,
org.eclipse.swt,
org.eclipse.jface,
org.eclipse.tm.terminal.view.core;bundle-version="4.5.0";resolution:=optional,
org.eclipse.tm.terminal.view.ui;bundle-version="4.5.0";resolution:=optional,
org.eclipse.tm.terminal.view.core;bundle-version="4.10.0";resolution:=optional,
org.eclipse.tm.terminal.view.ui;bundle-version="4.11.100";resolution:=optional,
org.eclipse.core.expressions
Bundle-RequiredExecutionEnvironment: JavaSE-17
Export-Package: org.eclipse.tm.terminal.connector.remote,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
*******************************************************************************/
package org.eclipse.tm.terminal.connector.remote.internal;

import static org.eclipse.tm.internal.terminal.control.ITerminalListener3.*;

import java.io.IOException;
import java.io.InputStream;

Expand Down Expand Up @@ -126,7 +128,7 @@ protected IStatus run(IProgressMonitor monitor) {
control.setVT100LineWrapping(true);
connector.setInputStream(remoteProcess.getInputStream());
control.setState(TerminalState.CONNECTED);
control.setTerminalTitle(remoteConnection.getName());
control.setTerminalTitle(remoteConnection.getName(), TerminalTitleRequestor.OTHER);
connector.setOutputStream(remoteProcess.getOutputStream());
// Initialize terminal size
VT100Emulator text = ((VT100TerminalControl) control).getTerminalText();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.tm.terminal.control; singleton:=true
Bundle-Version: 5.4.100.qualifier
Bundle-Version: 5.5.0.qualifier
Bundle-Activator: org.eclipse.tm.internal.terminal.control.impl.TerminalPlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ public interface ITerminalListener {
void setState(TerminalState state);

/**
* Set the title of the terminal.
* @deprecated Migrate to implementing {@link ITerminalListener3} and
* override {@link ITerminalListener3#setTerminalTitle(String, String)
* @param title
*/
@Deprecated(forRemoval = true)
void setTerminalTitle(String title);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*******************************************************************************
* Copyright (c) 2023 Infineon Technologies AG. All Rights Reserved.
*
* This program and the accompanying materials are made available under the terms
* of the Eclipse Public License 2.0 which accompanies this distribution, and is
* available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.tm.internal.terminal.control;

/**
* Terminal listener allowing to listen to terminal selection changes.
* The interface overrides the deprecated {@link #setTerminalTitle(String)} with
* {@link #setTerminalTitle(String, String)} that should be called instead.
*
* @since 5.5
*/
public interface ITerminalListener3 extends ITerminalListener2 {

/**
* Enum defines terminal title change requestors for
* setTerminalTitle method.
*
* @since 5.5
*/
enum TerminalTitleRequestor {
ANSI, // Terminal tab title change requested using ANSI command in terminal.
MENU, // Terminal tab title change requested from menu.
OTHER; // Terminal tab title change requested by other requestors.
}

/**
* Set the title of the terminal.
*
* @param title Termianl title.
* @param requestor Item that requests terminal title update.
*/
void setTerminalTitle(String title, TerminalTitleRequestor requestor);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
******************************************************************************/
package org.eclipse.tm.internal.terminal.control;

import static org.eclipse.tm.internal.terminal.control.ITerminalListener3.*;

import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;

Expand Down Expand Up @@ -191,10 +193,19 @@ public interface ITerminalViewControl {
void removeMouseListener(ITerminalMouseListener listener);

/**
* @since 5.1
* @deprecated call {@link #setTerminalTitle(String, String)} instead
*/
@Deprecated(forRemoval = true)
void setTerminalTitle(String newTitle);

/**
* Set the title of the terminal.
* @param newTitle
* @param requestor Item that requests terminal title update.
* @since 5.5
*/
void setTerminalTitle(String newTitle, TerminalTitleRequestor requestor);

/**
* @since 5.2
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*******************************************************************************/
package org.eclipse.tm.internal.terminal.control.impl;

import static org.eclipse.tm.internal.terminal.control.ITerminalListener3.*;

import java.io.OutputStream;

import org.eclipse.tm.internal.terminal.provisional.api.ITerminalConnector;
Expand All @@ -28,7 +30,13 @@ public interface ITerminalControlForText {

void setState(TerminalState state);

void setTerminalTitle(String title);
/**
* Set the title of the terminal.
*
* @param title Termianl title.
* @param requestor Item that requests terminal title update.
*/
void setTerminalTitle(String title, TerminalTitleRequestor requestor);

ITerminalConnector getTerminalConnector();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import static org.eclipse.tm.terminal.model.TerminalColor.RED;
import static org.eclipse.tm.terminal.model.TerminalColor.WHITE;
import static org.eclipse.tm.terminal.model.TerminalColor.YELLOW;
import static org.eclipse.tm.internal.terminal.control.ITerminalListener3.*;

import java.io.IOException;
import java.io.Reader;
Expand Down Expand Up @@ -486,7 +487,7 @@ private void processAnsiOsCommand() {
Logger.log("Ignoring unsupported ANSI OSC sequence: '" + ansiOsCommand + "'"); //$NON-NLS-1$ //$NON-NLS-2$
return;
}
terminal.setTerminalTitle(ansiOsCommand.substring(2));
terminal.setTerminalTitle(ansiOsCommand.substring(2), TerminalTitleRequestor.ANSI);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
*******************************************************************************/
package org.eclipse.tm.internal.terminal.emulator;

import static org.eclipse.tm.internal.terminal.control.ITerminalListener3.*;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
Expand Down Expand Up @@ -98,6 +100,7 @@
import org.eclipse.tm.internal.terminal.control.ICommandInputField;
import org.eclipse.tm.internal.terminal.control.ITerminalListener;
import org.eclipse.tm.internal.terminal.control.ITerminalListener2;
import org.eclipse.tm.internal.terminal.control.ITerminalListener3;
import org.eclipse.tm.internal.terminal.control.ITerminalMouseListener;
import org.eclipse.tm.internal.terminal.control.ITerminalViewControl;
import org.eclipse.tm.internal.terminal.control.impl.ITerminalControlForText;
Expand Down Expand Up @@ -1261,7 +1264,17 @@ private void processKeyBinding(KeyEvent event, int accelerator) {

@Override
public void setTerminalTitle(String title) {
fTerminalListener.setTerminalTitle(title);
setTerminalTitle(title, TerminalTitleRequestor.OTHER);
}

@Override
public void setTerminalTitle(String title, TerminalTitleRequestor requestor) {
if (fTerminalListener instanceof ITerminalListener3 listener3) {
listener3.setTerminalTitle(title, requestor);
} else {
fTerminalListener.setTerminalTitle(title);
}

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*******************************************************************************/
package org.eclipse.tm.internal.terminal.provisional.api;

import static org.eclipse.tm.internal.terminal.control.ITerminalListener3.*;

import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
Expand Down Expand Up @@ -155,11 +157,19 @@ public interface ITerminalControl {
OutputStream getRemoteToTerminalOutputStream();

/**
* Set the title of the terminal view.
* @param title
* @deprecated call {@link #setTerminalTitle(String, String)} instead
*/
@Deprecated(forRemoval = true)
void setTerminalTitle(String title);

/**
* Set the title of the terminal view.
* @param title Termianl title.
* @param requestor Item that requests terminal title update.
* @since 5.5
*/
void setTerminalTitle(String title, TerminalTitleRequestor requestor);

/**
* Show an error message during connect.
* @param msg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*******************************************************************************/
package org.eclipse.tm.internal.terminal.connector;

import static org.eclipse.tm.internal.terminal.control.ITerminalListener3.*;

import java.io.OutputStream;
import java.nio.charset.Charset;

Expand Down Expand Up @@ -99,6 +101,10 @@ public void setState(TerminalState state) {
public void setTerminalTitle(String title) {
}

@Override
public void setTerminalTitle(String title, TerminalTitleRequestor requestor) {
}

@Override
public void setupTerminal(Composite parent) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*******************************************************************************/
package org.eclipse.tm.internal.terminal.connector;

import static org.eclipse.tm.internal.terminal.control.ITerminalListener3.*;

import java.io.OutputStream;
import java.nio.charset.Charset;

Expand Down Expand Up @@ -99,6 +101,10 @@ public void setState(TerminalState state) {
public void setTerminalTitle(String title) {
}

@Override
public void setTerminalTitle(String title, TerminalTitleRequestor requestor) {
}

@Override
public void setupTerminal(Composite parent) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
*******************************************************************************/
package org.eclipse.tm.internal.terminal.emulator;

import static org.eclipse.tm.internal.terminal.control.ITerminalListener3.*;

import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -32,8 +34,10 @@ public void setState(TerminalState state) {
}

@Override
public void setTerminalTitle(String title) {
allTitles.add(title);
public void setTerminalTitle(String title, TerminalTitleRequestor requestor) {
if (requestor == TerminalTitleRequestor.ANSI) {
allTitles.add(title);
}
}

public List<String> getAllTitles() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.tm.internal.terminal.speedtest;

import static org.eclipse.tm.internal.terminal.control.ITerminalListener3.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -114,7 +116,7 @@ private void sleep(int ms) {
}

private void setTitle(final String title) {
Display.getDefault().asyncExec(() -> fControl.setTerminalTitle(title));
Display.getDefault().asyncExec(() -> fControl.setTerminalTitle(title, TerminalTitleRequestor.OTHER));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*******************************************************************************/
package org.eclipse.tm.internal.terminal.speedtest;

import static org.eclipse.tm.internal.terminal.control.ITerminalListener3.*;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
Expand Down Expand Up @@ -48,7 +50,7 @@ synchronized public void connect(ITerminalControl control) {
return;
}
fOutputStream = System.out;
fControl.setTerminalTitle(fSettings.getInputFile());
fControl.setTerminalTitle(fSettings.getInputFile(), TerminalTitleRequestor.OTHER);
fConnection = new SpeedTestConnection(fInputStream, fSettings, fControl);
fConnection.start();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*******************************************************************************/
package org.eclipse.tm.internal.terminal.test.ui;

import static org.eclipse.tm.internal.terminal.control.ITerminalListener3.*;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
Expand Down Expand Up @@ -212,7 +214,7 @@ public void setState(TerminalState state) {
}

@Override
public void setTerminalTitle(String title) {
public void setTerminalTitle(String title, TerminalTitleRequestor requestor) {
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.tm.terminal.view.core;singleton:=true
Bundle-Version: 4.9.100.qualifier
Bundle-Version: 4.10.0.qualifier
Bundle-Activator: org.eclipse.tm.terminal.view.core.activator.CoreBundleActivator
Bundle-Vendor: %providerName
Require-Bundle: org.eclipse.core.expressions;bundle-version="3.4.400",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ public interface ITerminalsConnectorConstants {
*/
public static final String PROP_TITLE = "title"; //$NON-NLS-1$

/**
* Property: Flag to set terminal title either using terminal API only or
* using terminal API and ANSI command.
* <p>
* Property Type: {@link String}
* @since 4.10
*/
public static final String PROP_TITLE_UPDATE_API = "titleUpdateAPI"; //$NON-NLS-1$

/**
* Property: The encoding of the terminal tab to open.
* <p>
Expand Down
Loading

0 comments on commit 1aa7ce0

Please sign in to comment.