Skip to content

Commit 8e66d58

Browse files
committed
fix(@inquirer/password): keep trailing space after message in empty state
1 parent 98f5ad3 commit 8e66d58

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

‎packages/password/password.vitest.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,35 @@
11
import { describe, it, expect } from 'vitest';
22
import { render } from '@inquirer/testing';
3+
import { cursorTo } from '@inquirer/ansi';
4+
import { stripVTControlCharacters } from 'node:util';
35
import password from './src/index.ts';
46

57
describe('password prompt', () => {
8+
it('keeps a trailing space after the message before the first character is typed', async () => {
9+
// Regression test for #2360: while the masked value is empty, the prompt
10+
// line must still claim the separator slot after the message, so the
11+
// cursor sits one column past it (as if a space was typed) instead of
12+
// right against the message. The renderer trims trailing spaces from the
13+
// visible line, so assert on the raw render's final cursor position.
14+
const { events, getScreen } = await render(password, {
15+
message: 'Enter your password',
16+
mask: true,
17+
});
18+
19+
const raw = getScreen({ raw: true });
20+
const promptLine = stripVTControlCharacters(raw).split('\n')[0] ?? '';
21+
expect(promptLine).toBe('? Enter your password');
22+
// One 1-indexed column for the separator space, one for the cursor itself.
23+
expect(raw.endsWith(cursorTo(promptLine.length + 1))).toBe(true);
24+
25+
events.type('J');
26+
const typedRaw = getScreen({ raw: true });
27+
const typedLine = stripVTControlCharacters(typedRaw).split('\n')[0] ?? '';
28+
expect(typedLine).toBe('? Enter your password *');
29+
// Once the value is non-empty, the mask character takes the separator slot.
30+
expect(typedRaw.endsWith(cursorTo(typedLine.length))).toBe(true);
31+
});
32+
633
it('handle muted input', async () => {
734
const { answer, events, getScreen } = await render(password, {
835
message: 'Enter your password',

‎packages/password/src/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export default createPrompt<string, PasswordConfig>((config, done) => {
9797
formattedValue += cursorHide;
9898
}
9999

100-
const content = [prefix, message, formattedValue].filter(Boolean).join(' ');
100+
const content = [prefix, message, formattedValue].join(' ');
101101
const bottomContent = [
102102
errorMsg ? theme.style.error(errorMsg) : '',
103103
toggleMask && status === 'idle'

0 commit comments

Comments
 (0)