From f0557eadf710337507c4cddd7e8a3189d8d78c9e Mon Sep 17 00:00:00 2001 From: tigercat2000 Date: Mon, 31 Jan 2022 20:43:49 -0800 Subject: [PATCH] Terminal: There is now an interface definition for the autocomplete() 'data' argument. --- src/ScriptEditor/NetscriptDefinitions.d.ts | 11 ++++++ ...termineAllPossibilitiesForTabCompletion.ts | 34 ++++++++++--------- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index 6e613ba80..75c2c2893 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -6779,3 +6779,14 @@ interface GameInfo { commit: string; platform: string; } + +/** + * Used for autocompletion + * @public + */ +interface AutocompleteData { + servers: string[]; + scripts: string[]; + txts: string[]; + flags(schema: [string, string | number | boolean | string[]][]): any; +} diff --git a/src/Terminal/determineAllPossibilitiesForTabCompletion.ts b/src/Terminal/determineAllPossibilitiesForTabCompletion.ts index 7a7317d26..d69174911 100644 --- a/src/Terminal/determineAllPossibilitiesForTabCompletion.ts +++ b/src/Terminal/determineAllPossibilitiesForTabCompletion.ts @@ -10,6 +10,7 @@ import { HelpTexts } from "./HelpText"; import { isScriptFilename } from "../Script/isScriptFilename"; import { compile } from "../NetscriptJSEvaluator"; import { Flags } from "../NetscriptFunctions/Flags"; +import { AutocompleteData } from "../ScriptEditor/NetscriptDefinitions"; import * as libarg from "arg"; // An array of all Terminal commands @@ -298,26 +299,27 @@ export async function determineAllPossibilitiesForTabCompletion( argv: command.slice(2), }); const flagFunc = Flags(flags._); + const autocompleteData: AutocompleteData = { + servers: GetAllServers().map((server) => server.hostname), + scripts: currServ.scripts.map((script) => script.filename), + txts: currServ.textFiles.map((txt) => txt.fn), + flags: (schema: any) => { + pos2 = schema.map((f: any) => { + if (f[0].length === 1) return "-" + f[0]; + return "--" + f[0]; + }); + try { + return flagFunc(schema); + } catch (err) { + return undefined; + } + }, + } let pos: string[] = []; let pos2: string[] = []; pos = pos.concat( loadedModule.autocomplete( - { - servers: GetAllServers().map((server) => server.hostname), - scripts: currServ.scripts.map((script) => script.filename), - txts: currServ.textFiles.map((txt) => txt.fn), - flags: (schema: any) => { - pos2 = schema.map((f: any) => { - if (f[0].length === 1) return "-" + f[0]; - return "--" + f[0]; - }); - try { - return flagFunc(schema); - } catch (err) { - return undefined; - } - }, - }, + autocompleteData, flags._, ), );