From 663b68a7335ec1104cd15fd44bc22c3e53dd17d2 Mon Sep 17 00:00:00 2001 From: ihrpr Date: Sun, 13 Apr 2025 16:16:14 +0100 Subject: [PATCH] exc to disconnect in example client --- src/examples/client/simpleStreamableHttp.ts | 22 +++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/examples/client/simpleStreamableHttp.ts b/src/examples/client/simpleStreamableHttp.ts index a687eccd..923ffbc2 100644 --- a/src/examples/client/simpleStreamableHttp.ts +++ b/src/examples/client/simpleStreamableHttp.ts @@ -405,11 +405,33 @@ async function cleanup(): Promise { } } + + process.stdin.setRawMode(false); readline.close(); console.log('\nGoodbye!'); process.exit(0); } +// Set up raw mode for keyboard input to capture Escape key +process.stdin.setRawMode(true); +process.stdin.on('data', async (data) => { + // Check for Escape key (27) + if (data.length === 1 && data[0] === 27) { + console.log('\nESC key pressed. Disconnecting from server...'); + + // Abort current operation and disconnect from server + if (client && transport) { + await disconnect(); + console.log('Disconnected. Press Enter to continue.'); + } else { + console.log('Not connected to server.'); + } + + // Re-display the prompt + process.stdout.write('> '); + } +}); + // Handle Ctrl+C process.on('SIGINT', async () => { console.log('\nReceived SIGINT. Cleaning up...');