Skip to content

Commit cec0d7d

Browse files
authored
Merge pull request coollabsio#3651 from LEstradioto/fix-enhance-terminal-2
Fix Terminal: no more exit fallback
2 parents 1f45532 + 2c38af1 commit cec0d7d

File tree

2 files changed

+12
-19
lines changed

2 files changed

+12
-19
lines changed

docker/coolify-realtime/terminal-server.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,10 @@ async function handleCommand(ws, command, userId) {
132132
// NOTE: - Initiates a process within the Terminal container
133133
// Establishes an SSH connection to root@coolify with RequestTTY enabled
134134
// Executes the 'docker exec' command to connect to a specific container
135-
// If the user types 'exit', it terminates the container connection and reverts to the server.
136-
const ptyProcess = pty.spawn('ssh', sshArgs.concat(['bash']), options);
135+
const ptyProcess = pty.spawn('ssh', sshArgs.concat([hereDocContent]), options);
136+
137137
userSession.ptyProcess = ptyProcess;
138138
userSession.isActive = true;
139-
ptyProcess.write(hereDocContent + '\n');
140-
// clear the terminal if the user has clear command
141-
ptyProcess.write('command -v clear >/dev/null 2>&1 && clear\n');
142139

143140
ws.send('pty-ready');
144141

@@ -147,6 +144,7 @@ async function handleCommand(ws, command, userId) {
147144
// when parent closes
148145
ptyProcess.onExit(({ exitCode, signal }) => {
149146
console.error(`Process exited with code ${exitCode} and signal ${signal}`);
147+
ws.send('pty-exited');
150148
userSession.isActive = false;
151149
});
152150

resources/js/terminal.js

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ export function initializeTerminalComponent() {
125125
if (this.term) this.term.reset();
126126
this.terminalActive = false;
127127
this.message = '(sorry, something went wrong, please try again)';
128+
} else if (event.data === 'pty-exited') {
129+
this.terminalActive = false;
130+
this.term.reset();
131+
this.commandBuffer = '';
128132
} else {
129133
this.pendingWrites++;
130134
this.term.write(event.data, this.flowControlCallback.bind(this));
@@ -136,9 +140,12 @@ export function initializeTerminalComponent() {
136140
if (this.pendingWrites > this.MAX_PENDING_WRITES && !this.paused) {
137141
this.paused = true;
138142
this.socket.send(JSON.stringify({ pause: true }));
139-
} else if (this.pendingWrites <= this.MAX_PENDING_WRITES && this.paused) {
143+
return;
144+
}
145+
if (this.pendingWrites <= this.MAX_PENDING_WRITES && this.paused) {
140146
this.paused = false;
141147
this.socket.send(JSON.stringify({ resume: true }));
148+
return;
142149
}
143150
},
144151

@@ -147,15 +154,7 @@ export function initializeTerminalComponent() {
147154

148155
this.term.onData((data) => {
149156
this.socket.send(JSON.stringify({ message: data }));
150-
// Handle CTRL + D or exit command
151-
if (data === '\x04' || (data === '\r' && this.stripAnsiCommands(this.commandBuffer).trim().includes('exit'))) {
152-
this.checkIfProcessIsRunningAndKillIt();
153-
setTimeout(() => {
154-
this.terminalActive = false;
155-
this.term.reset();
156-
}, 500);
157-
this.commandBuffer = '';
158-
} else if (data === '\r') {
157+
if (data === '\r') {
159158
this.commandBuffer = '';
160159
} else {
161160
this.commandBuffer += data;
@@ -183,10 +182,6 @@ export function initializeTerminalComponent() {
183182
});
184183
},
185184

186-
stripAnsiCommands(input) {
187-
return input.replace(/\x1b\[[0-9;]*[a-zA-Z]/g, '');
188-
},
189-
190185
keepAlive() {
191186
if (this.socket && this.socket.readyState === WebSocket.OPEN) {
192187
this.socket.send(JSON.stringify({ ping: true }));

0 commit comments

Comments
 (0)