Fixed terminal utility after 1.6.0 update
This commit is contained in:
parent
aa26f3db93
commit
886900de5d
@ -14,7 +14,7 @@ export function autocomplete(data) {
|
|||||||
* Search the network for a device and connect to it.
|
* Search the network for a device and connect to it.
|
||||||
* @param ns {NS} - BitBurner API
|
* @param ns {NS} - BitBurner API
|
||||||
*/
|
*/
|
||||||
export function main(ns) {
|
export async function main(ns) {
|
||||||
// Setup
|
// Setup
|
||||||
ns.disableLog('ALL');
|
ns.disableLog('ALL');
|
||||||
const argParser = new ArgParser('connect.js', 'Search the network for a device and connect to it.', null, [
|
const argParser = new ArgParser('connect.js', 'Search the network for a device and connect to it.', null, [
|
||||||
@ -26,11 +26,12 @@ export function main(ns) {
|
|||||||
const args = argParser.parse(ns.args);
|
const args = argParser.parse(ns.args);
|
||||||
const [devices, network] = scanNetwork(ns);
|
const [devices, network] = scanNetwork(ns);
|
||||||
pruneTree(network, d => d == args['device']);
|
pruneTree(network, d => d == args['device']);
|
||||||
let current = network, name;
|
let current = network, name, path = [];
|
||||||
while(name = Object.keys(current)[0]) {
|
while(name = Object.keys(current)[0]) {
|
||||||
terminal(`connect ${name}`);
|
|
||||||
current = current[name];
|
current = current[name];
|
||||||
|
path.push(name);
|
||||||
}
|
}
|
||||||
|
await terminal('home; ' + path.map(p => `connect ${p}`).join('; '));
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
if(err instanceof ArgError) return ns.tprint(argParser.help(err.message));
|
if(err instanceof ArgError) return ns.tprint(argParser.help(err.message));
|
||||||
throw err;
|
throw err;
|
||||||
|
@ -125,14 +125,23 @@ export async function slowPrint(ns, message, min = 0.5, max = 1.5) {
|
|||||||
/**
|
/**
|
||||||
* Write a command to the terminal.
|
* Write a command to the terminal.
|
||||||
* @param command {string} - Command that will be run
|
* @param command {string} - Command that will be run
|
||||||
* @returns {string} - Response
|
* @returns {Promise<string>} - Command line response
|
||||||
*/
|
*/
|
||||||
export async function terminal(command) {
|
export function terminal(command) {
|
||||||
// Get Terminal
|
// Get the terminal
|
||||||
const cli = eval('document').querySelector("#terminal-input"); // Terminal
|
const terminalInput = document.getElementById("terminal-input");
|
||||||
const key = Object.keys(cli)[1];
|
const handler = Object.keys(terminalInput)[1];
|
||||||
|
|
||||||
// Send command
|
// Send command
|
||||||
cli[key].onChange({ target: {value: command} });
|
terminalInput.value = command; // Enter the command
|
||||||
cli[key].onKeyDown({ keyCode: 13, preventDefault: () => {} });
|
terminalInput[handler].onChange({target:terminalInput}); // React on change
|
||||||
|
terminalInput[handler].onKeyDown({key: 'Enter', preventDefault: () => null}); // Enter 'keystroke'
|
||||||
|
|
||||||
|
// Return any new terminal output
|
||||||
|
return new Promise(res => setTimeout(() => {
|
||||||
|
const terminalOutput = Array.from(eval('document')
|
||||||
|
.querySelectorAll('#terminal li p')).map(out => out.innerText);
|
||||||
|
const i = terminalOutput.length - terminalOutput.reverse().findIndex(o => o.indexOf(command) != -1);
|
||||||
|
res(terminalOutput.reverse().slice(i));
|
||||||
|
}, 25));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user