Terminal Emulator State Machine