Skip to content

Commit

Permalink
chore: rebase branch
Browse files Browse the repository at this point in the history
  • Loading branch information
orochaa committed Jan 11, 2025
1 parent dfc587e commit de45a4e
Show file tree
Hide file tree
Showing 5 changed files with 246 additions and 314 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"
}
}
}
25 changes: 12 additions & 13 deletions packages/core/src/prompts/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ export interface PromptOptions<Self extends Prompt> {
signal?: AbortSignal;
}

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

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

export interface FormatLineOptions {
Expand Down Expand Up @@ -338,8 +336,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 @@ -401,14 +399,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 @@ -426,9 +424,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 de45a4e

Please sign in to comment.