Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/core/src/lib/key.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export type KeypressEvent = {
name: string;
ctrl: boolean;
shift: boolean;
};

export const isUpKey = (key: KeypressEvent): boolean =>
Expand Down
10 changes: 7 additions & 3 deletions packages/input/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
transformer?: (value: string, { isFinal }: { isFinal: boolean }) => string;
validate?: (value: string) => boolean | string | Promise<string | boolean>;
theme?: PartialDeep<Theme<InputTheme>>;
multiline?: boolean;
};

export default createPrompt<string, InputConfig>((config, done) => {
Expand All @@ -44,8 +45,8 @@
return;
}

if (isEnterKey(key)) {
const answer = value || defaultValue;
if (isEnterKey(key) && !key.shift) {
const answer = value.replaceAll('\r', '\n') || defaultValue;
setStatus('loading');

const isValid =
Expand All @@ -65,6 +66,9 @@
setError(isValid || 'You must provide a valid value');
setStatus('idle');
}
} else if (isEnterKey(key) && key.shift && config.multiline) {
setValue(value + '\r');
rl.write('\r');

Check warning on line 71 in packages/input/src/index.ts

View check run for this annotation

Codecov / codecov/patch

packages/input/src/index.ts#L70-L71

Added lines #L70 - L71 were not covered by tests
} else if (isBackspaceKey(key) && !value) {
setDefaultValue(undefined);
} else if (key.name === 'tab' && !value) {
Expand All @@ -79,7 +83,7 @@
});

const message = theme.style.message(config.message, status);
let formattedValue = value;
let formattedValue = value.replaceAll('\r', '\n');
if (typeof config.transformer === 'function') {
formattedValue = config.transformer(value, { isFinal: status === 'done' });
} else if (status === 'done') {
Expand Down