| 424 | this.subscribers.clear(); |
| 425 | } |
| 426 | onKeypress(u3, F5) { |
| 427 | if (this.state === "error" && (this.state = "active"), F5?.name && !this._track && z3.has(F5.name) && this.emit("cursor", z3.get(F5.name)), F5?.name && lD2.has(F5.name) && this.emit("cursor", F5.name), u3 && (u3.toLowerCase() === "y" || u3.toLowerCase() === "n") && this.emit("confirm", u3.toLowerCase() === "y"), u3 === " " && this.opts.placeholder && (this.value || (this.rl.write(this.opts.placeholder), this.emit("value", this.opts.placeholder))), u3 && this.emit("key", u3.toLowerCase()), F5?.name === "return") { |
| 428 | if (this.opts.validate) { |
| 429 | const e3 = this.opts.validate(this.value); |
| 430 | e3 && (this.error = e3, this.state = "error", this.rl.write(this.value)); |
| 431 | } |
| 432 | this.state !== "error" && (this.state = "submit"); |
| 433 | } |
| 434 | u3 === "" && (this.state = "cancel"), (this.state === "submit" || this.state === "cancel") && this.emit("finalize"), this.render(), (this.state === "submit" || this.state === "cancel") && this.close(); |
| 435 | } |
| 436 | close() { |
| 437 | this.input.unpipe(), this.input.removeListener("keypress", this.onKeypress), this.output.write(` |
| 438 | `), v3(this.input, false), this.rl.close(), this.emit(`${this.state}`, this.value), this.unsubscribe(); |