[RDY] Fix shell command output

Shell command output was broken in @8a5a8db, which refactored nvim to no longer
switch to cooked mode(linefeeds are processed differently).

Fix the problem by refactoring write_output to accept to extra arguments that
control the flushing behavior and where data will be written to: buffer or
raw editor screen.

Close #1612.
Can we be sure that `output` is always `NUL` terminated?