文件
mynode/packages/tools/fuzzer/utils/openDebugSession.ts
chen 301194963b
一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
feat: Initial clean release of CHM
2026-11-04 11:29:39 +08:00

51 行
1.5 KiB
TypeScript

import Logger from '@joplin/utils/Logger';
import ClientPool from '../ipc/ClientPool';
import { createInterface } from 'readline/promises';
const logger = Logger.create('openDebugSession');
const openDebugSession = async (clients: ClientPool) => {
const allClients = clients.clients;
const clientChoices = allClients.map((client, index) => {
return `${index}: ${client.label}`;
}).join('\n');
const askForClient = async (questionPrefix = '') => {
// Recreate the readline interface each time to avoid conflicting
// with the debug sessions for the individual clients.
const readlineInterface = createInterface({
input: process.stdin,
output: process.stdout,
});
try {
const clientChoice = await readlineInterface.question(
`${questionPrefix}Select a client from:\n${clientChoices}\nclient: `,
);
if (clientChoice.trim() === '' || clientChoice === 'exit') {
return null;
}
const asNumber = Number(clientChoice);
if (!isFinite(asNumber) || Math.floor(asNumber) !== asNumber) {
return askForClient('Please input an integer. ');
}
if (asNumber < 0 || asNumber >= allClients.length) {
return askForClient('Choice out of range. ');
}
return allClients[asNumber];
} finally {
readlineInterface.close();
}
};
for (let client = await askForClient(); client; client = await askForClient()) {
logger.info('Switching to client', client.getHelpText());
await client.startCliDebugSession();
}
};
export default openDebugSession;