You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using this code to apply 2 ways of SIGINT, process SIGINT and readline SIGINT
// Import the readline module to mock user interactions via the console.constreadline=require('readline');// Mock the client and its dependencies with basic stubs.classClient{asyncsendRequest(url: string){return'Response from '+url;// Dummy response}}// Function to simulate response conversion from gemtext.functionfromGemtext(response: string){returnresponse;// Simply return the same dummy response for simplicity}constclient=newClient();constrl=readline.createInterface({input: process.stdin,output: process.stdout});process.on('SIGINT',function(){console.log('Graceful shutdown');process.exit(0);}).on('SIGINT',function(){process.emit('SIGINT');});process.on('SIGINT',function(){// graceful shutdownprocess.kill(process.pid,'SIGINT');});// Versioning for the dummy package.constversion='1.0.0';// Hardcoded versionconsole.log(`Dummy Client v${version}`);console.log("Dummy CLI for testing. Type '/c' to exit or any URL to simulate a request.");// Function to handle the "gemini" requests in a dummy manner.asyncfunctionhandleGeminiRequest(inputUrl: string){try{constresponse=awaitclient.sendRequest(inputUrl);console.log(fromGemtext(response));}catch(err){if(errinstanceofError)console.log('Error:',err.message);}}// Function to create commands.functioncreateCommands(string: string){if(string.trim()==='/c'){return'exit';}return'url-request';// Default to URL request for any other input}// Function to prompt and process commands.functionpromptAndProcessCommand(){console.log(`Platform ${process.platform}, Node ${process.version}, isTTY? ${process.stdout.isTTY}`);if(process.platform==="win32"){rl.on("SIGINT",function(){console.log("Process terminated (SIGINT).");process.kill(process.pid,'SIGINT');});}rl.question('> ',async(cmd: string)=>{constcommand=createCommands(cmd);switch(command){case'exit':
console.log('Bye!');rl.close();process.exit(0);case'url-request':
awaithandleGeminiRequest(cmd);promptAndProcessCommand();// Continue the command loopbreak;}});}// Start the command loop.promptAndProcessCommand();
run the code
when > is visible try to press CTRL + C
What is the expected behavior?
When I press CTRL + C it should exit my program gracefully.
What do you see instead?
I need to press Enter after CTRL + C or Enter first to CTRL + C.
Temporary solution (for my case) was adding keypress event if the stdin isTTY is true.
import*asreadlinefrom"node:readline";// TODO: remove code when https://github.com/oven-sh/bun/issues/10403 is fixedif(process.stdin.isTTY){readline.emitKeypressEvents(process.stdin);process.stdin.setRawMode(true);process.stdin.on("keypress",(str,key)=>{if(key.ctrl&&key.name==="c")process.exit();});}
This simply ignores the defect because whenever ctrl and key c is pressed in the stdin process, it will exit the process.
Note: This would not solve the whole related issues. This behaviour still need to be fixed.
What version of Bun is running?
1.1.3+2615dc742
What platform is your computer?
Microsoft Windows NT 10.0.22621.0 x64
What steps can reproduce the bug?
>
is visible try to pressCTRL + C
What is the expected behavior?
When I press
CTRL + C
it should exit my program gracefully.What do you see instead?
I need to press
Enter
afterCTRL + C
orEnter
first toCTRL + C
.Additional information
Related:
CTRL + C
in readline nodejs/node#52597The text was updated successfully, but these errors were encountered: