mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-05-03 06:17:04 +02:00
[refactor] Pulling out post to terminal to its own file.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user