Skip to content

Commit 6dc8a34

Browse files
committed
feat: Added checking state to password input
1 parent 9054e65 commit 6dc8a34

3 files changed

Lines changed: 13 additions & 8 deletions

File tree

src/ui/components/default-component.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ export function DefaultComponent(props: {
8484
{
8585
renderStatus === RenderStatus.SUDO_PROMPT && (
8686
<SudoPasswordInput
87-
key={renderData as number}
88-
hasError={(renderData as number) > 0}
87+
key={(renderData as { attemptCount: number }).attemptCount}
88+
hasError={(renderData as { attemptCount: number }).attemptCount > 0}
89+
cancellable={(renderData as { cancellable: boolean }).cancellable}
8990
onSubmit={(password) => emitter.emit(RenderEvent.SUDO_PROMPT_RESULT, password)}
9091
onCancel={() => emitter.emit(RenderEvent.SUDO_PASSWORD_CANCEL)}
9192
/>

src/ui/components/widgets/SudoPasswordInput.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import Spinner from '../progress/spinner.js';
55

66
export function SudoPasswordInput(props: {
77
hasError: boolean;
8+
cancellable: boolean;
89
onSubmit: (password: string) => void;
910
onCancel: () => void;
1011
}) {
11-
const { hasError, onSubmit, onCancel } = props;
12+
const { hasError, cancellable, onSubmit, onCancel } = props;
1213
const [value, setValue] = useState('');
1314
const [isChecking, setIsChecking] = useState(false);
1415

@@ -17,7 +18,7 @@ export function SudoPasswordInput(props: {
1718
useInput((input, key) => {
1819
if (isChecking) return;
1920

20-
if (key.escape) {
21+
if (key.escape && cancellable) {
2122
onCancel();
2223
return;
2324
}
@@ -61,7 +62,7 @@ export function SudoPasswordInput(props: {
6162
</Box>
6263
)}
6364
{hasError && <Text color="red">Incorrect password, try again</Text>}
64-
{!isChecking && <Text dimColor>Enter to confirm · Esc to cancel</Text>}
65+
{!isChecking && <Text dimColor>Enter to confirm{cancellable ? ' · Esc to cancel' : ''}</Text>}
6566
</Box>
6667
);
6768
}

src/ui/reporters/default-reporter.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import React from 'react';
88
import { Plan } from '../../entities/plan.js';
99
import { ResourceConfig } from '../../entities/resource-config.js';
1010
import { ResourceInfo } from '../../entities/resource-info.js';
11-
import { Event, ProcessName, SubProcessName, ctx } from '../../events/context.js';
11+
import { ctx, Event, ProcessName, SubProcessName } from '../../events/context.js';
1212
import { FileModificationResult } from '../../generators/index.js';
1313
import { ImportResult } from '../../orchestrators/import.js';
1414
import { sleep } from '../../utils/index.js';
@@ -332,7 +332,7 @@ export class DefaultReporter implements Reporter {
332332

333333
while (attemptCount < 3) {
334334
const result = (await Promise.all([
335-
this.updateRenderState(RenderStatus.SUDO_PROMPT, attemptCount),
335+
this.updateRenderState(RenderStatus.SUDO_PROMPT, { attemptCount, cancellable: true }),
336336
Promise.race([
337337
this.awaitEvent<string>(RenderEvent.SUDO_PROMPT_RESULT),
338338
this.awaitEvent<'cancel'>(RenderEvent.SUDO_PASSWORD_CANCEL).then(() => Symbol.for('cancel')),
@@ -372,9 +372,12 @@ export class DefaultReporter implements Reporter {
372372
private async getUserPassword(): Promise<string> {
373373
let attemptCount = 0;
374374

375+
this.updateRenderState(RenderStatus.NOTHING);
376+
await sleep(50);
377+
375378
while (attemptCount < 3) {
376379
const passwordAttempt = await this.updateStateAndAwaitEvent<string>(
377-
() => this.updateRenderState(RenderStatus.SUDO_PROMPT, attemptCount),
380+
() => this.updateRenderState(RenderStatus.SUDO_PROMPT, { attemptCount, cancellable: false }),
378381
RenderEvent.SUDO_PROMPT_RESULT,
379382
);
380383

0 commit comments

Comments
 (0)