AlecAivazis / survey

A golang library for building interactive and accessible prompts with full support for windows and posix terminals.
MIT License
4.07k stars 350 forks source link

Sending enter key event doesn't work with pexpect and survey #422

Open coinpayu opened 2 years ago

coinpayu commented 2 years ago

I am using python3's pexpect module to interact with survey.

How can I send an 'enter' key event to survey? I have tried sendline(), send('\n'), send('\r'), but all failed. It seems survey ignored them.

mislav commented 2 years ago

Hi, I don't have experience with pexpect, but Survey interprets either \n or \r read from stdin (from the terminal, to be precise, because Survey only works when stdin is connected to a terminal) as Enter key being pressed. https://github.com/AlecAivazis/survey/blob/93657ef69381dd1ffc7a4a9cfe5a2aefff4ca4ad/terminal/runereader.go#L104

If Survey ignores a keystroke that pexpect has sent, maybe something was wrong in the way pexpect was set up in your case?