IDEA-179900 - Docker exec tab does not correctly wrap

- TerminalHandlerBase: allow to handle tty resize events terminal plugin
- cloud terminal handler: pass tty resize events to custom handlers
+ switch to modern condensed copyright comments

GitOrigin-RevId: 9a015be281eaa07dd5433b59fa08d3817ab600eb
This commit is contained in:
Michael Golubev
2019-08-04 20:28:09 +02:00
committed by intellij-monorepo-bot
parent 94b63d6ff0
commit b26eeec640
5 changed files with 48 additions and 66 deletions

View File

@@ -5,10 +5,13 @@ import com.intellij.remoteServer.runtime.log.TerminalHandler;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.awt.*;
import java.util.function.Consumer;
public abstract class TerminalHandlerBase extends LoggingHandlerBase implements TerminalHandler {
private boolean myClosed = false;
private Consumer<Dimension> myResizeHandler = size -> {
};
public TerminalHandlerBase(@NotNull String presentableName) {
super(presentableName);
@@ -26,4 +29,13 @@ public abstract class TerminalHandlerBase extends LoggingHandlerBase implements
public void close() {
myClosed = true;
}
}
public void setResizeHandler(@NotNull Consumer<Dimension> resizeHandler) {
myResizeHandler = resizeHandler;
}
@NotNull
protected Consumer<Dimension> getResizeHandler() {
return myResizeHandler;
}
}

View File

@@ -1,39 +1,34 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.plugins.terminal.cloud;
import com.intellij.util.concurrency.Semaphore;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.awt.*;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.function.Consumer;
public class CloudTerminalProcess extends Process {
private final OutputStream myOutputStream;
private final InputStream myInputStream;
private final Consumer<Dimension> myTtyResizeHandler;
private final Semaphore mySemaphore;
public CloudTerminalProcess(OutputStream terminalInput, InputStream terminalOutput) {
public CloudTerminalProcess(OutputStream terminalInput, InputStream terminalOutput, @Nullable Consumer<Dimension> ttyResizeHandler) {
myOutputStream = terminalInput;
myInputStream = terminalOutput;
myTtyResizeHandler = ttyResizeHandler;
mySemaphore = new Semaphore();
mySemaphore.down();
}
public CloudTerminalProcess(OutputStream terminalInput, InputStream terminalOutput) {
this(terminalInput, terminalOutput, null);
}
@Override
public OutputStream getOutputStream() {
return myOutputStream;
@@ -64,4 +59,10 @@ public class CloudTerminalProcess extends Process {
public void destroy() {
mySemaphore.up();
}
void resizeTty(@NotNull Dimension termSize) {
if (myTtyResizeHandler != null) {
myTtyResizeHandler.accept(termSize);
}
}
}

View File

@@ -1,18 +1,4 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.plugins.terminal.cloud;
import com.intellij.openapi.project.Project;

View File

@@ -1,18 +1,4 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.plugins.terminal.cloud;
import com.intellij.execution.process.ProcessHandler;
@@ -26,8 +12,10 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.terminal.AbstractTerminalRunner;
import java.awt.*;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.util.Objects;
import java.util.concurrent.ExecutionException;
public class CloudTerminalRunner extends AbstractTerminalRunner<CloudTerminalProcess> {
@@ -86,10 +74,18 @@ public class CloudTerminalRunner extends AbstractTerminalRunner<CloudTerminalPro
@Override
protected TtyConnector createTtyConnector(CloudTerminalProcess process) {
return new ProcessTtyConnector(process, Charset.defaultCharset()) {
private Dimension myAppliedTermSize;
@Override
protected void resizeImmediately() {
Dimension termSize = getPendingTermSize();
if (Objects.equals(myAppliedTermSize, termSize)) {
return;
}
if (termSize != null) {
myProcess.resizeTty(termSize);
}
myAppliedTermSize = termSize;
}
@Override

View File

@@ -1,18 +1,4 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.plugins.terminal.cloud;
import com.intellij.openapi.project.Project;
@@ -34,7 +20,8 @@ public class TerminalHandlerImpl extends TerminalHandlerBase {
@NotNull OutputStream terminalInput) {
super(presentableName);
final CloudTerminalProcess process = new CloudTerminalProcess(terminalInput, terminalOutput);
final CloudTerminalProcess process = new CloudTerminalProcess(terminalInput, terminalOutput,
ttySize -> getResizeHandler().accept(ttySize));
CloudTerminalRunner terminalRunner = new CloudTerminalRunner(project, presentableName, process);