ttyd icon indicating copy to clipboard operation
ttyd copied to clipboard

Have window close upon disconnect

Open limetech opened this issue 1 year ago • 3 comments

Suppose a ttyd is started and executes the 'bash' command. When the user types 'exit' the connection closes and user is prompted to hit Enter to reconnect. Instead, when user types 'exit' the window should be closed - how to accomplish this? thank you

limetech avatar Jun 18 '23 17:06 limetech

It's not supported yet.

tsl0922 avatar Jun 19 '23 01:06 tsl0922

Ok thanks. What we do for now is apply this patch and then rebuild the 'html.h' file.

diff --git a/html/src/components/terminal/xterm/index.ts b/html/src/components/terminal/xterm/index.ts
index e6809e4..c7b377f 100644
--- a/html/src/components/terminal/xterm/index.ts
+++ b/html/src/components/terminal/xterm/index.ts
@@ -269,7 +269,9 @@ export class Xterm {
         this.dispose();

         // 1000: CLOSE_NORMAL
-        if (event.code !== 1000 && doReconnect) {
+        if (event.code === 1000 || event.code === 1006) {
+            window.close();
+        } else if (event.code !== 1000 && doReconnect) {
             overlayAddon.showOverlay('Reconnecting...');
             refreshToken().then(connect);
         } else {

This is from git checkout tags/1.7.3

btw: when we build 'ttyd' using latest code, the terminal does not accept any input, meaning anything you type just doesn't get sent.

limetech avatar Jun 19 '23 21:06 limetech

btw: when we build 'ttyd' using latest code, the terminal does not accept any input, meaning anything you type just doesn't get sent.

Start ttyd with -W option.

tsl0922 avatar Jun 22 '23 15:06 tsl0922