Skip to content

Commit

Permalink
Fixed ability to set terminal tab name programmatically. Fixes #494
Browse files Browse the repository at this point in the history
  • Loading branch information
maxoleksiv-ifx authored and jonahgraham committed Aug 16, 2023
1 parent b9cfdf9 commit c6841a7
Show file tree
Hide file tree
Showing 17 changed files with 72 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,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(), "RCM");
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 @@ -30,6 +30,7 @@ public interface ITerminalListener {
/**
* Set the title of the terminal.
* @param title
* @param requestor Who requests update.
*/
void setTerminalTitle(String title);
void setTerminalTitle(String title, String requestor);
}
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,11 @@ public interface ITerminalViewControl {
void removeMouseListener(ITerminalMouseListener listener);

/**
* @since 5.1
* Set the title of the terminal.
* @param newTitle
* @param requestor Who requests update.
*/
void setTerminalTitle(String newTitle);
void setTerminalTitle(String newTitle, String requestor);

/**
* @since 5.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public interface ITerminalControlForText {

void setState(TerminalState state);

void setTerminalTitle(String title);
void setTerminalTitle(String title, String requestor);

ITerminalConnector getTerminalConnector();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,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), "ANSI");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1260,8 +1260,8 @@ private void processKeyBinding(KeyEvent event, int accelerator) {
}

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,9 @@ public interface ITerminalControl {
/**
* Set the title of the terminal view.
* @param title
* @param requestor Who requests title update.
*/
void setTerminalTitle(String title);
void setTerminalTitle(String title, String requestor);

/**
* Show an error message during connect.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void setState(TerminalState state) {
}

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void setState(TerminalState state) {
}

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ public void setState(TerminalState state) {
}

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

public List<String> getAllTitles() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private void sleep(int ms) {
}

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ synchronized public void connect(ITerminalControl control) {
return;
}
fOutputStream = System.out;
fControl.setTerminalTitle(fSettings.getInputFile());
fControl.setTerminalTitle(fSettings.getInputFile(), "STC");
fConnection = new SpeedTestConnection(fInputStream, fSettings, fControl);
fConnection.start();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public void setState(TerminalState state) {
}

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ 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}
*/
public static final String PROP_TITLE_UPDATE_API = "titleUpdateAPI"; //$NON-NLS-1$

/**
* Property: The encoding of the terminal tab to open.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void run() {
if (inputDialog.open() == Window.OK) {
String value = inputDialog.getValue();
if (value != null) {
target.setTerminalTitle(value);
target.setTerminalTitle(value, "Menu");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,12 @@ public void doRun(String id, String secondaryId, String title, ITerminalConnecto
flags.put(ITerminalsConnectorConstants.PROP_DATA_NO_RECONNECT,
(Boolean) properties.get(ITerminalsConnectorConstants.PROP_DATA_NO_RECONNECT));
}
if (properties.get(ITerminalsConnectorConstants.PROP_TITLE_UPDATE_API) instanceof Boolean) {
flags.put(ITerminalsConnectorConstants.PROP_TITLE_UPDATE_API,
(Boolean) properties.get(ITerminalsConnectorConstants.PROP_TITLE_UPDATE_API));
} else {
flags.put(ITerminalsConnectorConstants.PROP_TITLE_UPDATE_API, false);
}
// Open the new console
CTabItem item;
item = ConsoleManager.getInstance().openConsole(id, secondaryId, title, encoding, connector, data,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@
*******************************************************************************/
package org.eclipse.tm.terminal.view.ui.tabs;

import java.util.Map;

import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.widgets.Display;
import org.eclipse.tm.internal.terminal.control.ITerminalListener2;
import org.eclipse.tm.internal.terminal.provisional.api.TerminalState;
import org.eclipse.tm.terminal.view.core.interfaces.constants.ITerminalsConnectorConstants;
import org.eclipse.tm.terminal.view.ui.nls.Messages;

/**
Expand Down Expand Up @@ -114,7 +117,6 @@ private void updateTitle() {
if (item == null || item.isDisposed()) {
return;
}

// Run asynchronously in the display thread
item.getDisplay().asyncExec(() -> {
// Update the tab item title
Expand Down Expand Up @@ -161,10 +163,38 @@ protected String getTerminalConsoleTabTitle(TerminalState state) {
return newTitle != null && !newTitle.equals(oldTitle) ? newTitle : null;
}

@Override
public void setTerminalTitle(String title) {
tabItemTitle = title;
updateTitle();
/**
* Sets Terminal tilte and checks if originator is ANSI command.
* If originator is ANSI command in terminal and user does not want to use
* ANSI command to upate terminal then return else update title.
* @param title Title to update.
* @param requestor Who requests title update. Can be null.
* @since 11.3
*/
public void setTerminalTitle(String title, String requestor) {

CTabItem item = getTabItem();
if (item == null || item.isDisposed()) {
return;
}

// Run asynchronously in the display thread
item.getDisplay().asyncExec(() -> {
Boolean flag = false;
// Get the original terminal properties associated with the tab item
Map<String, Object> properties = (Map<String, Object>) item.getData("properties"); //$NON-NLS-1$
if (properties.containsKey(ITerminalsConnectorConstants.PROP_TITLE_UPDATE_API)) {
flag = (Boolean) properties.get(ITerminalsConnectorConstants.PROP_TITLE_UPDATE_API);
}
// Check if terminal should be updated either using API only (flag == true)
// or using API and ANSI command (flag == false).
if (flag == true && requestor != null && requestor.equals("ANSI")) {
return;
}

tabItemTitle = title;
updateTitle();
});
}

/**
Expand Down

0 comments on commit c6841a7

Please sign in to comment.