@@ -40827,7 +40827,7 @@ function useKeypress(userHandler) {
4082740827 const handler2 = withUpdates((_input, event) => {
4082840828 if (ignore)
4082940829 return;
40830- signal.current(event, rl);
40830+ void signal.current(event, rl);
4083140831 });
4083240832 rl.input.on("keypress", handler2);
4083340833 return () => {
@@ -41174,6 +41174,9 @@ var import_strip_ansi = __toESM(require_strip_ansi(), 1);
4117441174var import_ansi_escapes = __toESM(require_ansi_escapes(), 1);
4117541175var height = (content) => content.split("\n").length;
4117641176var lastLine = (content) => content.split("\n").pop() ?? "";
41177+ function cursorDown(n) {
41178+ return n > 0 ? import_ansi_escapes.default.cursorDown(n) : "";
41179+ }
4117741180var ScreenManager = class {
4117841181 rl;
4117941182 height = 0;
@@ -41184,6 +41187,11 @@ var ScreenManager = class {
4118441187 this.rl = rl;
4118541188 this.cursorPos = rl.getCursorPos();
4118641189 }
41190+ write(content) {
41191+ this.rl.output.unmute();
41192+ this.rl.output.write(content);
41193+ this.rl.output.mute();
41194+ }
4118741195 render(content, bottomContent = "") {
4118841196 const promptLine = lastLine(content);
4118941197 const rawPromptLine = (0, import_strip_ansi.default)(promptLine);
@@ -41205,44 +41213,23 @@ var ScreenManager = class {
4120541213 if (bottomContentHeight > 0)
4120641214 output += import_ansi_escapes.default.cursorUp(bottomContentHeight);
4120741215 output += import_ansi_escapes.default.cursorTo(this.cursorPos.cols);
41208- this.clean();
41209- this.rl.output.unmute();
41216+ this.write(cursorDown(this.extraLinesUnderPrompt) + import_ansi_escapes.default.eraseLines(this.height) + output);
4121041217 this.extraLinesUnderPrompt = bottomContentHeight;
4121141218 this.height = height(output);
41212- this.rl.output.write(output);
41213- this.rl.output.mute();
4121441219 }
4121541220 checkCursorPos() {
4121641221 const cursorPos = this.rl.getCursorPos();
4121741222 if (cursorPos.cols !== this.cursorPos.cols) {
41218- this.rl.output.unmute();
41219- this.rl.output.write(import_ansi_escapes.default.cursorTo(cursorPos.cols));
41220- this.rl.output.mute();
41223+ this.write(import_ansi_escapes.default.cursorTo(cursorPos.cols));
4122141224 this.cursorPos = cursorPos;
4122241225 }
4122341226 }
41224- clean() {
41225- this.rl.output.unmute();
41226- this.rl.output.write([
41227- this.extraLinesUnderPrompt > 0 ? import_ansi_escapes.default.cursorDown(this.extraLinesUnderPrompt) : "",
41228- import_ansi_escapes.default.eraseLines(this.height)
41229- ].join(""));
41230- this.extraLinesUnderPrompt = 0;
41231- this.rl.output.mute();
41232- }
41233- clearContent() {
41234- this.rl.output.unmute();
41235- this.rl.output.write([
41236- this.extraLinesUnderPrompt > 0 ? import_ansi_escapes.default.cursorDown(this.extraLinesUnderPrompt) : "",
41237- "\n"
41238- ].join(""));
41239- this.rl.output.mute();
41240- }
41241- done() {
41227+ done({ clearContent }) {
4124241228 this.rl.setPrompt("");
41243- this.rl.output.unmute();
41244- this.rl.output.write(import_ansi_escapes.default.cursorShow);
41245- this.rl.output.end();
41229+ let output = cursorDown(this.extraLinesUnderPrompt);
41230+ output += clearContent ? import_ansi_escapes.default.eraseLines(this.height) : "\n";
41231+ output += import_ansi_escapes.default.cursorShow;
41232+ this.write(output);
4124641233 this.rl.close();
4124741234 }
4124841235};
@@ -41279,12 +41266,7 @@ function createPrompt(view) {
4127941266 });
4128041267 function onExit2() {
4128141268 hooksCleanup();
41282- if (context3 == null ? void 0 : context3.clearPromptOnDone) {
41283- screen.clean();
41284- } else {
41285- screen.clearContent();
41286- }
41287- screen.done();
41269+ screen.done({ clearContent: Boolean(context3 == null ? void 0 : context3.clearPromptOnDone) });
4128841270 removeExitListener();
4128941271 rl.input.removeListener("keypress", checkCursorPos);
4129041272 rl.removeListener("close", hooksCleanup);
@@ -41717,7 +41699,7 @@ var esm_default2 = createPrompt((config2, done) => {
4171741699 if (Separator.isSeparator(item)) {
4171841700 return ` ${item.separator}`;
4171941701 }
41720- const line = item.name || item.value;
41702+ const line = String( item.name || item.value) ;
4172141703 if (item.disabled) {
4172241704 const disabledLabel = typeof item.disabled === "string" ? item.disabled : "(disabled)";
4172341705 return theme.style.disabledChoice(`${line} ${disabledLabel}`);
@@ -41768,7 +41750,7 @@ ${page}${helpTipBottom}${error2}${import_ansi_escapes2.default.cursorHide}`;
4176841750var import_external_editor = __toESM(require_main2(), 1);
4176941751import { AsyncResource as AsyncResource4 } from "node:async_hooks";
4177041752var esm_default3 = createPrompt((config2, done) => {
41771- const { waitForUseInput = true, validate = () => true } = config2;
41753+ const { waitForUseInput = true, postfix = ".txt", validate = () => true } = config2;
4177241754 const theme = makeTheme(config2.theme);
4177341755 const [status, setStatus] = useState("pending");
4177441756 const [value, setValue] = useState(config2.default || "");
@@ -41777,30 +41759,25 @@ var esm_default3 = createPrompt((config2, done) => {
4177741759 const prefix = usePrefix({ isLoading, theme });
4177841760 function startEditor(rl) {
4177941761 rl.pause();
41780- (0, import_external_editor.editAsync)(
41781- value,
41782- AsyncResource4.bind(async (error3, answer) => {
41783- rl.resume();
41784- if (error3) {
41785- setError(error3.toString());
41762+ const editCallback = AsyncResource4.bind(async (error3, answer) => {
41763+ rl.resume();
41764+ if (error3) {
41765+ setError(error3.toString());
41766+ } else {
41767+ setStatus("loading");
41768+ const isValid = await validate(answer);
41769+ if (isValid === true) {
41770+ setError(void 0);
41771+ setStatus("done");
41772+ done(answer);
4178641773 } else {
41787- setStatus("loading");
41788- const isValid = await validate(answer);
41789- if (isValid === true) {
41790- setError(void 0);
41791- setStatus("done");
41792- done(answer);
41793- } else {
41794- setValue(answer);
41795- setError(isValid || "You must provide a valid value");
41796- setStatus("pending");
41797- }
41774+ setValue(answer);
41775+ setError(isValid || "You must provide a valid value");
41776+ setStatus("pending");
4179841777 }
41799- }),
41800- {
41801- postfix: config2.postfix || ".txt"
4180241778 }
41803- );
41779+ });
41780+ (0, import_external_editor.editAsync)(value, (error3, answer) => void editCallback(error3, answer), { postfix });
4180441781 }
4180541782 useEffect((rl) => {
4180641783 if (!waitForUseInput) {
@@ -42019,7 +41996,7 @@ ${theme.style.help("(Use arrow keys to reveal more choices)")}`;
4201941996 if (Separator.isSeparator(item)) {
4202041997 return ` ${item.separator}`;
4202141998 }
42022- const line = item.name || item.value;
41999+ const line = String( item.name || item.value) ;
4202342000 if (item.disabled) {
4202442001 const disabledLabel = typeof item.disabled === "string" ? item.disabled : "(disabled)";
4202542002 return theme.style.disabled(`${line} ${disabledLabel}`);
0 commit comments