Json-Rpc user interface
=======================

Kakoune user interfaces can be implemented through the
https://www.jsonrpc.org/specification[json-rpc 2.0 protocol].

By launching Kakoune in client mode with the `-ui json` option, the launched
client will write newline separated json-rpc requests on stdout and read
json-rpc requests on stdin.  Errors will be reported on stderr (not in
json format).

Kakoune requests are always using positional parameters, never named, and
Kakoune won't be able to parse named parameters in requests.

Here are the data structures used:

* Color: a string, either a named color, or #rrggbb, or 'default'
* Attribute: one of {underline, curly_underline, double_underline, reverse, blink, bold, dim, italic, final_fg, final_bg, final_attr}
* Face { Color fg; Color bg; Array<Attribute> attributes; }
* Atom { Face face; String contents; }
* Line : Array of Atom
* Coord { int line; int column }

Here are the requests that can be written by the json ui on stdout:

* draw(Array<Line> lines, Coord cursor_pos, Face default_face, Face padding_face, int widget_columns)
  padding_face is the face of the padding characters '~' in the
  terminal UI.
  cursor_pos is the main cursor coordinates
  widget_columns is the number of columns at the start of each line used by flag-lines highlighters.
* draw_status(Line prompt, Line content, int cursor_pos, Line mode_line, Face default_face,
              String style)
  cursor_pos is the location of the cursor in the content, the UI is expected to trim
  content in order to ensure the cursor stays visible, if cursor_pos is negative, no
  cursor should be displayed in the prompt. Prompt cursor show have priority to buffer
  cursor if only one cursor can be displayed.
  style can be:
  - "command": command prompt (:)
  - "search": search prompt (/, ?)
  - "prompt": general prompt (e.g. pipe, object desc)
  - "status": normal status (file info, echo messages)
* menu_show(Array<Line> items, Coord anchor, Face selected_item_face, Face menu_face,
            String style)
  style can be:
  - prompt: display the menu as a prompt menu (anchor is ignored)
  - inline: display the menu next to (above or below) the anchor coordinate
  - search: display the menu as a search menu (anchor is ignored)
* menu_select(int selected)
* menu_hide()
* info_show(Line title, Array<Line> content, Coord anchor, Face face, String style)
  style can be:
  - prompt: display the info as a prompt info (anchor is ignored)
  - inline: display the info next to (above or below) the anchor coordinate
  - inlineAbove: display the info next to (above) the anchor coordinate
  - inlineBelow: display the info next to (below) the anchor coordinate
  - menuDoc: display the info next to the menu, as a documentation for it
  - modal: display the info in a way that shows Kakoune is waiting for a
    special action related to it.
* info_hide()
* set_ui_options(Map<String, String> options)
  called when ui_options changed with a map of options name to option values
* refresh(bool force)

The requests that the json ui can interpret on stdin are:

* keys(String key1, String key2...): keystrokes
* paste(String content): paste content at selections
* resize(int rows, int columns): notify ui resize
* scroll(int amount, int line, int colum): scroll by given line amount, line and
  column relate to cursor position
* mouse_move(int line, int column): line and column relate to the cursor position.
* mouse_press(String button, int line, int column): line and column relate to
  cursor position, button can be 'left', 'middle' or 'right'
* mouse_release(String button, int line, int column): same.
* menu_select(int index): explicit select of given menu entry
