Skip to content

Commit 9edaa10

Browse files
committed
fix: /logout uses showModal and welcome screen uses FIGlet logo
Switch /logout from broken safePrompt confirm to showModal Yes/No. Upgrade welcome screen with large FIGlet ASCII art for Autohand Code with circle icons and typewriter animation.
1 parent 71e1287 commit 9edaa10

3 files changed

Lines changed: 72 additions & 22 deletions

File tree

‎src/auth/ensureAuth.ts‎

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,49 @@ import { showModal } from '../ui/ink/components/Modal.js';
1212
import packageJson from '../../package.json' with { type: 'json' };
1313
import type { LoadedConfig } from '../types.js';
1414

15-
const AUTOHAND_LOGO = [
16-
' ◎ ◎ ◎ ◎ ▄▀█ █ █ ▀█▀ █▀█ █ █ ▄▀█ █▄ █ █▀▄ ▄▀█ █',
17-
' ◎ ◎ ◎ ◎ █▀█ █▄█ █ █▄█ █▀█ █▀█ █ ▀█ █▄▀ █▀█ █',
18-
].join('\n');
15+
// Large FIGlet ASCII art — circles on left (lines 1-2), "Autohand Code" fills all lines
16+
const LOGO_LINES = [
17+
'◎ ◎ ◎ ◎ ___ __ __ __ ______ __',
18+
'◎ ◎ ◎ ◎ / | __ __/ /_____ / /_ ____ _____ ____/ / / ____/___ ____/ /__',
19+
' / /| |/ / / / __/ __ \\/ __ \\/ __ `/ __ \\/ __ / / / / __ \\/ __ / _ \\',
20+
' / ___ / /_/ / /_/ /_/ / / / / /_/ / / / / /_/ / / /___/ /_/ / /_/ / __/',
21+
' /_/ |_\\__,_/\\__/\\____/_/ /_/\\__,_/_/ /_/\\__,_/ \\____/\\____/\\__,_/\\___/',
22+
];
23+
24+
/**
25+
* Typewriter: circles appear column by column on both rows,
26+
* then the full FIGlet text reveals line by line.
27+
*/
28+
async function typewriteWelcome(startRow: number): Promise<void> {
29+
const hide = '\x1b[?25l';
30+
const show = '\x1b[?25h';
31+
const moveTo = (r: number, c: number) => `\x1b[${r};${c}H`;
32+
33+
process.stdout.write(hide);
34+
35+
// Phase 1: Type circles column by column (both rows at once)
36+
for (let col = 0; col < 4; col++) {
37+
const x = 1 + col * 2; // column position (◎ + space = 2 chars)
38+
process.stdout.write(moveTo(startRow, x) + chalk.white('◎'));
39+
process.stdout.write(moveTo(startRow + 1, x) + chalk.white('◎'));
40+
await new Promise(r => setTimeout(r, 100));
41+
}
42+
43+
await new Promise(r => setTimeout(r, 150));
44+
45+
// Phase 2: Reveal the text portion of each line
46+
for (let i = 0; i < LOGO_LINES.length; i++) {
47+
const line = LOGO_LINES[i];
48+
// For circle lines (0,1), only write the text part after the circles
49+
const textStart = i < 2 ? 9 : 0; // circles take 9 chars "◎ ◎ ◎ ◎ "
50+
const text = i < 2 ? line.slice(textStart) : line;
51+
const col = i < 2 ? 10 : 1;
52+
process.stdout.write(moveTo(startRow + i, col) + chalk.white(text));
53+
await new Promise(r => setTimeout(r, 60));
54+
}
55+
56+
process.stdout.write(show);
57+
}
1958

2059
/**
2160
* Ensure the user is authenticated before proceeding.
@@ -109,19 +148,23 @@ async function promptLogin(config: LoadedConfig): Promise<LoadedConfig> {
109148
// Clear screen and position content vertically centered
110149
process.stdout.write('\x1b[2J\x1b[H');
111150

112-
// The art block: logo + tagline + version + prompt = ~8 lines
113-
const contentHeight = 8;
151+
// Layout: logo (5 lines) + blank + version + blank + modal (~12 lines)
152+
const logoHeight = LOGO_LINES.length;
153+
const contentHeight = logoHeight + 6;
114154
const topPadding = Math.max(0, Math.floor((rows - contentHeight) / 2));
155+
const logoRow = topPadding + 1; // 1-based terminal row
156+
157+
// Typewriter the circles, then reveal the FIGlet text
158+
await typewriteWelcome(logoRow);
115159

116-
process.stdout.write('\n'.repeat(topPadding));
117-
console.log(chalk.white(AUTOHAND_LOGO));
160+
// Position cursor below the logo for version + modal
161+
process.stdout.write(`\x1b[${logoRow + logoHeight};1H`);
118162
console.log();
119-
console.log(chalk.gray(' Your AI-powered coding agent for the terminal'));
120-
console.log(chalk.gray(` ${version}`));
163+
console.log(chalk.gray(` ${version}`));
121164
console.log();
122165

123166
const selected = await showModal({
124-
title: chalk.white('Please sign in to continue.'),
167+
title: chalk.white('Sign in to continue.'),
125168
options: [
126169
{ label: 'Login', value: 'login' },
127170
{ label: 'Exit', value: 'exit' },

‎src/commands/logout.ts‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
import chalk from 'chalk';
77
import { t } from '../i18n/index.js';
8-
import { safePrompt } from '../utils/prompt.js';
8+
import { showModal } from '../ui/ink/components/Modal.js';
99
import type { SlashCommandContext } from '../core/slashCommandTypes.js';
1010
import { getAuthClient } from '../auth/index.js';
1111
import { saveConfig } from '../config.js';
@@ -32,14 +32,15 @@ export async function logout(ctx: LogoutContext): Promise<string | null> {
3232
const userName = config.auth.user?.name || config.auth.user?.email || 'user';
3333

3434
// Confirm logout
35-
const result = await safePrompt<{ confirm: boolean }>({
36-
type: 'confirm',
37-
name: 'confirm',
38-
message: `Log out from ${chalk.cyan(userName)}?`,
39-
initial: true,
35+
const selected = await showModal({
36+
title: `Log out from ${chalk.cyan(userName)}?`,
37+
options: [
38+
{ label: 'Yes', value: 'yes' },
39+
{ label: 'No', value: 'no' },
40+
],
4041
});
4142

42-
if (!result || !result.confirm) {
43+
if (!selected || selected.value === 'no') {
4344
console.log(chalk.gray(t('commands.logout.cancelled')));
4445
return null;
4546
}

‎tests/commands/auth.spec.ts‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ vi.mock('../../src/utils/prompt.js', () => ({
3838
safePrompt: vi.fn(),
3939
}));
4040

41+
// Mock Modal (logout uses showModal instead of safePrompt)
42+
var mockShowModal = vi.fn();
43+
vi.mock('../../src/ui/ink/components/Modal.js', () => ({
44+
showModal: (...args: unknown[]) => mockShowModal(...args),
45+
}));
46+
4147
vi.mock('node:child_process', () => ({
4248
exec: vi.fn(),
4349
execFile: vi.fn(),
@@ -229,13 +235,13 @@ describe('logout command', () => {
229235
},
230236
};
231237

232-
(safePrompt as ReturnType<typeof vi.fn>).mockResolvedValue({ confirm: false });
238+
mockShowModal.mockResolvedValue({ value: 'no' });
233239

234240
const { logout } = await import('../../src/commands/logout.js');
235241
const result = await logout({ config: mockConfig });
236242

237243
expect(result).toBeNull();
238-
expect(safePrompt).toHaveBeenCalled();
244+
expect(mockShowModal).toHaveBeenCalled();
239245
expect(consoleOutput.some((line) => line.includes('cancelled'))).toBe(true);
240246
});
241247

@@ -252,7 +258,7 @@ describe('logout command', () => {
252258
logout: vi.fn().mockResolvedValue(undefined),
253259
};
254260

255-
(safePrompt as ReturnType<typeof vi.fn>).mockResolvedValue({ confirm: true });
261+
mockShowModal.mockResolvedValue({ value: 'yes' });
256262
(getAuthClient as ReturnType<typeof vi.fn>).mockReturnValue(mockAuthClient);
257263
(saveConfig as ReturnType<typeof vi.fn>).mockResolvedValue(undefined);
258264

@@ -281,7 +287,7 @@ describe('logout command', () => {
281287
logout: vi.fn().mockRejectedValue(new Error('Network error')),
282288
};
283289

284-
(safePrompt as ReturnType<typeof vi.fn>).mockResolvedValue({ confirm: true });
290+
mockShowModal.mockResolvedValue({ value: 'yes' });
285291
(getAuthClient as ReturnType<typeof vi.fn>).mockReturnValue(mockAuthClient);
286292
(saveConfig as ReturnType<typeof vi.fn>).mockResolvedValue(undefined);
287293

0 commit comments

Comments
 (0)