Skip to content

Commit

Permalink
Merge pull request #20 from LexBorisoff/dev
Browse files Browse the repository at this point in the history
Merge dev into main
  • Loading branch information
LexBorisoff authored Jan 24, 2025
2 parents f61190c + 788d824 commit 6d335c8
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
7 changes: 1 addition & 6 deletions lib/elements/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,7 @@ class AutocompletePrompt extends Prompt {
if (this.clearFirst && this.input.length > 0) {
this.reset();
} else {
this.done = this.exited = true;
this.aborted = false;
this.fire();
this.render();
this.out.write('\n');
this.close();
this.abort();
}
}

Expand Down
5 changes: 3 additions & 2 deletions lib/elements/number.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,11 @@ class NumberPrompt extends Prompt {
render() {
if (this.closed) return;
if (!this.firstRender && this.outputError) {
this.out.write(cursor.restore);
this.out.write(
cursor.down(lines(this.outputError, this.out.columns) - 1) +
clear(this.outputError, this.out.columns),
cursor.down(lines(this.outputError, this.out.columns) - 1),
);
this.clear = clear(this.outputError, this.out.columns);
}
super.render();
this.outputError = '';
Expand Down
5 changes: 3 additions & 2 deletions lib/elements/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,11 @@ class TextPrompt extends Prompt {
render() {
if (this.closed) return;
if (!this.firstRender && this.outputError) {
this.out.write(cursor.restore);
this.out.write(
cursor.down(lines(this.outputError, this.out.columns) - 1) +
clear(this.outputError, this.out.columns),
cursor.down(lines(this.outputError, this.out.columns) - 1),
);
this.clear = clear(this.outputError, this.out.columns);
}
super.render();
this.outputError = '';
Expand Down
17 changes: 15 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
BaseConfig,
BaseReturn,
MultiSelectReturn,
NumberReturn,
SelectConfig,
SelectReturn,
ToggleConfig,
Expand Down Expand Up @@ -92,8 +93,20 @@ const prompts = {
async number<Name extends string = string>(
config: BaseConfig<Name>,
options?: Options,
): BaseReturn<Name> {
return await $_({ ...config, type: 'number' }, options);
): NumberReturn<Name> {
return await $_(
{
validate(input) {
return typeof input === 'number' || 'Enter a valid number';
},
...config,
type: 'number',
format(input) {
return Number(input);
},
},
options,
);
},

async list<Name extends string = string>(
Expand Down
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export type MultiSelectReturn<
[K in Name]: C['value'][] | undefined;
}>;

export type NumberReturn<Name extends string = string> = Promise<{
[K in Name]: number | undefined;
}>;

/* ~~~ TOGGLE ~~~ */
export interface ToggleConfig<Name extends string> extends BaseConfig<Name> {
active?: string;
Expand Down

0 comments on commit 6d335c8

Please sign in to comment.