Wrap prompt

This commit is contained in:
Kilian Hofmann 2025-07-15 11:10:24 +02:00
parent 50077746f0
commit 13bea68195
4 changed files with 24 additions and 15 deletions

View File

@ -1,5 +1,5 @@
import readline from 'readline';
import Parser from './parser.ts'; import Parser from './parser.ts';
import { prompting } from './utils/prompting.ts';
// mutate fetch to be local // mutate fetch to be local
@ -14,11 +14,4 @@ fetch = async (path: string) => {
const parser = await Parser.instance(); const parser = await Parser.instance();
const rl = readline.createInterface({ console.log(JSON.stringify(await parser.parse(Number.parseInt((await prompting('Terminal ID')) ?? ''))));
input: process.stdin,
output: process.stdout,
});
rl.question(`Terminal ID? `, async (id) => {
console.log(JSON.stringify(await parser.parse(Number.parseInt(id))));
rl.close();
});

View File

@ -20,6 +20,7 @@ import { TerminatorsVI } from './terminators/VI.ts';
import { TerminatorsVM } from './terminators/VM.ts'; import { TerminatorsVM } from './terminators/VM.ts';
import { TerminatorsVR } from './terminators/VR.ts'; import { TerminatorsVR } from './terminators/VR.ts';
import './utils/extensions.ts'; import './utils/extensions.ts';
import { prompting } from './utils/prompting.ts';
/* /*
Runway IDs for LIED Runway IDs for LIED
@ -73,11 +74,7 @@ class Parser {
// Get runway this procedure is for // Get runway this procedure is for
let runway = this.runways.find(({ ID }) => ID === terminal.RwyID); let runway = this.runways.find(({ ID }) => ID === terminal.RwyID);
if (!runway) { if (!runway) {
let id = 26156; const id = Number.parseInt((await prompting('Runway ID')) ?? '');
if (typeof prompt !== 'undefined')
// throw new Error("Prompt not defined, cannot continue");
id = Number.parseInt(prompt('Runway ID') ?? '');
runway = this.runways.find(({ ID }) => ID === id); runway = this.runways.find(({ ID }) => ID === id);
if (!runway) throw new Error('Procedure links to non existent Runway'); if (!runway) throw new Error('Procedure links to non existent Runway');
} }

View File

@ -0,0 +1,19 @@
import readline from 'readline';
export const prompting = (message: string) => {
return new Promise<string | null>((resolve) => {
if (typeof prompt !== 'undefined') {
return resolve(prompt(message));
}
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
rl.question(`${message}: `, (id) => {
rl.close();
resolve(id);
});
});
};

View File

@ -72,7 +72,7 @@ export declare global {
ID: number; ID: number;
FullName: string; FullName: string;
ICAO: string; ICAO: string;
RwyID: number; RwyID?: number;
}; };
type NavFix = { type NavFix = {