2
votes

I want to write a shell in Erlang. The shell needs to get one line command from user (stdin) and that one line should be editable. I need to provide history of commands to user. For example by pressing up arrow key user should see previous command. But how can we read only one character in Erlang and see if that's up arrow key?

1

1 Answers

1
votes

Normally to write a good shell you have to control the terminal. And terminal-controlling functions are platform-specific. For example for Linux it will be "tcgetattr", "tcsetattr" stdlib functions.

If you really want to write a good terminal, you have to take a look at

  1. "Unix/Linux programming. Theory and Practice", Bruce Molay. You need chapter 5(about terminals)

  2. Take a look at uart application and Try to follow this advice

  3. Also you can read about erlang drivers(preferrable way) and erlang ports

By using drivers and ports, you can extend erlang with functionality which it doesn't have. (you can write them in C, for ex)

You can read about ports and drivers in "Erlang Programming"(Francesco Cesarini and Simon Thompson) chapter 16. You can get the difference between ports and linked-in drivers there.