Skip to content

Commit

Permalink
chore: rebase branch
Browse files Browse the repository at this point in the history
  • Loading branch information
orochaa committed Dec 15, 2024
1 parent 69b7030 commit b780203
Show file tree
Hide file tree
Showing 6 changed files with 257 additions and 324 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
"volta": {
"node": "20.18.1"
}
}
}
19 changes: 10 additions & 9 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
export { default as ConfirmPrompt } from "./prompts/confirm";
export { default as GroupMultiSelectPrompt } from "./prompts/group-multiselect";
export { default as MultiSelectPrompt } from "./prompts/multi-select";
export { default as PasswordPrompt } from "./prompts/password";
export { default as Prompt, State } from "./prompts/prompt";
export { default as SelectPrompt } from "./prompts/select";
export { default as SelectKeyPrompt } from "./prompts/select-key";
export { default as TextPrompt } from "./prompts/text";
export { block, isCancel, strLength, setGlobalAliases } from "./utils";
export { default as ConfirmPrompt } from './prompts/confirm';
export { default as GroupMultiSelectPrompt } from './prompts/group-multiselect';
export { default as MultiSelectPrompt } from './prompts/multi-select';
export { default as PasswordPrompt } from './prompts/password';
export { default as Prompt } from './prompts/prompt';
export { default as SelectPrompt } from './prompts/select';
export { default as SelectKeyPrompt } from './prompts/select-key';
export { default as TextPrompt } from './prompts/text';
export type { ClackState as State } from './types';
export { block, isCancel, strLength, setGlobalAliases } from './utils';
25 changes: 12 additions & 13 deletions packages/core/src/prompts/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ export interface PromptOptions<Self extends Prompt> {
debug?: boolean;
}

export type State = 'initial' | 'active' | 'cancel' | 'submit' | 'error';

export type LineOption = 'firstLine' | 'newLine' | 'lastLine';

export interface FormatLineOptions {
Expand Down Expand Up @@ -313,8 +311,8 @@ export default class Prompt {
): NonNullable<FormatOptions[TLine][TKey]> => {
return (
key === 'style'
? options?.[line]?.[key] ?? options?.default?.[key] ?? ((line) => line)
: options?.[line]?.[key] ?? options?.[line]?.sides ?? options?.default?.[key] ?? ''
? (options?.[line]?.[key] ?? options?.default?.[key] ?? ((line) => line))
: (options?.[line]?.[key] ?? options?.[line]?.sides ?? options?.default?.[key] ?? '')
) as NonNullable<FormatOptions[TLine][TKey]>;
};
const getLineOptions = (line: LineOption): Omit<FormatLineOptions, 'sides'> => {
Expand Down Expand Up @@ -376,14 +374,14 @@ export default class Prompt {
): FormatLineOptions[TPosition] => {
return (
i === 0 && ar.length === 1
? options?.firstLine?.[position] ??
options?.lastLine?.[position] ??
firstLine[position]
? (options?.firstLine?.[position] ??
options?.lastLine?.[position] ??
firstLine[position])
: i === 0
? firstLine[position]
: i + 1 === ar.length
? lastLine[position]
: newLine[position]
? firstLine[position]
: i + 1 === ar.length
? lastLine[position]
: newLine[position]
) as FormatLineOptions[TPosition];
};
const startLine = opt('start');
Expand All @@ -401,9 +399,10 @@ export default class Prompt {
.join('\n');
}

private _prevFrame = '';
private render() {
const frame = wrap(this._render(this) ?? '', process.stdout.columns, { hard: true });
const frame = wrap(this._render(this) ?? '', process.stdout.columns, {
hard: true,
});
if (frame === this._prevFrame) return;

if (this.state === 'initial') {
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ export function strLength(str: string): number {
}

// Remove ANSI escape codes from the input string.
str = stripAnsi(str);
const stripedStr = stripAnsi(str);

let length = 0;

for (let i = 0; i < str.length; i++) {
const code = str.codePointAt(i);
for (let i = 0; i < stripedStr.length; i++) {
const code = stripedStr.codePointAt(i);

if (!code || isControlCharacter(code) || isCombiningCharacter(code)) {
continue;
Expand Down
Loading

0 comments on commit b780203

Please sign in to comment.