You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by "g3g4x5x6 (Jira)" <ji...@apache.org> on 2021/12/27 03:45:00 UTC
[jira] [Created] (SSHD-1235) Terminal resizing: with jediterm, when quit from vim, terminal don't resizing any more
g3g4x5x6 created SSHD-1235:
------------------------------
Summary: Terminal resizing: with jediterm, when quit from vim, terminal don't resizing any more
Key: SSHD-1235
URL: https://issues.apache.org/jira/browse/SSHD-1235
Project: MINA SSHD
Issue Type: Bug
Affects Versions: 2.8.0
Environment: IDEA
Reporter: g3g4x5x6
h1. Create widget
{code:java}
......
private ClientSession getSession(SshClient client){
ClientSession session;
try {
session = client.connect(this.user, this.host, this.port).verify(5000, TimeUnit.MILLISECONDS).getSession();
session.addPasswordIdentity(this.pass);
session.auth().verify(15, TimeUnit.SECONDS);
session.setSessionHeartbeat(SessionHeartbeatController.HeartbeatType.IGNORE, Duration.ofMinutes(3));
return session;
} catch (IOException e) {
e.printStackTrace();
DialogUtil.error(e.getMessage());
return null;
}
}
......
private @NotNull JediTermWidget createTerminalWidget() {
SshSettingsProvider sshSettingsProvider = new SshSettingsProvider();
JediTermWidget widget = new JediTermWidget(sshSettingsProvider);
widget.setTtyConnector(new DefaultTtyConnector(session));
widget.start();
return widget;
} {code}
h1. DefaultTtyConnector
{code:java}
package com.g3g4x5x6.ui.panels.ssh;
import com.jediterm.terminal.Questioner;
import com.jediterm.terminal.TtyConnector;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.sshd.client.channel.ChannelShell;
import org.apache.sshd.client.session.ClientSession;
import org.jetbrains.annotations.NotNull;
import java.awt.*;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeUnit;
@Slf4j
public class DefaultTtyConnector implements TtyConnector {
private ClientSession session;
private ChannelShell channel;
private Dimension myPendingTermSize;
private PipedOutputStream channelOut;
private InputStream channelIn;
private OutputStream outputStream;
private BufferedReader reader;
private BufferedWriter writer;
public DefaultTtyConnector(ClientSession clientSession) {
this.session = clientSession;
}
@Override
public boolean init(Questioner questioner) {
try {
PipedOutputStream out = new PipedOutputStream();
channelIn = new PipedInputStream(out);
channelOut = new PipedOutputStream();
PipedInputStream in = new PipedInputStream(channelOut);
reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8));
writer = new BufferedWriter(new OutputStreamWriter(out));
channel = initClientChannel(session, channelIn, channelOut);
outputStream = channel.getInvertedIn();
} catch (IOException e) {
e.printStackTrace();
}
return true;
}
private ChannelShell initClientChannel(ClientSession session, InputStream input, OutputStream output) throws IOException {
ChannelShell channel = session.createShellChannel();
String lang = (String) System.getenv().get("LANG");
channel.setEnv("LANG", lang != null ? lang : "zh_CN.UTF-8");
channel.setPtyType("xterm");
channel.setUsePty(true);
channel.setIn(input);
channel.setOut(output);
channel.setErr(output);
channel.open().verify(3000, TimeUnit.MILLISECONDS);
return channel;
}
@SneakyThrows
@Override
public void close() {
channel.close();
}
@Override
public String getName() {
return "SSH";
}
@Override
public int read(char[] chars, int i, int i1) throws IOException {
return reader.read(chars, i, i1);
}
@Override
public void write(byte[] bytes) throws IOException {
outputStream.write(bytes);
outputStream.flush();
}
@Override
public boolean isConnected() {
return channel.isOpen();
}
@Override
public void write(String s) throws IOException {
log.debug(">>>>>>>>>>>>>>>>>>>>>>>>>>" + s);
this.write(s.getBytes(StandardCharsets.UTF_8));
}
@Override
public int waitFor() throws InterruptedException {
return channel.getExitStatus();
}
@Override
public boolean ready() throws IOException {
return true;
}
@Override
public void resize(@NotNull Dimension termWinSize) {
channel.setPtyWidth(termWinSize.width);
channel.setPtyHeight(termWinSize.height);
channel.setPtyColumns(termWinSize.width);
channel.setPtyLines(termWinSize.height);
}
private void resizeImmediately() {
if (this.myPendingTermSize != null) {
this.setPtySize(this.channel,
this.myPendingTermSize.width,
this.myPendingTermSize.height,
this.myPendingTermSize.width,
this.myPendingTermSize.height);
this.myPendingTermSize = null;
}
}
private void setPtySize(ChannelShell channel, int col, int row, int wp, int hp) {
channel.setPtyColumns(col);
channel.setPtyLines(row);
channel.setPtyWidth(wp);
channel.setPtyHeight(hp);
}
} {code}
h1. Problem
[info|https://github.com/JetBrains/jediterm/issues/236]
--
This message was sent by Atlassian Jira
(v8.20.1#820001)
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org