Replies: 11 comments 5 replies
-
I found this crate https://crates.io/crates/getch |
Beta Was this translation helpful? Give feedback.
-
@fuelen @andyl I tried using Rustler + getch but couldn't get it to work. I think it is due to BEAM blocking the stdin port (here). So I came with a dirty solution that closes the stdin port opened by the user driver and re-opens it on a process I can control: It works well but it has the big downside of overriding the IO port, meaning regular IO operations won't work. Here is an asciicast of the script: |
Beta Was this translation helpful? Give feedback.
-
Hey @antedeguemon Cool, that's interesting. I went to Google to find what is tty_sl and quickly found this repo https://github.com/swalkerhppr/elixir-io_tty :) |
Beta Was this translation helpful? Give feedback.
-
@antedeguemon thanks for posting your code I was able to run it locally. Studying. @fuelen - have not seen |
Beta Was this translation helpful? Give feedback.
-
I had another look - seems like |
Beta Was this translation helpful? Give feedback.
-
Unfortunately no |
Beta Was this translation helpful? Give feedback.
-
Here's a thread with some good resources: |
Beta Was this translation helpful? Give feedback.
-
Hi friends! I’ve been reading through the various linked resources from this thread this morning and wanted to follow up to see if any conclusions had been drawn. It looks to me like the key is: Port.open({:spawn, "tty_sl -c -e"}, [:binary, :eof]) which will send input characters to the opening process. The question then is what are the additional responsibilities that process has to keep everything working? Some misc things that I believe would need to be handled:
Other questions:
|
Beta Was this translation helpful? Give feedback.
-
Here's a gist for a 'getch' demo script. It works for me on Ubuntu 22.04 with OTP25 and Elixir 1.15. Give it a try! |
Beta Was this translation helpful? Give feedback.
-
Also, here are some upcoming changes which may change the current state erlang/otp#6144
|
Beta Was this translation helpful? Give feedback.
-
This issue has a demo of |
Beta Was this translation helpful? Give feedback.
-
I’ve been unable to find a simple & portable
getch
implementation for Elixir. The use case is to detect single keypress events, without needing the return key.Comparable tools like inquirer/npm and tty/ruby use
getch
to build features like type-ahead, pull-down menus, etc.To implement
getch
I've looked at ex_ncurses, rustler, System.cmd, Ports, etc. This is the best I’ve come up with so far:This works on my Linux dev machine, but depends on Ruby.
Does anyone know of a portable
getch
implementation? Maybe with Rustler or precompiled binaries or ???Beta Was this translation helpful? Give feedback.
All reactions