Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux Terminal Characters Show Up as Symbols Rather Than As Typed On Keyboard

I am using Ocaml from a Linux terminal. Sometimes it gets stuck in a weird mode where it does not respond to my keyboard as expected. For example, if I press the arrows up, down, right, and left, it generates ^[[A^[[B^[[C^[[D in input. Alternatively, sometimes if I type a letter only once it might repeat that same letter three times in a row and/or if I type the delete button it types "^H" instead.

Does anyone know what is going on here? I assume that I am inadvertently doing something to switch the mode but I don't how to switch it back or why it is switching in the first place.

like image 866
user2174 Avatar asked Feb 18 '23 12:02

user2174


2 Answers

I believe this is essentially a duplicate of this other Stack Overflow question:

Is it possible to use arrow keys in OCaml interpreter?

The stock version of the OCaml interpreter doesn't interpret special keys like arrow keys. So it will just echo their control codes (as Ben Graham points out). To get the kind of behavior you probably want (editing the input, going back to previous lines, etc.) you need to wrap the OCaml interpreter with a line editing facility. See the other question linked above for some suggestions.

This doesn't explain why you see different "modes" of behavior, but I still think this is how you want to think about your problem.

like image 167
Jeffrey Scofield Avatar answered Feb 21 '23 22:02

Jeffrey Scofield


You should use Utop. Utop is a OCaml interpreter which offers auto-completion (like bash) and a history of command. Of course, all problems with arrow keys disappears.

You'll need to compile Zed and Lambda-Term to compile Utop.

like image 22
Ontologiae Avatar answered Feb 21 '23 23:02

Ontologiae