handle switch between raw and line mode correctly