diff --git a/css/menupages.scss b/css/menupages.scss index fd4bfc0ab..7eadef042 100644 --- a/css/menupages.scss +++ b/css/menupages.scss @@ -5,15 +5,17 @@ terminal which has its own page) */ .generic-menupage-container { - padding-left: 2px; -ms-overflow-style: none; /* for Internet Explorer, Edge */ scrollbar-width: none; /* for Firefox */ flex-grow: 1; + height: 100vh; + bottom: 0px; } #generic-react-container { - padding: 10px; overflow-y: scroll; + height: 100vh; + bottom: 0px; } #generic-react-container::-webkit-scrollbar { diff --git a/src/Alias.ts b/src/Alias.ts index ed23d6492..73029f69b 100644 --- a/src/Alias.ts +++ b/src/Alias.ts @@ -1,5 +1,5 @@ import { IMap } from "./types"; -import { post } from "./ui/postToTerminal"; +import { Terminal } from "./Terminal"; export let Aliases: IMap = {}; export let GlobalAliases: IMap = {}; @@ -24,12 +24,12 @@ export function loadGlobalAliases(saveString: string): void { export function printAliases(): void { for (const name in Aliases) { if (Aliases.hasOwnProperty(name)) { - post("alias " + name + "=" + Aliases[name]); + Terminal.print("alias " + name + "=" + Aliases[name]); } } for (const name in GlobalAliases) { if (GlobalAliases.hasOwnProperty(name)) { - post("global alias " + name + "=" + GlobalAliases[name]); + Terminal.print("global alias " + name + "=" + GlobalAliases[name]); } } } diff --git a/src/DarkWeb/DarkWeb.tsx b/src/DarkWeb/DarkWeb.tsx index f41aac65a..d18f2a2e0 100644 --- a/src/DarkWeb/DarkWeb.tsx +++ b/src/DarkWeb/DarkWeb.tsx @@ -2,8 +2,9 @@ import * as React from "react"; import { DarkWebItems } from "./DarkWebItems"; import { Player } from "../Player"; +import { Terminal } from "../Terminal"; import { SpecialServerIps } from "../Server/SpecialServerIps"; -import { post, postElement } from "../ui/postToTerminal"; +import { numeralWrapper } from "../ui/numeralFormat"; import { Money } from "../ui/React/Money"; import { isValidIPAddress } from "../../utils/helpers/isValidIPAddress"; @@ -16,7 +17,7 @@ export function checkIfConnectedToDarkweb(): void { return; } if (darkwebIp == Player.getCurrentServer().ip) { - post( + Terminal.print( "You are now connected to the dark web. From the dark web you can purchase illegal items. " + "Use the 'buy -l' command to display a list of all the items you can buy. Use 'buy [item-name] " + "to purchase an item.", @@ -35,9 +36,9 @@ export function executeDarkwebTerminalCommand(commandArray: string[]): void { switch (commandArray[0]) { case "buy": { if (commandArray.length != 2) { - post("Incorrect number of arguments. Usage: "); - post("buy -l"); - post("buy [item name]"); + Terminal.error("Incorrect number of arguments. Usage: "); + Terminal.print("buy -l"); + Terminal.print("buy [item name]"); return; } const arg = commandArray[1]; @@ -49,7 +50,7 @@ export function executeDarkwebTerminalCommand(commandArray: string[]): void { break; } default: - post("Command not found"); + Terminal.error("Command not found"); break; } } @@ -57,11 +58,7 @@ export function executeDarkwebTerminalCommand(commandArray: string[]): void { export function listAllDarkwebItems(): void { for (const key in DarkWebItems) { const item = DarkWebItems[key]; - postElement( - <> - {item.program} - - {item.description} - , - ); + Terminal.print(`${item.program} - ${numeralWrapper.formatMoney(item.price)} - ${item.description}`); } } @@ -79,24 +76,26 @@ export function buyDarkwebItem(itemName: string): void { // return if invalid if (item === null) { - post("Unrecognized item: " + itemName); + Terminal.print("Unrecognized item: " + itemName); return; } // return if the player already has it. if (Player.hasProgram(item.program)) { - post("You already have the " + item.program + " program"); + Terminal.print("You already have the " + item.program + " program"); return; } // return if the player doesn't have enough money if (Player.money.lt(item.price)) { - post("Not enough money to purchase " + item.program); + Terminal.print("Not enough money to purchase " + item.program); return; } // buy and push Player.loseMoney(item.price); Player.getHomeComputer().programs.push(item.program); - post("You have purchased the " + item.program + " program. The new program can be found on your home computer."); + Terminal.print( + "You have purchased the " + item.program + " program. The new program can be found on your home computer.", + ); } diff --git a/src/Missions.jsx b/src/Missions.jsx index 7e5a0edcf..d5dd7dfa9 100644 --- a/src/Missions.jsx +++ b/src/Missions.jsx @@ -1590,7 +1590,7 @@ HackingMission.prototype.finishMission = function (win) { Mission won! You earned {Reputation(gain)} reputation with {this.faction.name} , ); - Player.gainIntelligenceExp(this.difficulty * CONSTANTS.IntelligenceHackingMissionBaseExpGain); + Player.gainIntelligenceExp(Math.pow(this.difficulty * CONSTANTS.IntelligenceHackingMissionBaseExpGain, 0.5)); this.faction.playerReputation += gain; } else { dialogBoxCreate("Mission lost/forfeited! You did not gain any faction reputation."); diff --git a/src/NetscriptFunctions.js b/src/NetscriptFunctions.js index c34dc1566..add4e2693 100644 --- a/src/NetscriptFunctions.js +++ b/src/NetscriptFunctions.js @@ -145,7 +145,6 @@ import { findSleevePurchasableAugs } from "./PersonObjects/Sleeve/SleeveHelpers" import { Exploit } from "./Exploits/Exploit.ts"; import { numeralWrapper } from "./ui/numeralFormat"; -import { post } from "./ui/postToTerminal"; import { setTimeoutRef } from "./utils/SetTimeoutRef"; import { is2DArray } from "./utils/helpers/is2DArray"; import { convertTimeMsToTimeElapsedString } from "../utils/StringHelperFunctions"; @@ -1059,10 +1058,10 @@ function NetscriptFunctions(workerScript) { if (arguments.length === 0) { throw makeRuntimeErrorMsg("tprint", "Takes at least 1 argument."); } - post(`${workerScript.scriptRef.filename}: ${argsToString(arguments)}`); + Terminal.print(`${workerScript.scriptRef.filename}: ${argsToString(arguments)}`); }, tprintf: function (format, ...args) { - post(vsprintf(format, args)); + Terminal.print(vsprintf(format, args)); }, clearLog: function () { workerScript.scriptRef.clearLog(); @@ -3134,8 +3133,7 @@ function NetscriptFunctions(workerScript) { Player.getCurrentServer().isConnectedTo = false; Player.currentServer = Player.getHomeComputer().ip; Player.getCurrentServer().isConnectedTo = true; - Terminal.currDir = "/"; - Terminal.resetTerminalInput(true); + Terminal.setcwd("/"); return true; } @@ -3146,8 +3144,7 @@ function NetscriptFunctions(workerScript) { Player.getCurrentServer().isConnectedTo = false; Player.currentServer = target.ip; Player.getCurrentServer().isConnectedTo = true; - Terminal.currDir = "/"; - Terminal.resetTerminalInput(true); + Terminal.setcwd("/"); return true; } } diff --git a/src/Prestige.js b/src/Prestige.js index a9e8dac97..eb8eec4f2 100755 --- a/src/Prestige.js +++ b/src/Prestige.js @@ -23,7 +23,7 @@ import { prestigeHomeComputer } from "./Server/ServerHelpers"; import { SourceFileFlags, updateSourceFileFlags } from "./SourceFile/SourceFileFlags"; import { SpecialServerIps, prestigeSpecialServerIps, SpecialServerNames } from "./Server/SpecialServerIps"; import { deleteStockMarket, initStockMarket, initSymbolToStockMap } from "./StockMarket/StockMarket"; -import { Terminal, postVersion } from "./Terminal"; +import { Terminal } from "./Terminal"; import { Page, routing } from "./ui/navigationTracking"; @@ -65,13 +65,8 @@ function prestigeAugmentation() { Player.factions = Player.factions.concat(maintainMembership); - // Now actually go to the Terminal Screen (and reset it) - var mainMenu = document.getElementById("mainmenu-container"); - mainMenu.style.visibility = "visible"; - Terminal.resetTerminalInput(); + Terminal.clear(); Engine.loadTerminalContent(); - $("#terminal tr:not(:last)").remove(); - postVersion(); // Delete all Worker Scripts objects prestigeWorkerScripts(); diff --git a/src/Script/RunningScript.ts b/src/Script/RunningScript.ts index 9b0442ff7..cf5f9fac9 100644 --- a/src/Script/RunningScript.ts +++ b/src/Script/RunningScript.ts @@ -6,7 +6,7 @@ import { Script } from "./Script"; import { FconfSettings } from "../Fconf/FconfSettings"; import { Settings } from "../Settings/Settings"; import { IMap } from "../types"; -import { post } from "../ui/postToTerminal"; +import { Terminal } from "../Terminal"; import { Generic_fromJSON, Generic_toJSON, Reviver } from "../../utils/JSONReviver"; import { getTimestamp } from "../../utils/helpers/getTimestamp"; @@ -85,7 +85,7 @@ export class RunningScript { displayLog(): void { for (let i = 0; i < this.logs.length; ++i) { - post(this.logs[i]); + Terminal.print(this.logs[i]); } } diff --git a/src/Terminal.d.ts b/src/Terminal.d.ts index 80643959f..80b9d17aa 100644 --- a/src/Terminal.d.ts +++ b/src/Terminal.d.ts @@ -1 +1 @@ -export declare const Terminal: any; +export declare const Terminal: ITerminal; diff --git a/src/Terminal.jsx b/src/Terminal.jsx index 217f141be..da5f973dc 100644 --- a/src/Terminal.jsx +++ b/src/Terminal.jsx @@ -9,235 +9,25 @@ import { setTimeoutRef } from "./utils/SetTimeoutRef"; import { Page, routing } from "./ui/navigationTracking"; import { KEY } from "../utils/helpers/keyCodes"; import { getTimestamp } from "../utils/helpers/getTimestamp"; -import { post } from "./ui/postToTerminal"; import { Terminal as TTerminal } from "./Terminal/Terminal"; -const NewTerminal = new TTerminal(); - -import autosize from "autosize"; - -function postVersion() { - post("Bitburner v" + CONSTANTS.Version); -} - -function getTerminalInput() { - return document.getElementById("terminal-input-text-box").value; -} +const Terminal = new TTerminal(); // Defines key commands in terminal $(document).keydown(function (event) { // Terminal - if (routing.isOn(Page.Terminal)) { - var terminalInput = document.getElementById("terminal-input-text-box"); - if (terminalInput != null && !event.ctrlKey && !event.shiftKey && !NewTerminal.contractOpen) { - terminalInput.focus(); + + if (event.keyCode === KEY.C && event.ctrlKey) { + if (Engine._actionInProgress) { + // Cancel action + // post("Cancelling..."); + Engine._actionInProgress = false; + Terminal.finishAction(true); + } else if (FconfSettings.ENABLE_BASH_HOTKEYS) { + // Dont prevent default so it still copies + Terminal.clear(); // Clear Terminal } - - if (event.keyCode === KEY.ENTER) { - event.preventDefault(); // Prevent newline from being entered in Script Editor - const command = getTerminalInput(); - const dir = NewTerminal.currDir; - post( - "[" + - (FconfSettings.ENABLE_TIMESTAMPS ? getTimestamp() + " " : "") + - Player.getCurrentServer().hostname + - ` ~${dir}]> ${command}`, - ); - - if (command.length > 0) { - Terminal.resetTerminalInput(); // Clear input first - NewTerminal.executeCommands(Engine, Player, command); - } - } - - if (event.keyCode === KEY.C && event.ctrlKey) { - if (Engine._actionInProgress) { - // Cancel action - post("Cancelling..."); - Engine._actionInProgress = false; - NewTerminal.finishAction(true); - } else if (FconfSettings.ENABLE_BASH_HOTKEYS) { - // Dont prevent default so it still copies - Terminal.resetTerminalInput(); // Clear Terminal - } - } - - if (event.keyCode === KEY.L && event.ctrlKey) { - event.preventDefault(); - NewTerminal.executeCommands(Engine, Player, "clear"); // Clear screen - } - - // Ctrl p same as up arrow - // Ctrl n same as down arrow - - if ( - event.keyCode === KEY.UPARROW || - (FconfSettings.ENABLE_BASH_HOTKEYS && event.keyCode === KEY.P && event.ctrlKey) - ) { - if (FconfSettings.ENABLE_BASH_HOTKEYS) { - event.preventDefault(); - } - // Cycle through past commands - if (terminalInput == null) { - return; - } - var i = NewTerminal.commandHistoryIndex; - var len = NewTerminal.commandHistory.length; - - if (len == 0) { - return; - } - if (i < 0 || i > len) { - NewTerminal.commandHistoryIndex = len; - } - - if (i != 0) { - --NewTerminal.commandHistoryIndex; - } - var prevCommand = NewTerminal.commandHistory[NewTerminal.commandHistoryIndex]; - terminalInput.value = prevCommand; - setTimeoutRef(function () { - terminalInput.selectionStart = terminalInput.selectionEnd = 10000; - }, 10); - } - - if ( - event.keyCode === KEY.DOWNARROW || - (FconfSettings.ENABLE_BASH_HOTKEYS && event.keyCode === KEY.M && event.ctrlKey) - ) { - if (FconfSettings.ENABLE_BASH_HOTKEYS) { - event.preventDefault(); - } - // Cycle through past commands - if (terminalInput == null) { - return; - } - var i = NewTerminal.commandHistoryIndex; - var len = NewTerminal.commandHistory.length; - - if (len == 0) { - return; - } - if (i < 0 || i > len) { - NewTerminal.commandHistoryIndex = len; - } - - // Latest command, put nothing - if (i == len || i == len - 1) { - NewTerminal.commandHistoryIndex = len; - terminalInput.value = ""; - } else { - ++NewTerminal.commandHistoryIndex; - var prevCommand = NewTerminal.commandHistory[NewTerminal.commandHistoryIndex]; - terminalInput.value = prevCommand; - } - } - - if (event.keyCode === KEY.TAB) { - event.preventDefault(); - - // Autocomplete - if (terminalInput == null) { - return; - } - let input = terminalInput.value; - if (input == "") { - return; - } - - const semiColonIndex = input.lastIndexOf(";"); - if (semiColonIndex !== -1) { - input = input.slice(semiColonIndex + 1); - } - - input = input.trim(); - input = input.replace(/\s\s+/g, " "); - - const commandArray = input.split(" "); - let index = commandArray.length - 2; - if (index < -1) { - index = 0; - } - const allPos = determineAllPossibilitiesForTabCompletion(Player, input, index, NewTerminal.currDir); - if (allPos.length == 0) { - return; - } - - let arg = ""; - let command = ""; - if (commandArray.length == 0) { - return; - } - if (commandArray.length == 1) { - command = commandArray[0]; - } else if (commandArray.length == 2) { - command = commandArray[0]; - arg = commandArray[1]; - } else if (commandArray.length == 3) { - command = commandArray[0] + " " + commandArray[1]; - arg = commandArray[2]; - } else { - arg = commandArray.pop(); - command = commandArray.join(" "); - } - - tabCompletion(command, arg, allPos); - terminalInput.focus(); - } - - // Extra Bash Emulation Hotkeys, must be enabled through .fconf - if (FconfSettings.ENABLE_BASH_HOTKEYS) { - if (event.keyCode === KEY.A && event.ctrlKey) { - event.preventDefault(); - Terminal.moveTextCursor("home"); - } - - if (event.keyCode === KEY.E && event.ctrlKey) { - event.preventDefault(); - Terminal.moveTextCursor("end"); - } - - if (event.keyCode === KEY.B && event.ctrlKey) { - event.preventDefault(); - Terminal.moveTextCursor("prevchar"); - } - - if (event.keyCode === KEY.B && event.altKey) { - event.preventDefault(); - Terminal.moveTextCursor("prevword"); - } - - if (event.keyCode === KEY.F && event.ctrlKey) { - event.preventDefault(); - Terminal.moveTextCursor("nextchar"); - } - - if (event.keyCode === KEY.F && event.altKey) { - event.preventDefault(); - Terminal.moveTextCursor("nextword"); - } - - if ((event.keyCode === KEY.H || event.keyCode === KEY.D) && event.ctrlKey) { - Terminal.modifyInput("backspace"); - event.preventDefault(); - } - - // TODO AFTER THIS: - // alt + d deletes word after cursor - // ^w deletes word before cursor - // ^k clears line after cursor - // ^u clears line before cursor - } - } -}); - -// Keep terminal in focus -let terminalCtrlPressed = false, - shiftKeyPressed = false; -$(document).ready(function () { - if (routing.isOn(Page.Terminal)) { - $(".terminal-input").focus(); } }); @@ -247,7 +37,7 @@ $(document).keydown(function (e) { terminalCtrlPressed = true; } else if (e.shiftKey) { shiftKeyPressed = true; - } else if (terminalCtrlPressed || shiftKeyPressed || NewTerminal.contractOpen) { + } else if (terminalCtrlPressed || shiftKeyPressed || Terminal.contractOpen) { // Don't focus } else { var inputTextBox = document.getElementById("terminal-input-text-box"); @@ -261,146 +51,4 @@ $(document).keydown(function (e) { } }); -$(document).keyup(function (e) { - if (routing.isOn(Page.Terminal)) { - if (e.which == KEY.CTRL) { - terminalCtrlPressed = false; - } - if (e.shiftKey) { - shiftKeyPressed = false; - } - } -}); - -let Terminal = { - resetTerminalInput: function (keepInput = false) { - let input = ""; - if (keepInput) { - input = getTerminalInput(); - } - const dir = NewTerminal.currDir; - if (FconfSettings.WRAP_INPUT) { - document.getElementById("terminal-input-td").innerHTML = - `
[${Player.getCurrentServer().hostname} ~${dir}]$
` + - `