# Prompt

Dusk's main loop endlessly consumes text coming from "in<". If you plug your
input (for example the keyboard device) directly on it, words will be executed
as soon as you type a whitespace. This behavior is generally uncomfortable
because we expect the system to consume what we type in a line-by-line manner.

The unit at [io/prompt.fs] provides "prompt ( -- ?a u )", a word that is
compatible with NEXTIN< [doc/usage/io] and does the following:

1. Buffer input without interpreting it immediately.
2. When we begin buffering a line, prompt with "ok\n".
3. Echo every character received.
4. When backspace (ASCII $08) is received, go back one character in the buffer
   and emit backspace+space (unless of course we're at the beginning of the
   buffer).
5. Replace CR (ASII $0d) keys with LF (ASCII $0a).
6. If ESC is pressed (ASCII $1b), flush the line and don't interpret it.
7. If any other ASCII control character is received (< $20), flush the line and
   interpret it.

To install it, you can call "prompt$ ( -- )", which installs itself at the
appropriate places:

1. Set the "abort" alias to its regular "(abort)" target (prompt is usually
   installed during boot, at which time "abort" points to a word that spits
   "boot failure" and halts the machine)
2. Add a "quit hook" [doc/usage/flow] that sets NEXTIN< to "prompt".

It *doesn't* set itself as input right away, the idea being that "prompt$" if
often called in an initialization context and there is generally a need for
further initialization before we give the wheel to the operator.

Therefore, after having called "prompt$", what you'll want to do to actually get
into interactive mode is to call "quit".

## API

typeline ( -- ?a u )
  Clear the buffer and type into it through "key" [io/kbd], applying buffering
  rules outlined above. Unless typing ended with a "ESC", yields a range
  containing the typed characters. Otherwise, u=0 and "a" is absent.

  The resulting range contains the "ending character" (LF, etc), which means
  it's never empty. Therefore, there is no ambuiguity between "empty line" (u=1)
  and "pressed ESC" (u=0).

prompt ( -- ?a u )
  Emits "ok\n", then calls "typeline", then emits a newline.

prompt$ ( -- )
  Initializes the unit as described above.
