Merge pull request #2891 from tigercat2000/autocomplete_documentation

Terminal: There is now an interface definition for the autocomplete() 'data' argument.
This commit is contained in:
hydroflame 2022-03-08 16:34:57 -05:00 committed by GitHub
commit 92909689b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 16 deletions

@ -6904,3 +6904,14 @@ interface GameInfo {
commit: string; commit: string;
platform: string; platform: string;
} }
/**
* Used for autocompletion
* @public
*/
interface AutocompleteData {
servers: string[];
scripts: string[];
txts: string[];
flags(schema: [string, string | number | boolean | string[]][]): any;
}

@ -10,6 +10,7 @@ import { HelpTexts } from "./HelpText";
import { isScriptFilename } from "../Script/isScriptFilename"; import { isScriptFilename } from "../Script/isScriptFilename";
import { compile } from "../NetscriptJSEvaluator"; import { compile } from "../NetscriptJSEvaluator";
import { Flags } from "../NetscriptFunctions/Flags"; import { Flags } from "../NetscriptFunctions/Flags";
import { AutocompleteData } from "../ScriptEditor/NetscriptDefinitions";
import * as libarg from "arg"; import * as libarg from "arg";
// An array of all Terminal commands // An array of all Terminal commands
@ -298,26 +299,27 @@ export async function determineAllPossibilitiesForTabCompletion(
argv: command.slice(2), argv: command.slice(2),
}); });
const flagFunc = Flags(flags._); 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 pos: string[] = [];
let pos2: string[] = []; let pos2: string[] = [];
pos = pos.concat( pos = pos.concat(
loadedModule.autocomplete( loadedModule.autocomplete(
{ 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;
}
},
},
flags._, flags._,
), ),
); );