cli: Fix reverse-line-wrap in terminals (VPP-1295) 69/12969/3
authorChris Luke <chrisy@flirble.org>
Wed, 6 Jun 2018 03:50:19 +0000 (23:50 -0400)
committerFlorin Coras <florin.coras@gmail.com>
Sun, 10 Jun 2018 19:54:08 +0000 (19:54 +0000)
commitfc379d28ab06760c8dcf0d976a5b224f1b062b97
tree26fcf09ebdb7b3221e2574499f5ce13d81ca6444
parent887b7ba8ad000a535ad4b7d730c6f07c0ee65165
cli: Fix reverse-line-wrap in terminals (VPP-1295)

- Terminals do not reverse-line-wrap when the cursor is at the left
  edge and \b tries to make it go left.
- Instead, we have to track the cursor position if we need to emit \b's
  and if we are at the left edge emit an ANSI sequence to relocate
  the cursor. Previously we usually simply calculated the new cursor
  position after a bunch of output had completed.
- Further trickiness is required since most xterm-like terminals also
  defer moving the cursor to the next line when at the right edge[1], and
  then if they receive a \b move the cursor back one character too many.
- This requires intricate reworking of everywhere that \b is emitted
  by the CLI code during command line editing.

[1] Bash counters this issue by tracking the cursor position as output
  is generated and forcing the cursor to the next line (by emitting
  a space followed by \r) if it gets to this phantom cursor position);
  here we effectively do that but only if the user tries to go left
  when in this state.

Change-Id: I7c1d7c0e24c53111a5810cebb504ccfdac743086
Signed-off-by: Chris Luke <chrisy@flirble.org>
src/vlib/unix/cli.c