(toplevel) Small terminal screens do not fit and causes rendering error

Summary

To save your time, let’s jump to the conclusion:

OCaml’s default toplevel / interactive shell probably has some render issues. If you try:

4nji@Gra ~/d/o/pdf_copypaste> ocaml
OCaml version 5.0.0
Enter #help;; for help.

# Unix.sleep 1;;

You’ll get:

Alert ocaml_deprecated_auto_include:
OCaml's lib directory layout changed in 5.0. The unix subdirectory has been
# Unix.sleep 1;;ded to the search path, but you should add -I +unix to the
command-line to silence this alert (e.g. by adding unix to the list of
libraries in your dune file, or adding use_unix to your _tags file for
ocamlbuild, or using -package unix for ocamlfind).
Error: Reference to undefined global `Unix'
#

Notice that the 3rd line of Alert message was overwritten by my previous input, causing confusion.

You’ll need a window-sized terminal (with <= 65 columns) which has a rather small screen buffer to reproduce the bug.

(end of summary)



Hello! A very random topic / issue / question here. Could be a bug tho.

~/ocaml $ rlwrap ocaml
OCaml version 5.1.0+dev1-2022-06-09
Enter #help;; for help.

# Unix.sleep 1;;
Alert ocaml_deprecated_auto_include:
OCaml's lib directory layout changed in 5.0. The unix subdirectory has been
automatically added to the search path, but yo# Unix.sleep 1;;+unix to the
command-line to silence this alert (e.g. by adding unix to the list of
libraries in your dune file, or adding use_unix to your _tags file for
ocamlbuild, or using -package unix for ocamlfind).

Error: Reference to undefined global `Unix'
Hint: This means that the interface of a module is loaded, but its implementation is not.
      Found /data/data/com.termux/files/usr/lib/ocaml/unix/unix.cma
      in the load paths. Did you mean to load it using #load "unix.cma"
      or by passing it as an argument to the toplevel?
#

Then I Ctrl-D to terminate the process and changed the columns & rows of my terminal, then do the same thing again

~/ocaml $ rlwrap ocaml
OCaml version 5.1.0+dev1-2022-06-09
Enter #help;; for help.

# Unix.sleep 1;;
Alert ocaml_deprecated_auto_include:
OCaml's lib directory layout changed in 5.0. The unix subdirectory has been
# Unix.sleep 1;;ded to the search path, but you should add -I +unix to the
command-line to silence this alert (e.g. by adding unix to the list of
libraries in your dune file, or adding use_unix to your _tags file for
ocamlbuild, or using -package unix for ocamlfind).

Error: Reference to undefined global `Unix'
Hint: This means that the interface of a module is loaded, but its implementation is not.
      Found /data/data/com.termux/files/usr/lib/ocaml/unix/unix.cma
      in the load paths. Did you mean to load it using #load "unix.cma"
      or by passing it as an argument to the toplevel?

What am I missing here? Is this a random bug?


update

I tried this on my macOS with OCaml 5.0.0, I think it’s officially a bug now

4nji@Gra ~> rlwrap ocaml
OCaml version 5.0.0
Enter #help;; for help.

# Unix.sleep 1;;
Alert ocaml_deprecated_auto_include:
OCaml's lib directory layout changed in 5.0. The unix subdirectory has been
# Unix.sleep 1;;ded to the search path, but you should add -I +unix to the
command-line to silence this alert (e.g. by adding unix to the list of
libraries in your dune file, or adding use_unix to your _tags file for
ocamlbuild, or using -package unix for ocamlfind).
Error: Reference to undefined global `Unix'
#

Both Android (Termux) and macOS Big Sur have the same issue

I am not sure sure what bug you are trying to describe?

The console output was messed up

Ok, this indeed looks like some strange interaction between the REPL and the terminal line wrapping.

1 Like

Should I open an issue on github page?

Recording the issue might be a good idea.

So the bug goes like this: if you’re using a window-sized terminal which does not have enough screen buffer - like an Android smartphone, or a window-sized terminal on your PC, the error message would be overwritten by user’s input

4nji@Gra ~> rlwrap ocaml
OCaml version 5.0.0
Enter #help;; for help.

# Unix.sleep 1;;
Alert ocaml_deprecated_auto_include:
OCaml's lib directory layout changed in 5.0. The unix subdirectory has been
# Unix.sleep 1;;ded to the search path, but you should add -I +unix to the
command-line to silence this alert (e.g. by adding unix to the list of
libraries in your dune file, or adding use_unix to your _tags file for
ocamlbuild, or using -package unix for ocamlfind).
Error: Reference to undefined global `Unix'
#
4nji@Gra ~> python3 -c 'import os; print(os.get_terminal_size())'
os.terminal_size(columns=65, lines=17)
4nji@Gra ~>

I noticed that the error message output’s size (columns & rows) was hard-coded


Update

I changed the post’s title and opened an issue on github. I’m not sure if this is a rlwrap problem or OCaml default toplevel problem.

Update again

It’s a confirmed toplevel problem, cuz I tried without rlwrap.