Wrap prompt
This commit is contained in:
parent
50077746f0
commit
13bea68195
@ -1,5 +1,5 @@
|
||||
import readline from 'readline';
|
||||
import Parser from './parser.ts';
|
||||
import { prompting } from './utils/prompting.ts';
|
||||
|
||||
// mutate fetch to be local
|
||||
|
||||
@ -14,11 +14,4 @@ fetch = async (path: string) => {
|
||||
|
||||
const parser = await Parser.instance();
|
||||
|
||||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout,
|
||||
});
|
||||
rl.question(`Terminal ID? `, async (id) => {
|
||||
console.log(JSON.stringify(await parser.parse(Number.parseInt(id))));
|
||||
rl.close();
|
||||
});
|
||||
console.log(JSON.stringify(await parser.parse(Number.parseInt((await prompting('Terminal ID')) ?? ''))));
|
||||
|
||||
@ -20,6 +20,7 @@ import { TerminatorsVI } from './terminators/VI.ts';
|
||||
import { TerminatorsVM } from './terminators/VM.ts';
|
||||
import { TerminatorsVR } from './terminators/VR.ts';
|
||||
import './utils/extensions.ts';
|
||||
import { prompting } from './utils/prompting.ts';
|
||||
|
||||
/*
|
||||
Runway IDs for LIED
|
||||
@ -73,11 +74,7 @@ class Parser {
|
||||
// Get runway this procedure is for
|
||||
let runway = this.runways.find(({ ID }) => ID === terminal.RwyID);
|
||||
if (!runway) {
|
||||
let id = 26156;
|
||||
if (typeof prompt !== 'undefined')
|
||||
// throw new Error("Prompt not defined, cannot continue");
|
||||
|
||||
id = Number.parseInt(prompt('Runway ID') ?? '');
|
||||
const id = Number.parseInt((await prompting('Runway ID')) ?? '');
|
||||
runway = this.runways.find(({ ID }) => ID === id);
|
||||
if (!runway) throw new Error('Procedure links to non existent Runway');
|
||||
}
|
||||
|
||||
19
browser/src/parser/utils/prompting.ts
Normal file
19
browser/src/parser/utils/prompting.ts
Normal 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);
|
||||
});
|
||||
});
|
||||
};
|
||||
2
browser/src/types/types.d.ts
vendored
2
browser/src/types/types.d.ts
vendored
@ -72,7 +72,7 @@ export declare global {
|
||||
ID: number;
|
||||
FullName: string;
|
||||
ICAO: string;
|
||||
RwyID: number;
|
||||
RwyID?: number;
|
||||
};
|
||||
|
||||
type NavFix = {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user