gui: Simplify handle_command() and avoid a buffer overflow.