pty: Rework the pty layer to use the normal buffering logic