[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.
If the call to `shell()` fails (`status  == -1`), the variable `nread` is not initialized. Can there still be output?