Fix run disconnect behavious in tty mode + add unit test to enforce it
Make sure to flush buffer when setting raw mode