Linux terminal characters are displayed as characters, not as on a keyboard

I am using Ocaml from a Linux terminal. Sometimes it gets stuck in weird mode when it doesn't respond to the keyboard as expected. For example, if I press the up, down, left and right arrows, it generates ^[[A^[[B^[[C^[[D at the input. Alternatively, sometimes if I type the letter only once, it can repeat the same letter three times in a row and / or if I type the delete button, it will instead type β€œ^ H”.

Does anyone know what is going on here? I assume that I inadvertently do something to switch the mode, but I cannot switch it or why it switches in the first place.

+4
source share
2 answers

I believe this is essentially a duplicate of this other stack overflow question:

Can I use the arrow keys in the OCaml interpreter?

The original version of the OCaml interpreter does not interpret special keys, such as arrow keys. That way, it will simply reflect their control codes (as Ben Graham points out). To get the behavior that you probably want (editing input, returning to previous lines, etc.), you need to wrap the OCaml interpreter with a line editing tool. See Another question related above for some suggestions.

This does not explain why you see different β€œmodes” of behavior, but I still think that you want to think about your problem this way.

+6
source

You must use Utop. Utop is an OCaml interpreter that offers autocomplete (e.g. bash) and command history. Of course, all problems with the arrows disappear.

You will need to compile Zed and Lambda-Term to compile Utop.

+2
source

Source: https://habr.com/ru/post/1445913/


All Articles