Simple JavaScript Terminal & State Machine