I have found out that MongoDB Shell have built in terminal device on which the user enters a stream of data and it manage cursor position etc ( using linenoise that is a readline replacement ) . It read a keystroke from the keyboard and translate it using the function readUnicodeCharacter to get Unicode (UChar32) character.
Why usage of simple code with scanf instead of custom console terminal is not good enough?
Line editing libraries like Readline and Linenoise provides extra functionality over just reading raw character input. Linenoise aims to provide common line editing features in a much more concise package than Readline.
Core Linenoise features include support for:
Single and multi line editing mode with the usual key bindings implemented.
History handling.
Completion.
Hints (suggestions at the right of the prompt as you type).
The mongo shell version of Linenoise has also evolved with additional keyboard shortcuts and cross-platform behaviour.
However, Linenoise is only used in the legacy mongo shell.