[refactor] Pulling out post to terminal to its own file.

This commit is contained in:
Steven Evans 2018-07-18 14:34:18 -04:00
parent 0bea4e0430
commit 7313d551f1
6 changed files with 47 additions and 29 deletions

@ -1,4 +1,4 @@
import {post} from "./Terminal"; import {post} from "./ui/postToTerminal";
let Aliases = {}; let Aliases = {};
let GlobalAliases = {}; let GlobalAliases = {};

@ -1,7 +1,7 @@
import {Programs} from "./CreateProgram"; import {Programs} from "./CreateProgram";
import {Player} from "./Player"; import {Player} from "./Player";
import {SpecialServerIps} from "./SpecialServerIps"; import {SpecialServerIps} from "./SpecialServerIps";
import {post} from "./Terminal"; import {post} from "./ui/postToTerminal";
import {isValidIPAddress} from "../utils/helpers/isValidIPAddress"; import {isValidIPAddress} from "../utils/helpers/isValidIPAddress";
import {formatNumber} from "../utils/StringHelperFunctions"; import {formatNumber} from "../utils/StringHelperFunctions";

@ -35,7 +35,7 @@ import {StockMarket, StockSymbols, SymbolToStockMap, initStockSymbols,
updateStockTicker, updateStockPlayerPosition, updateStockTicker, updateStockPlayerPosition,
Stock, shortStock, sellShort, OrderTypes, Stock, shortStock, sellShort, OrderTypes,
PositionTypes, placeOrder, cancelOrder} from "./StockMarket"; PositionTypes, placeOrder, cancelOrder} from "./StockMarket";
import {post} from "./Terminal"; import {post} from "./ui/postToTerminal";
import {TextFile, getTextFile, createTextFile} from "./TextFile"; import {TextFile, getTextFile, createTextFile} from "./TextFile";
import {unknownBladeburnerActionErrorMessage, import {unknownBladeburnerActionErrorMessage,

@ -29,7 +29,7 @@ import {addWorkerScript,
import {Player} from "./Player"; import {Player} from "./Player";
import {AllServers, processSingleServerGrowth} from "./Server"; import {AllServers, processSingleServerGrowth} from "./Server";
import {Settings} from "./Settings"; import {Settings} from "./Settings";
import {post} from "./Terminal"; import {post} from "./ui/postToTerminal";
import {TextFile} from "./TextFile"; import {TextFile} from "./TextFile";
import {parse, Node} from "../utils/acorn"; import {parse, Node} from "../utils/acorn";

@ -44,34 +44,12 @@ import {logBoxCreate} from "../utils/LogBox";
import {yesNoBoxCreate, import {yesNoBoxCreate,
yesNoBoxGetYesButton, yesNoBoxGetYesButton,
yesNoBoxGetNoButton, yesNoBoxClose} from "../utils/YesNoBox"; yesNoBoxGetNoButton, yesNoBoxClose} from "../utils/YesNoBox";
import {post, hackProgressBarPost,
hackProgressPost} from "./ui/postToTerminal";
import * as JSZip from 'jszip'; import * as JSZip from 'jszip';
import * as FileSaver from 'file-saver'; import * as FileSaver from 'file-saver';
/* Write text to terminal */
//If replace is true then spaces are replaced with " "
function post(input) {
$("#terminal-input").before('<tr class="posted"><td class="terminal-line" style="color: var(--my-font-color); background-color: var(--my-background-color); white-space:pre-wrap;">' + input + '</td></tr>');
updateTerminalScroll();
}
//Same thing as post but the td cells have ids so they can be animated for the hack progress bar
function hackProgressBarPost(input) {
$("#terminal-input").before('<tr class="posted"><td id="hack-progress-bar" style="color: var(--my-font-color); background-color: var(--my-background-color);">' + input + '</td></tr>');
updateTerminalScroll();
}
function hackProgressPost(input) {
$("#terminal-input").before('<tr class="posted"><td id="hack-progress" style="color: var(--my-font-color); background-color: var(--my-background-color);">' + input + '</td></tr>');
updateTerminalScroll();
}
//Scroll to the bottom of the terminal's 'text area'
function updateTerminalScroll() {
var element = document.getElementById("terminal-container");
element.scrollTop = element.scrollHeight;
}
function postNetburnerText() { function postNetburnerText() {
post("Bitburner v" + CONSTANTS.Version); post("Bitburner v" + CONSTANTS.Version);
} }
@ -2057,4 +2035,4 @@ let Terminal = {
} }
}; };
export {postNetburnerText, post, Terminal}; export {postNetburnerText, Terminal};

40
src/ui/postToTerminal.ts Normal file

@ -0,0 +1,40 @@
import { getElementById } from "../../utils/uiHelpers/getElementById";
/**
* Adds some output to the terminal.
* @param input Text or HTML to output to the terminal
*/
export function post(input: string) {
postContent(input);
}
/**
* 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");
}
/**
* Adds some output to the terminal with an identifier of "hack-progress"
* @param input Text or HTML to output to the terminal
*/
export function hackProgressPost(input: string) {
postContent(input, "hack-progress");
}
function postContent(input: string, id?: string) {
// 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;" : ""}`;
// 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 inputElement: HTMLElement = getElementById("terminal-input");
inputElement.insertAdjacentHTML("beforebegin", content);
scrollTerminalToBottom();
}
function scrollTerminalToBottom() {
const container: HTMLElement = getElementById("terminal-container");
container.scrollTop = container.scrollHeight;
}