Guard that restores the terminal (leave alternate screen, show cursor,
disable bracketed paste) when dropped. Generic over W so tests can
inject a Vec<u8> writer and verify the teardown sequences.
Initialize terminal for TUI mode: write startup escape sequences
(alternate screen, hide cursor, bracketed paste, mouse capture) to
the given writer, enable raw mode on stdin, and return a guard that
restores the terminal on drop.