mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-03-28 14:56:28 +01:00
Cleanup of PTY class
Change-Id: If04a3ccbc178040d4929767ef1f4c0f1672dfae9 Signed-off-by: Torbjörn Svensson <azoff@svenskalinuxforeningen.se>
This commit is contained in:
parent
38e970a45d
commit
8e42cc8b7b
7 changed files with 20 additions and 43 deletions
|
@ -39,7 +39,7 @@ public class PTY {
|
|||
TERMINAL
|
||||
}
|
||||
|
||||
final boolean console;
|
||||
final Mode mode;
|
||||
final String slave;
|
||||
final PTYInputStream in;
|
||||
final PTYOutputStream out;
|
||||
|
@ -72,6 +72,7 @@ public class PTY {
|
|||
/**
|
||||
* @return whether PTY support for console mode is available on this platform
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean isSupported() {
|
||||
return isSupported(Mode.CONSOLE);
|
||||
}
|
||||
|
@ -86,7 +87,7 @@ public class PTY {
|
|||
|
||||
/**
|
||||
* Create PTY for use with Eclipse console.
|
||||
* Identical to {@link PTY#PTY(boolean) PTY(Mode.CONSOLE)}.
|
||||
* Identical to {@link PTY#PTY(Mode.CONSOLE)}.
|
||||
*/
|
||||
public PTY() throws IOException {
|
||||
this(Mode.CONSOLE);
|
||||
|
@ -114,39 +115,11 @@ public class PTY {
|
|||
* @since 5.6
|
||||
*/
|
||||
public PTY(Mode mode) throws IOException {
|
||||
this(mode == Mode.CONSOLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create pseudo terminal.
|
||||
*
|
||||
* <p>
|
||||
* The provided flag indicates whether the pseudo terminal is used with the interactive
|
||||
* Eclipse console:
|
||||
* <ul>
|
||||
* <li>If <code>true</code> the terminal is configured with no echo and stderr is
|
||||
* redirected to a pipe instead of the PTY. This mode is not supported on windows</li>
|
||||
* <li>If <code>false</code> the terminal is configured with echo and stderr is
|
||||
* connected to the PTY. This mode is best suited for use with a proper terminal emulation.
|
||||
* Note that this mode might not be supported on all platforms.
|
||||
* Known platforms which support this mode are:
|
||||
* <code>linux-x86</code>, <code>linux-x86_64</code>, <code>solaris-sparc</code>, <code>macosx</code>.
|
||||
* </li>
|
||||
* </ul>
|
||||
* </p>
|
||||
*
|
||||
* @param console whether terminal is used with Eclipse console
|
||||
* @throws IOException if the PTY could not be created
|
||||
* @deprecated Use {@link #PTY(Mode)} instead
|
||||
* @since 5.2
|
||||
*/
|
||||
@Deprecated
|
||||
public PTY(boolean console) throws IOException {
|
||||
this.console = console;
|
||||
if (console && !isConsoleModeSupported) {
|
||||
this.mode = mode;
|
||||
if (isConsole() && !isConsoleModeSupported) {
|
||||
throw new IOException(Messages.Util_exception_cannotCreatePty);
|
||||
}
|
||||
slave = hasPTY ? openMaster(console) : null;
|
||||
slave = hasPTY ? openMaster(isConsole()) : null;
|
||||
|
||||
if (slave == null) {
|
||||
throw new IOException(Messages.Util_exception_cannotCreatePty);
|
||||
|
@ -165,8 +138,9 @@ public class PTY {
|
|||
public void validateSlaveName() throws IOException {
|
||||
// on windows the slave name is just an internal identifier
|
||||
// and does not represent a real device
|
||||
if (isWinPTY)
|
||||
if (isWinPTY) {
|
||||
throw new IOException("Slave name is not valid"); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
public String getSlaveName() {
|
||||
|
@ -183,7 +157,7 @@ public class PTY {
|
|||
* @since 5.2
|
||||
*/
|
||||
public final boolean isConsole() {
|
||||
return console;
|
||||
return mode == Mode.CONSOLE;
|
||||
}
|
||||
|
||||
public PTYOutputStream getOutputStream() {
|
||||
|
@ -227,9 +201,9 @@ public class PTY {
|
|||
public int exec_pty(Spawner spawner, String[] cmdarray, String[] envp, String dir, IChannel[] chan)
|
||||
throws IOException {
|
||||
if (isWinPTY) {
|
||||
return exec2(cmdarray, envp, dir, chan, slave, master, console);
|
||||
return exec2(cmdarray, envp, dir, chan, slave, master, isConsole());
|
||||
} else {
|
||||
return spawner.exec2(cmdarray, envp, dir, chan, slave, master, console);
|
||||
return spawner.exec2(cmdarray, envp, dir, chan, slave, master, isConsole());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,10 @@ import java.io.InputStream;
|
|||
|
||||
import org.eclipse.cdt.utils.pty.PTY.MasterFD;
|
||||
|
||||
class PTYInputStream extends InputStream {
|
||||
/**
|
||||
* @since 6.0
|
||||
*/
|
||||
public class PTYInputStream extends InputStream {
|
||||
|
||||
MasterFD master;
|
||||
|
||||
|
|
|
@ -170,7 +170,7 @@ public class Utilities {
|
|||
if (workDir == null) {
|
||||
return ProcessFactory.getFactory().exec(commandArray, envp);
|
||||
}
|
||||
if (PTY.isSupported() && usePty) {
|
||||
if (PTY.isSupported(PTY.Mode.CONSOLE) && usePty) {
|
||||
return ProcessFactory.getFactory().exec(commandArray, envp, workDir, new PTY());
|
||||
} else {
|
||||
return ProcessFactory.getFactory().exec(commandArray, envp, workDir);
|
||||
|
|
|
@ -280,7 +280,7 @@ public class LocalRunLaunchDelegate extends AbstractCLaunchDelegate2 {
|
|||
*/
|
||||
protected Process exec(String[] cmdLine, String[] environ, File workingDirectory) throws CoreException {
|
||||
try {
|
||||
if (PTY.isSupported()) {
|
||||
if (PTY.isSupported(PTY.Mode.CONSOLE)) {
|
||||
return ProcessFactory.getFactory().exec(cmdLine, environ, workingDirectory, new PTY());
|
||||
} else {
|
||||
return ProcessFactory.getFactory().exec(cmdLine, environ, workingDirectory);
|
||||
|
|
|
@ -152,7 +152,7 @@ public class CMainTab extends CAbstractMainTab {
|
|||
updateLaunchConfigurationDialog();
|
||||
}
|
||||
});
|
||||
fTerminalButton.setEnabled(PTY.isSupported());
|
||||
fTerminalButton.setEnabled(PTY.isSupported(PTY.Mode.CONSOLE));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -32,7 +32,7 @@ public class ProcessSettings {
|
|||
private PTY pty;
|
||||
// Flag to control the local echo (defaults to true if
|
||||
// the PTY is not supported on the current host platform)
|
||||
private boolean localEcho = !PTY.isSupported();
|
||||
private boolean localEcho = !PTY.isSupported(PTY.Mode.CONSOLE);
|
||||
// The line separator setting
|
||||
private String lineSeparator = null;
|
||||
// The list of stdout output listeners
|
||||
|
|
|
@ -113,7 +113,7 @@ public class ProcessSettingsPage extends AbstractSettingsPage {
|
|||
localEchoSelectorControl = new Button(composite, SWT.CHECK);
|
||||
localEchoSelectorControl.setText(Messages.ProcessSettingsPage_localEchoSelectorControl_label);
|
||||
localEchoSelectorControl.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
localEchoSelectorControl.setSelection(!PTY.isSupported());
|
||||
localEchoSelectorControl.setSelection(!PTY.isSupported(PTY.Mode.CONSOLE));
|
||||
|
||||
// Initialize the control content
|
||||
loadSettings();
|
||||
|
|
Loading…
Add table
Reference in a new issue