mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-22 07:33:48 +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
|
||||
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
|
||||
--------------------
|
||||
|
||||
|
@ -90,7 +90,10 @@ function removeAlias(name) {
|
||||
//Aliases only applied to "whole words", one level deep
|
||||
function substituteAliases(origCommand) {
|
||||
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]);
|
||||
if (alias != null) {
|
||||
commandArray[0] = alias;
|
||||
|
@ -156,7 +156,6 @@ $(document).keydown(function(event) {
|
||||
if (!(Player.bladeburner instanceof Bladeburner)) {return;}
|
||||
let consoleHistory = Player.bladeburner.consoleHistory;
|
||||
|
||||
//NOTE: Keycodes imported from Terminal.js
|
||||
if (event.keyCode === KEY.ENTER) {
|
||||
event.preventDefault();
|
||||
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.
|
||||
//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
|
||||
var args = [];
|
||||
var start = 0, i = 0;
|
||||
const args = [];
|
||||
let start = 0, i = 0;
|
||||
while (i < command.length) {
|
||||
var c = command.charAt(i);
|
||||
if (c === '"') {
|
||||
var endQuote = command.indexOf('"', i+1);
|
||||
const c = command.charAt(i);
|
||||
if (c === '"') { // Double quotes
|
||||
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) === " ")) {
|
||||
args.push(command.substr(i+1, (endQuote - i - 1)));
|
||||
if (endQuote === command.length-1) {
|
||||
@ -2891,7 +2901,7 @@ Bladeburner.prototype.parseCommandArguments = function(command) {
|
||||
++i;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ export const TerminalHelpText: string =
|
||||
"tail [script] [args...] Displays dynamic logs for the specified script<br>" +
|
||||
"theme [preset] | bg txt hlgt Change the color scheme of the UI<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>";
|
||||
|
||||
interface IMap<T> {
|
||||
@ -215,12 +215,12 @@ export const HelpTexts: IMap<string> = {
|
||||
top: "top<br>" +
|
||||
"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.",
|
||||
unalias: 'unalias "[alias name]"<br>' +
|
||||
unalias: 'unalias [alias name]<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>" +
|
||||
'alias r="run"<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'",
|
||||
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 " +
|
||||
|
@ -24,8 +24,8 @@ function initLiterature() {
|
||||
title = "The Beginner's Guide to Hacking";
|
||||
fn = "hackers-starting-handbook.lit";
|
||||
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/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/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/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>" +
|
||||
"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>" +
|
||||
@ -78,7 +78,7 @@ function initLiterature() {
|
||||
"find investors. Instead, your Corporation will be publicly traded and its stock price will change based on how well " +
|
||||
"it's performing financially. You can then sell your stock shares in order to make money.<br><br>" +
|
||||
"<u>Tips/Pointers</u><br>" +
|
||||
"-The 'Smart Supply' upgrade is extremely useful. Consider purchasing it as soon as possible.<br><br>" +
|
||||
"-The 'Smart Supply' upgrade is extremely useful. Consider purchasing it as soon as possible.<br><br>" +
|
||||
"-Purchasing Hardware, Robots, AI Cores, and Real Estate can potentially increase your production. " +
|
||||
"The effects of these depend on what industry you are in.<br><br>" +
|
||||
"-In order to optimize your production, you will need a good balance of Operators, Managers, and Engineers<br><br>" +
|
||||
|
925
src/Terminal.js
925
src/Terminal.js
File diff suppressed because it is too large
Load Diff
@ -8,12 +8,16 @@ export function post(input: string) {
|
||||
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"
|
||||
* @param input Text or HTML to output to the terminal
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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
|
||||
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
|
||||
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");
|
||||
inputElement.insertAdjacentHTML("beforebegin", content);
|
||||
scrollTerminalToBottom();
|
||||
|
Loading…
Reference in New Issue
Block a user