mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-26 09:33:49 +01:00
Improved terminal parsing to account for quotation marks
This commit is contained in:
parent
0e8872fad1
commit
5ac10f17f8
@ -312,6 +312,9 @@ getStockForecast
|
|||||||
that the stock's price has a 30% chance of increasing and a 70% chance of
|
that the stock's price has a 30% chance of increasing and a 70% chance of
|
||||||
decreasing during the next tick.
|
decreasing during the next tick.
|
||||||
|
|
||||||
|
In order to use this function, you must first purchase access to the Four Sigma (4S)
|
||||||
|
Market Data TIX API.
|
||||||
|
|
||||||
purchase4SMarketData
|
purchase4SMarketData
|
||||||
--------------------
|
--------------------
|
||||||
|
|
||||||
|
@ -91,6 +91,9 @@ function removeAlias(name) {
|
|||||||
function substituteAliases(origCommand) {
|
function substituteAliases(origCommand) {
|
||||||
var commandArray = origCommand.split(" ");
|
var commandArray = origCommand.split(" ");
|
||||||
if (commandArray.length > 0){
|
if (commandArray.length > 0){
|
||||||
|
// For the unalias command, dont substite
|
||||||
|
if (commandArray[0] === "unalias") { return commandArray.join(" "); }
|
||||||
|
|
||||||
var alias = getAlias(commandArray[0]);
|
var alias = getAlias(commandArray[0]);
|
||||||
if (alias != null) {
|
if (alias != null) {
|
||||||
commandArray[0] = alias;
|
commandArray[0] = alias;
|
||||||
|
@ -156,7 +156,6 @@ $(document).keydown(function(event) {
|
|||||||
if (!(Player.bladeburner instanceof Bladeburner)) {return;}
|
if (!(Player.bladeburner instanceof Bladeburner)) {return;}
|
||||||
let consoleHistory = Player.bladeburner.consoleHistory;
|
let consoleHistory = Player.bladeburner.consoleHistory;
|
||||||
|
|
||||||
//NOTE: Keycodes imported from Terminal.js
|
|
||||||
if (event.keyCode === KEY.ENTER) {
|
if (event.keyCode === KEY.ENTER) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
var command = DomElems.consoleInput.value;
|
var command = DomElems.consoleInput.value;
|
||||||
@ -2869,12 +2868,23 @@ Bladeburner.prototype.parseCommandArguments = function(command) {
|
|||||||
//Returns an array with command and its arguments in each index.
|
//Returns an array with command and its arguments in each index.
|
||||||
//e.g. skill "blade's intuition" foo returns [skill, blade's intuition, foo]
|
//e.g. skill "blade's intuition" foo returns [skill, blade's intuition, foo]
|
||||||
//The input to this fn will be trimmed and will have all whitespace replaced w/ a single space
|
//The input to this fn will be trimmed and will have all whitespace replaced w/ a single space
|
||||||
var args = [];
|
const args = [];
|
||||||
var start = 0, i = 0;
|
let start = 0, i = 0;
|
||||||
while (i < command.length) {
|
while (i < command.length) {
|
||||||
var c = command.charAt(i);
|
const c = command.charAt(i);
|
||||||
if (c === '"') {
|
if (c === '"') { // Double quotes
|
||||||
var endQuote = command.indexOf('"', i+1);
|
const endQuote = command.indexOf('"', i+1);
|
||||||
|
if (endQuote !== -1 && (endQuote === command.length-1 || command.charAt(endQuote+1) === " ")) {
|
||||||
|
args.push(command.substr(i+1, (endQuote - i - 1)));
|
||||||
|
if (endQuote === command.length-1) {
|
||||||
|
start = i = endQuote+1;
|
||||||
|
} else {
|
||||||
|
start = i = endQuote+2; //Skip the space
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else if (c === "'") { // Single quotes, same thing as above
|
||||||
|
const endQuote = command.indexOf("'", i+1);
|
||||||
if (endQuote !== -1 && (endQuote === command.length-1 || command.charAt(endQuote+1) === " ")) {
|
if (endQuote !== -1 && (endQuote === command.length-1 || command.charAt(endQuote+1) === " ")) {
|
||||||
args.push(command.substr(i+1, (endQuote - i - 1)));
|
args.push(command.substr(i+1, (endQuote - i - 1)));
|
||||||
if (endQuote === command.length-1) {
|
if (endQuote === command.length-1) {
|
||||||
@ -2891,7 +2901,7 @@ Bladeburner.prototype.parseCommandArguments = function(command) {
|
|||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
if (start !== i) {args.push(command.substr(start, i-start));}
|
if (start !== i) {args.push(command.substr(start, i-start));}
|
||||||
console.log("Bladeburner.parseCommandArguments returned: " + args);
|
console.log("Bladeburner console command parsing returned: " + args);
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ export const TerminalHelpText: string =
|
|||||||
"tail [script] [args...] Displays dynamic logs for the specified script<br>" +
|
"tail [script] [args...] Displays dynamic logs for the specified script<br>" +
|
||||||
"theme [preset] | bg txt hlgt Change the color scheme of the UI<br>" +
|
"theme [preset] | bg txt hlgt Change the color scheme of the UI<br>" +
|
||||||
"top Displays all running scripts and their RAM usage<br>" +
|
"top Displays all running scripts and their RAM usage<br>" +
|
||||||
'unalias "[alias name]" Deletes the specified alias<br>' +
|
'unalias [alias name] Deletes the specified alias<br>' +
|
||||||
"wget [url] [target file] Retrieves code/text from a web server<br>";
|
"wget [url] [target file] Retrieves code/text from a web server<br>";
|
||||||
|
|
||||||
interface IMap<T> {
|
interface IMap<T> {
|
||||||
@ -215,12 +215,12 @@ export const HelpTexts: IMap<string> = {
|
|||||||
top: "top<br>" +
|
top: "top<br>" +
|
||||||
"Prints a list of all scripts running on the current server as well as their thread count and how much " +
|
"Prints a list of all scripts running on the current server as well as their thread count and how much " +
|
||||||
"RAM they are using in total.",
|
"RAM they are using in total.",
|
||||||
unalias: 'unalias "[alias name]"<br>' +
|
unalias: 'unalias [alias name]<br>' +
|
||||||
"Deletes the specified alias. Note that the double quotation marks are required. <br><br>" +
|
"Deletes the specified alias. Note that the double quotation marks are required. <br><br>" +
|
||||||
"As an example, if an alias was declared using:<br><br>" +
|
"As an example, if an alias was declared using:<br><br>" +
|
||||||
'alias r="run"<br><br>' +
|
'alias r="run"<br><br>' +
|
||||||
"Then it could be removed using:<br><br>" +
|
"Then it could be removed using:<br><br>" +
|
||||||
'unalias "r"<br><br>' +
|
'unalias r<br><br>' +
|
||||||
"It is not necessary to differentiate between global and non-global aliases when using 'unalias'",
|
"It is not necessary to differentiate between global and non-global aliases when using 'unalias'",
|
||||||
wget: "wget [url] [target file]<br>" +
|
wget: "wget [url] [target file]<br>" +
|
||||||
"Retrieves data from a URL and downloads it to a file on the current server. The data can only " +
|
"Retrieves data from a URL and downloads it to a file on the current server. The data can only " +
|
||||||
|
@ -24,8 +24,8 @@ function initLiterature() {
|
|||||||
title = "The Beginner's Guide to Hacking";
|
title = "The Beginner's Guide to Hacking";
|
||||||
fn = "hackers-starting-handbook.lit";
|
fn = "hackers-starting-handbook.lit";
|
||||||
txt = "Some resources:<br><br>" +
|
txt = "Some resources:<br><br>" +
|
||||||
"<a class='a-link-button' href='https://bitburner.readthedocs.io/en/latest/netscriptlearntoprogram.html' target='_blank' style='margin:4px'>Learn to Program</a><br><br>" +
|
"<a class='a-link-button' href='https://bitburner.readthedocs.io/en/latest/netscript/netscriptlearntoprogram.html' target='_blank' style='margin:4px'>Learn to Program</a><br><br>" +
|
||||||
"<a class='a-link-button' href='https://bitburner.readthedocs.io/en/latest/netscriptjs.html' target='_blank' style='margin:4px'>For Experienced JavaScript Developers: NetscriptJS</a><br><br>" +
|
"<a class='a-link-button' href='https://bitburner.readthedocs.io/en/latest/netscript/netscriptjs.html' target='_blank' style='margin:4px'>For Experienced JavaScript Developers: NetscriptJS</a><br><br>" +
|
||||||
"<a class='a-link-button' href='https://bitburner.readthedocs.io/en/latest/netscript.html' target='_blank' style='margin:4px'>Netscript Documentation</a><br><br>" +
|
"<a class='a-link-button' href='https://bitburner.readthedocs.io/en/latest/netscript.html' target='_blank' style='margin:4px'>Netscript Documentation</a><br><br>" +
|
||||||
"When starting out, hacking is the most profitable way to earn money and progress. This " +
|
"When starting out, hacking is the most profitable way to earn money and progress. This " +
|
||||||
"is a brief collection of tips/pointers on how to make the most out of your hacking scripts.<br><br>" +
|
"is a brief collection of tips/pointers on how to make the most out of your hacking scripts.<br><br>" +
|
||||||
|
909
src/Terminal.js
909
src/Terminal.js
File diff suppressed because it is too large
Load Diff
@ -8,12 +8,16 @@ export function post(input: string) {
|
|||||||
postContent(input);
|
postContent(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function postError(input: string) {
|
||||||
|
postContent(`ERROR: ${input}`, { color: "#ff2929" });
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds some output to the terminal with an identifier of "hack-progress-bar"
|
* Adds some output to the terminal with an identifier of "hack-progress-bar"
|
||||||
* @param input Text or HTML to output to the terminal
|
* @param input Text or HTML to output to the terminal
|
||||||
*/
|
*/
|
||||||
export function hackProgressBarPost(input: string) {
|
export function hackProgressBarPost(input: string) {
|
||||||
postContent(input, "hack-progress-bar");
|
postContent(input, { id: "hack-progress-bar" });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -21,14 +25,19 @@ export function hackProgressBarPost(input: string) {
|
|||||||
* @param input Text or HTML to output to the terminal
|
* @param input Text or HTML to output to the terminal
|
||||||
*/
|
*/
|
||||||
export function hackProgressPost(input: string) {
|
export function hackProgressPost(input: string) {
|
||||||
postContent(input, "hack-progress");
|
postContent(input, { id: "hack-progress" });
|
||||||
}
|
}
|
||||||
|
|
||||||
function postContent(input: string, id?: string) {
|
interface IPostContentConfig {
|
||||||
|
id?: string; // Replaces class, if specified
|
||||||
|
color?: string; // Additional class for terminal-line. Does NOT replace
|
||||||
|
}
|
||||||
|
|
||||||
|
function postContent(input: string, config: IPostContentConfig = {}) {
|
||||||
// tslint:disable-next-line:max-line-length
|
// tslint:disable-next-line:max-line-length
|
||||||
const style: string = `color: var(--my-font-color); background-color:var(--my-background-color);${id === undefined ? " white-space:pre-wrap;" : ""}`;
|
const style: string = `color: ${config.color != null ? config.color : "var(--my-font-color)"}; background-color:var(--my-background-color);${config.id === undefined ? " white-space:pre-wrap;" : ""}`;
|
||||||
// tslint:disable-next-line:max-line-length
|
// tslint:disable-next-line:max-line-length
|
||||||
const content: string = `<tr class="posted"><td ${id === undefined ? 'class="terminal-line"' : `id="${id}"`} style="${style}">${input}</td></tr>`;
|
const content: string = `<tr class="posted"><td ${config.id === undefined ? `class="terminal-line"` : `id="${config.id}"`} style="${style}">${input}</td></tr>`;
|
||||||
const inputElement: HTMLElement = getElementById("terminal-input");
|
const inputElement: HTMLElement = getElementById("terminal-input");
|
||||||
inputElement.insertAdjacentHTML("beforebegin", content);
|
inputElement.insertAdjacentHTML("beforebegin", content);
|
||||||
scrollTerminalToBottom();
|
scrollTerminalToBottom();
|
||||||
|
Loading…
Reference in New Issue
Block a user