feat: 补全终端交互逻辑.

This commit is contained in:
lijiahangmax
2024-01-12 02:05:27 +08:00
parent 6c0ad50b4e
commit c1a046f30e
14 changed files with 150 additions and 52 deletions

View File

@@ -32,7 +32,7 @@ public enum InputTypeEnum {
*/
CONNECT("co",
TerminalConnectHandler.class,
new String[]{"type", "sessionId", "cols", "rows"},
new String[]{"type", "sessionId", "terminalType", "cols", "rows"},
TerminalConnectRequest.class),
/**

View File

@@ -110,7 +110,7 @@ public class TerminalConnectHandler extends AbstractTerminalHandler<TerminalConn
// 建立连接
SessionStore sessionStore = hostTerminalService.openSessionStore(connect);
terminalSession = new TerminalSession(sessionId, channel, sessionStore, config);
terminalSession.connect(body.getCols(), body.getRows());
terminalSession.connect(body.getTerminalType(), body.getCols(), body.getRows());
log.info("TerminalConnectHandler-handle success sessionId: {}", sessionId);
return terminalSession;
} catch (Exception e) {

View File

@@ -25,6 +25,9 @@ import lombok.experimental.SuperBuilder;
@Schema(name = "TerminalConnectRequest", description = "终端连接请求 实体对象")
public class TerminalConnectRequest extends TerminalBasePayload {
@Schema(description = "伪终端类型")
private String terminalType;
@Schema(description = "列数")
private Integer cols;

View File

@@ -14,10 +14,11 @@ public interface ITerminalSession extends SafeCloseable {
/**
* 连接
*
* @param cols cols
* @param rows rows
* @param terminalType terminalType
* @param cols cols
* @param rows rows
*/
void connect(int cols, int rows);
void connect(String terminalType, int cols, int rows);
/**
* 重置大小

View File

@@ -61,14 +61,13 @@ public class TerminalSession implements ITerminalSession {
}
@Override
public void connect(int cols, int rows) {
public void connect(String terminalType, int cols, int rows) {
config.setCols(cols);
config.setRows(rows);
// 打开 shell
this.executor = sessionStore.getShellExecutor();
executor.size(cols, rows);
// FIXME
executor.terminalType(TerminalType.XTERM.getType());
executor.terminalType(terminalType);
executor.streamHandler(this::streamHandler);
executor.callback(this::eofCallback);
executor.connect();