mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-28 02:23:53 +01:00
commit
a4e1d4872d
4
dist/main.bundle.js
vendored
4
dist/main.bundle.js
vendored
File diff suppressed because one or more lines are too long
2
dist/main.bundle.js.map
vendored
2
dist/main.bundle.js.map
vendored
File diff suppressed because one or more lines are too long
42
dist/vendor.bundle.js
vendored
42
dist/vendor.bundle.js
vendored
File diff suppressed because one or more lines are too long
2
dist/vendor.bundle.js.map
vendored
2
dist/vendor.bundle.js.map
vendored
File diff suppressed because one or more lines are too long
@ -39,7 +39,7 @@ There are two methods of obtaining Duplicate Sleeves:
|
|||||||
|
|
||||||
1. Destroy BitNode-10. Each completion give you one additional Duplicate Sleeve
|
1. Destroy BitNode-10. Each completion give you one additional Duplicate Sleeve
|
||||||
2. Purchase Duplicate Sleeves from :ref:`the faction The Covenant <gameplay_factions>`.
|
2. Purchase Duplicate Sleeves from :ref:`the faction The Covenant <gameplay_factions>`.
|
||||||
This is only available in BitNodes-10. Sleeves purchased this way are **permanent** (they persist
|
This is only available in BitNode-10. Sleeves purchased this way are **permanent** (they persist
|
||||||
through BitNodes). You can purchase up to 5 Duplicate Sleeves from The Covenant.
|
through BitNodes). You can purchase up to 5 Duplicate Sleeves from The Covenant.
|
||||||
|
|
||||||
Synchronization
|
Synchronization
|
||||||
@ -86,8 +86,7 @@ switching BitNodes. For example, if a sleeve has a memory of 10, then when you
|
|||||||
switch BitNodes its synchronization will initially be set to 10, rather than 1.
|
switch BitNodes its synchronization will initially be set to 10, rather than 1.
|
||||||
|
|
||||||
Memory can only be increased by purchasing upgrades from The Covenant. Just like
|
Memory can only be increased by purchasing upgrades from The Covenant. Just like
|
||||||
the ability to purchase additional sleeves, this is only available in BitNodes-10
|
the ability to purchase additional sleeves, this is only available in BitNode-10.
|
||||||
and above, and is only available after defeating BitNode-10 at least once.
|
|
||||||
|
|
||||||
Memory is a persistent stat, meaning it never gets reset back to 1.
|
Memory is a persistent stat, meaning it never gets reset back to 1.
|
||||||
The maximum possible value for a sleeve's memory is 100.
|
The maximum possible value for a sleeve's memory is 100.
|
||||||
|
@ -23,3 +23,14 @@ into a script using::
|
|||||||
args.length
|
args.length
|
||||||
|
|
||||||
**WARNING: Do not try to modify the args array. This will break the game.**
|
**WARNING: Do not try to modify the args array. This will break the game.**
|
||||||
|
|
||||||
|
|
||||||
|
example for accessing arguments in ns2 from terminal execution:
|
||||||
|
terminal command:
|
||||||
|
run name_of_script.js -t 10 --tail argument1 argument2
|
||||||
|
|
||||||
|
ns2 script:
|
||||||
|
|
||||||
|
const args_obj = arguments[0]
|
||||||
|
const argument1 = (args_obj.server.args[0])
|
||||||
|
const argument2 = (args_obj.server.args[1])
|
||||||
|
@ -256,8 +256,8 @@ export const BlackOperations: {
|
|||||||
ones from the Uprising.
|
ones from the Uprising.
|
||||||
<br />
|
<br />
|
||||||
<br />
|
<br />
|
||||||
{FactionNames.OmniTekIncorporated} has also told us they they believe someone has triggered this malfunction in
|
{FactionNames.OmniTekIncorporated} has also told us they believe someone has triggered this malfunction in a
|
||||||
a large group of MK-VI Synthoids, and that these newly-radicalized Synthoids are now amassing in{" "}
|
large group of MK-VI Synthoids, and that these newly-radicalized Synthoids are now amassing in{" "}
|
||||||
{CityName.Volhaven} to form a terrorist group called Ultron.
|
{CityName.Volhaven} to form a terrorist group called Ultron.
|
||||||
<br />
|
<br />
|
||||||
<br />
|
<br />
|
||||||
|
@ -71,7 +71,7 @@ export const CorporationUpgrades: Record<CorporationUpgradeIndex, CorporationUpg
|
|||||||
name: "Wilson Analytics",
|
name: "Wilson Analytics",
|
||||||
desc:
|
desc:
|
||||||
"Purchase data and analysis from Wilson, a marketing research " +
|
"Purchase data and analysis from Wilson, a marketing research " +
|
||||||
"firm. Each level of this upgrades increases the effectiveness of your " +
|
"firm. Each level of this upgrade increases the effectiveness of your " +
|
||||||
"advertising by 0.5% (additive).",
|
"advertising by 0.5% (additive).",
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -150,7 +150,7 @@ export const FactionInfos: IMap<FactionInfo> = {
|
|||||||
[FactionNames.BachmanAssociates]: new FactionInfo({
|
[FactionNames.BachmanAssociates]: new FactionInfo({
|
||||||
infoText: (
|
infoText: (
|
||||||
<>
|
<>
|
||||||
Where Law and Business meet - thats where we are.
|
Where Law and Business meet - that's where we are.
|
||||||
<br />
|
<br />
|
||||||
<br />
|
<br />
|
||||||
Legal Insight - Business Instinct - Innovative Experience.
|
Legal Insight - Business Instinct - Innovative Experience.
|
||||||
|
@ -426,7 +426,7 @@ function processAllHacknetServerEarnings(player: IPlayer, numCycles: number): nu
|
|||||||
if (upgrade === null) throw new Error("Could not get the hash upgrade");
|
if (upgrade === null) throw new Error("Could not get the hash upgrade");
|
||||||
if (!upgrade.cost) throw new Error("Upgrade is not properly configured");
|
if (!upgrade.cost) throw new Error("Upgrade is not properly configured");
|
||||||
|
|
||||||
const multiplier = Math.floor(wastedHashes / upgrade.cost);
|
const multiplier = wastedHashes / upgrade.cost;
|
||||||
if (multiplier > 0) {
|
if (multiplier > 0) {
|
||||||
player.gainMoney(upgrade.value * multiplier, "hacknet");
|
player.gainMoney(upgrade.value * multiplier, "hacknet");
|
||||||
}
|
}
|
||||||
|
@ -244,7 +244,7 @@ export const Literatures: IMap<Literature> = {};
|
|||||||
"is that most of the rise is in violent crime such as homicide and assault. According " +
|
"is that most of the rise is in violent crime such as homicide and assault. According " +
|
||||||
"to the study, the city saw a total of 21,406 reported homicides in 2076, which is over " +
|
"to the study, the city saw a total of 21,406 reported homicides in 2076, which is over " +
|
||||||
"a 20% increase compared to 2075.<br><br>" +
|
"a 20% increase compared to 2075.<br><br>" +
|
||||||
"CIA director David Glarow says its too early to know " +
|
"CIA director David Glarow says it's too early to know " +
|
||||||
"whether these figures indicate the beginning of a sustained increase in crime rates, or whether " +
|
"whether these figures indicate the beginning of a sustained increase in crime rates, or whether " +
|
||||||
"the year was just an unfortunate outlier. He states that many intelligence and law enforcement " +
|
"the year was just an unfortunate outlier. He states that many intelligence and law enforcement " +
|
||||||
"agents have noticed an increase in organized crime activites, and believes that these figures may " +
|
"agents have noticed an increase in organized crime activites, and believes that these figures may " +
|
||||||
@ -319,7 +319,7 @@ export const Literatures: IMap<Literature> = {};
|
|||||||
"CompanionBot, a robot meant to act as a comforting friend for lonely and grieving people, is eerily human-like " +
|
"CompanionBot, a robot meant to act as a comforting friend for lonely and grieving people, is eerily human-like " +
|
||||||
"in its appearance, speech, mannerisms, and even movement. However its artificial intelligence isn't the same as " +
|
"in its appearance, speech, mannerisms, and even movement. However its artificial intelligence isn't the same as " +
|
||||||
"that of humans. Not yet. It doesn't have sentience or self-awareness or consciousness.<br><br>" +
|
"that of humans. Not yet. It doesn't have sentience or self-awareness or consciousness.<br><br>" +
|
||||||
"Many neuroscientists believe that we won't ever reach the point of creating artificial human intelligence. 'At the end of the " +
|
"Many neuroscientists believe that we won't ever reach the point of creating artificial human intelligence. 'At the end of " +
|
||||||
"the day, AI comes down to 1's and 0's, while the human brain does not. We'll never see AI that is identical to that of " +
|
"the day, AI comes down to 1's and 0's, while the human brain does not. We'll never see AI that is identical to that of " +
|
||||||
"humans.'";
|
"humans.'";
|
||||||
Literatures[fn] = new Literature(title, fn, txt);
|
Literatures[fn] = new Literature(title, fn, txt);
|
||||||
|
@ -232,7 +232,7 @@ export function SpecialLocation(props: IProps): React.ReactElement {
|
|||||||
<>
|
<>
|
||||||
<Typography>
|
<Typography>
|
||||||
<i>
|
<i>
|
||||||
Allison "Mother" Stanek: I see you've taken to my creation. So much so it could hardly be recognized as
|
Allison "Mother" Stanek: I see you've taken to my creation. So much that it could hardly be recognized as
|
||||||
one of my own after your tinkering with it. I see you follow the ways of the Machine God as I do, and your
|
one of my own after your tinkering with it. I see you follow the ways of the Machine God as I do, and your
|
||||||
mastery of the gift clearly demonstrates that. My hopes are climbing by the day for you.
|
mastery of the gift clearly demonstrates that. My hopes are climbing by the day for you.
|
||||||
</i>
|
</i>
|
||||||
|
@ -164,6 +164,11 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
|||||||
|
|
||||||
const augs = getFactionAugmentationsFiltered(player, fac);
|
const augs = getFactionAugmentationsFiltered(player, fac);
|
||||||
|
|
||||||
|
if (!player.factions.includes(fac.name)) {
|
||||||
|
_ctx.log(() => `You can't purchase augmentations from '${facName}' because you aren't a member`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!augs.includes(augName)) {
|
if (!augs.includes(augName)) {
|
||||||
_ctx.log(() => `Faction '${facName}' does not have the '${augName}' augmentation.`);
|
_ctx.log(() => `Faction '${facName}' does not have the '${augName}' augmentation.`);
|
||||||
return false;
|
return false;
|
||||||
|
@ -1326,10 +1326,16 @@ export function createProgramWork(this: IPlayer, numCycles: number): boolean {
|
|||||||
|
|
||||||
export function finishCreateProgramWork(this: IPlayer, cancelled: boolean): string {
|
export function finishCreateProgramWork(this: IPlayer, cancelled: boolean): string {
|
||||||
const programName = this.createProgramName;
|
const programName = this.createProgramName;
|
||||||
|
let message = "";
|
||||||
if (!cancelled) {
|
if (!cancelled) {
|
||||||
//Complete case
|
//Complete case
|
||||||
this.gainIntelligenceExp((CONSTANTS.IntelligenceProgramBaseExpGain * this.timeWorked) / 1000);
|
this.gainIntelligenceExp((CONSTANTS.IntelligenceProgramBaseExpGain * this.timeWorked) / 1000);
|
||||||
dialogBoxCreate(`You've finished creating ${programName}!<br>The new program can be found on your home computer.`);
|
const lines = [
|
||||||
|
`You've finished creating ${programName}!`,
|
||||||
|
"The new program can be found on your home computer.",
|
||||||
|
];
|
||||||
|
dialogBoxCreate(lines.join("<br>"));
|
||||||
|
message = lines.join(" ");
|
||||||
|
|
||||||
if (!this.getHomeComputer().programs.includes(programName)) {
|
if (!this.getHomeComputer().programs.includes(programName)) {
|
||||||
this.getHomeComputer().programs.push(programName);
|
this.getHomeComputer().programs.push(programName);
|
||||||
@ -1339,12 +1345,12 @@ export function finishCreateProgramWork(this: IPlayer, cancelled: boolean): stri
|
|||||||
const perc = (Math.floor((this.timeWorkedCreateProgram / this.timeNeededToCompleteWork) * 10000) / 100).toString();
|
const perc = (Math.floor((this.timeWorkedCreateProgram / this.timeNeededToCompleteWork) * 10000) / 100).toString();
|
||||||
const incompleteName = programName + "-" + perc + "%-INC";
|
const incompleteName = programName + "-" + perc + "%-INC";
|
||||||
this.getHomeComputer().programs.push(incompleteName);
|
this.getHomeComputer().programs.push(incompleteName);
|
||||||
|
message = `Cancelled creating program: ${programName} (${perc}% complete)`;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.isWorking = false;
|
this.isWorking = false;
|
||||||
|
|
||||||
this.resetWorkStatus();
|
this.resetWorkStatus();
|
||||||
return "You've finished creating " + programName + "! The new program can be found on your home computer.";
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function startGraftAugmentationWork(this: IPlayer, augmentationName: string, time: number): void {
|
export function startGraftAugmentationWork(this: IPlayer, augmentationName: string, time: number): void {
|
||||||
|
@ -104,7 +104,7 @@ export function FAQModal({ open, onClose }: IProps): React.ReactElement {
|
|||||||
<Typography variant="h4">What is Memory?</Typography>
|
<Typography variant="h4">What is Memory?</Typography>
|
||||||
<br />
|
<br />
|
||||||
<Typography>
|
<Typography>
|
||||||
Sleeve memory dictates what a sleeve's synchronization will be when its reset by switching BitNodes. For
|
Sleeve memory dictates what a sleeve's synchronization will be when it's reset by switching BitNodes. For
|
||||||
example, if a sleeve has a memory of 25, then when you switch BitNodes its synchronization will initially be
|
example, if a sleeve has a memory of 25, then when you switch BitNodes its synchronization will initially be
|
||||||
set to 25, rather than 1.
|
set to 25, rather than 1.
|
||||||
</Typography>
|
</Typography>
|
||||||
|
@ -580,7 +580,7 @@ function createNewUpdateText(): void {
|
|||||||
() =>
|
() =>
|
||||||
dialogBoxCreate(
|
dialogBoxCreate(
|
||||||
"New update!<br>" +
|
"New update!<br>" +
|
||||||
"Please report any bugs/issues through the github repository " +
|
"Please report any bugs/issues through the GitHub repository " +
|
||||||
"or the Bitburner subreddit (reddit.com/r/bitburner).<br><br>" +
|
"or the Bitburner subreddit (reddit.com/r/bitburner).<br><br>" +
|
||||||
CONSTANTS.LatestUpdate,
|
CONSTANTS.LatestUpdate,
|
||||||
resets,
|
resets,
|
||||||
|
35
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
35
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@ -4859,6 +4859,7 @@ export interface NS {
|
|||||||
* @remarks
|
* @remarks
|
||||||
* RAM cost: 0 GB
|
* RAM cost: 0 GB
|
||||||
*
|
*
|
||||||
|
* see: https://github.com/alexei/sprintf.js
|
||||||
* @param format - format of the message
|
* @param format - format of the message
|
||||||
* @param msg - Value to be printed.
|
* @param msg - Value to be printed.
|
||||||
*/
|
*/
|
||||||
@ -4950,7 +4951,7 @@ export interface NS {
|
|||||||
* @param args - Arguments to identify which scripts to get logs for.
|
* @param args - Arguments to identify which scripts to get logs for.
|
||||||
* @returns Returns an string array, where each line is an element in the array. The most recently logged line is at the end of the array.
|
* @returns Returns an string array, where each line is an element in the array. The most recently logged line is at the end of the array.
|
||||||
*/
|
*/
|
||||||
getScriptLogs(fn?: string, host?: string, ...args: any[]): string[];
|
getScriptLogs(fn?: string, host?: string, ...args: (string | number | boolean)[]): string[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an array of recently killed scripts across all servers.
|
* Get an array of recently killed scripts across all servers.
|
||||||
@ -5013,7 +5014,7 @@ export interface NS {
|
|||||||
* @param host - Optional. Hostname of the script being tailed. Defaults to the server this script is running on. If args are specified, this is not optional.
|
* @param host - Optional. Hostname of the script being tailed. Defaults to the server this script is running on. If args are specified, this is not optional.
|
||||||
* @param args - Arguments for the script being tailed.
|
* @param args - Arguments for the script being tailed.
|
||||||
*/
|
*/
|
||||||
tail(fn?: FilenameOrPID, host?: string, ...args: any[]): void;
|
tail(fn?: FilenameOrPID, host?: string, ...args: (string | number | boolean)[]): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Close the tail window of a script.
|
* Close the tail window of a script.
|
||||||
@ -5218,7 +5219,7 @@ export interface NS {
|
|||||||
* @param args - Additional arguments to pass into the new script that is being run. Note that if any arguments are being passed into the new script, then the second argument numThreads must be filled in with a value.
|
* @param args - Additional arguments to pass into the new script that is being run. Note that if any arguments are being passed into the new script, then the second argument numThreads must be filled in with a value.
|
||||||
* @returns Returns the PID of a successfully started script, and 0 otherwise.
|
* @returns Returns the PID of a successfully started script, and 0 otherwise.
|
||||||
*/
|
*/
|
||||||
run(script: string, numThreads?: number, ...args: Array<string | number | boolean>): number;
|
run(script: string, numThreads?: number, ...args: (string | number | boolean)[]): number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start another script on any server.
|
* Start another script on any server.
|
||||||
@ -5266,7 +5267,7 @@ export interface NS {
|
|||||||
* @param args - Additional arguments to pass into the new script that is being run. Note that if any arguments are being passed into the new script, then the third argument numThreads must be filled in with a value.
|
* @param args - Additional arguments to pass into the new script that is being run. Note that if any arguments are being passed into the new script, then the third argument numThreads must be filled in with a value.
|
||||||
* @returns Returns the PID of a successfully started script, and 0 otherwise.
|
* @returns Returns the PID of a successfully started script, and 0 otherwise.
|
||||||
*/
|
*/
|
||||||
exec(script: string, host: string, numThreads?: number, ...args: Array<string | number | boolean>): number;
|
exec(script: string, host: string, numThreads?: number, ...args: (string | number | boolean)[]): number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Terminate current script and start another in 10s.
|
* Terminate current script and start another in 10s.
|
||||||
@ -5296,7 +5297,7 @@ export interface NS {
|
|||||||
* @param numThreads - Number of threads to spawn new script with. Will be rounded to nearest integer.
|
* @param numThreads - Number of threads to spawn new script with. Will be rounded to nearest integer.
|
||||||
* @param args - Additional arguments to pass into the new script that is being run.
|
* @param args - Additional arguments to pass into the new script that is being run.
|
||||||
*/
|
*/
|
||||||
spawn(script: string, numThreads?: number, ...args: string[]): void;
|
spawn(script: string, numThreads?: number, ...args: (string | number | boolean)[]): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Terminate another script.
|
* Terminate another script.
|
||||||
@ -5366,7 +5367,7 @@ export interface NS {
|
|||||||
* ns.kill("foo.script", getHostname(), 1, "foodnstuff");
|
* ns.kill("foo.script", getHostname(), 1, "foodnstuff");
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
kill(script: string, host: string, ...args: string[]): boolean;
|
kill(script: string, host: string, ...args: (string | number | boolean)[]): boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Terminate all scripts on a server.
|
* Terminate all scripts on a server.
|
||||||
@ -5863,7 +5864,7 @@ export interface NS {
|
|||||||
* @param args - Arguments to specify/identify which scripts to search for.
|
* @param args - Arguments to specify/identify which scripts to search for.
|
||||||
* @returns True if specified script is running on the target server, and false otherwise.
|
* @returns True if specified script is running on the target server, and false otherwise.
|
||||||
*/
|
*/
|
||||||
isRunning(script: FilenameOrPID, host: string, ...args: string[]): boolean;
|
isRunning(script: FilenameOrPID, host?: string, ...args: (string | number | boolean)[]): boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get general info about a running script.
|
* Get general info about a running script.
|
||||||
@ -5878,7 +5879,11 @@ export interface NS {
|
|||||||
* @param args - Arguments to identify the script
|
* @param args - Arguments to identify the script
|
||||||
* @returns The info about the running script if found, and null otherwise.
|
* @returns The info about the running script if found, and null otherwise.
|
||||||
*/
|
*/
|
||||||
getRunningScript(filename?: FilenameOrPID, hostname?: string, ...args: (string | number)[]): RunningScript | null;
|
getRunningScript(
|
||||||
|
filename?: FilenameOrPID,
|
||||||
|
hostname?: string,
|
||||||
|
...args: (string | number | boolean)[]
|
||||||
|
): RunningScript | null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get cost of purchasing a server.
|
* Get cost of purchasing a server.
|
||||||
@ -6204,13 +6209,13 @@ export interface NS {
|
|||||||
* Get the execution time of a hack() call.
|
* Get the execution time of a hack() call.
|
||||||
* @remarks
|
* @remarks
|
||||||
* RAM cost: 0.05 GB
|
* RAM cost: 0.05 GB
|
||||||
|
*
|
||||||
* When `hack` completes an amount of money is stolen depending on the player's skills.
|
* When `hack` completes an amount of money is stolen depending on the player's skills.
|
||||||
* Returns the amount of time in milliseconds it takes to execute the hack Netscript function on the target server.
|
* Returns the amount of time in milliseconds it takes to execute the hack Netscript function on the target server.
|
||||||
* The function takes in an optional hackLvl parameter that can be specified to see what the hack time would be at different hacking levels.
|
|
||||||
* The required time is increased by the security level of the target server and decreased by the player's hacking level.
|
* The required time is increased by the security level of the target server and decreased by the player's hacking level.
|
||||||
*
|
*
|
||||||
* @param host - Host of target server.
|
* @param host - Host of target server.
|
||||||
* @returns Returns the amount of time in milliseconds it takes to execute the hack Netscript function. Returns Infinity if called on a Hacknet Server.
|
* @returns Returns the amount of time in milliseconds it takes to execute the hack Netscript function.
|
||||||
*/
|
*/
|
||||||
getHackTime(host: string): number;
|
getHackTime(host: string): number;
|
||||||
|
|
||||||
@ -6220,11 +6225,10 @@ export interface NS {
|
|||||||
* RAM cost: 0.05 GB
|
* RAM cost: 0.05 GB
|
||||||
*
|
*
|
||||||
* Returns the amount of time in milliseconds it takes to execute the grow Netscript function on the target server.
|
* Returns the amount of time in milliseconds it takes to execute the grow Netscript function on the target server.
|
||||||
* The function takes in an optional hackLvl parameter that can be specified to see what the grow time would be at different hacking levels.
|
|
||||||
* The required time is increased by the security level of the target server and decreased by the player's hacking level.
|
* The required time is increased by the security level of the target server and decreased by the player's hacking level.
|
||||||
*
|
*
|
||||||
* @param host - Host of target server.
|
* @param host - Host of target server.
|
||||||
* @returns Returns the amount of time in milliseconds it takes to execute the grow Netscript function. Returns Infinity if called on a Hacknet Server.
|
* @returns Returns the amount of time in milliseconds it takes to execute the grow Netscript function.
|
||||||
*/
|
*/
|
||||||
getGrowTime(host: string): number;
|
getGrowTime(host: string): number;
|
||||||
|
|
||||||
@ -6234,11 +6238,10 @@ export interface NS {
|
|||||||
* RAM cost: 0.05 GB
|
* RAM cost: 0.05 GB
|
||||||
*
|
*
|
||||||
* Returns the amount of time in milliseconds it takes to execute the weaken Netscript function on the target server.
|
* Returns the amount of time in milliseconds it takes to execute the weaken Netscript function on the target server.
|
||||||
* The function takes in an optional hackLvl parameter that can be specified to see what the weaken time would be at different hacking levels.
|
|
||||||
* The required time is increased by the security level of the target server and decreased by the player's hacking level.
|
* The required time is increased by the security level of the target server and decreased by the player's hacking level.
|
||||||
*
|
*
|
||||||
* @param host - Host of target server.
|
* @param host - Host of target server.
|
||||||
* @returns Returns the amount of time in milliseconds it takes to execute the weaken Netscript function. Returns Infinity if called on a Hacknet Server.
|
* @returns Returns the amount of time in milliseconds it takes to execute the weaken Netscript function.
|
||||||
*/
|
*/
|
||||||
getWeakenTime(host: string): number;
|
getWeakenTime(host: string): number;
|
||||||
|
|
||||||
@ -6271,7 +6274,7 @@ export interface NS {
|
|||||||
/**
|
/**
|
||||||
* {@inheritDoc NS.(getScriptIncome:1)}
|
* {@inheritDoc NS.(getScriptIncome:1)}
|
||||||
*/
|
*/
|
||||||
getScriptIncome(script: string, host: string, ...args: string[]): number;
|
getScriptIncome(script: string, host: string, ...args: (string | number | boolean)[]): number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the exp gain of a script.
|
* Get the exp gain of a script.
|
||||||
@ -6295,7 +6298,7 @@ export interface NS {
|
|||||||
/**
|
/**
|
||||||
* {@inheritDoc NS.(getScriptExpGain:1)}
|
* {@inheritDoc NS.(getScriptExpGain:1)}
|
||||||
*/
|
*/
|
||||||
getScriptExpGain(script: string, host: string, ...args: string[]): number;
|
getScriptExpGain(script: string, host: string, ...args: (string | number | boolean)[]): number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the amount of time in milliseconds that have passed since you last installed Augmentations.
|
* Returns the amount of time in milliseconds that have passed since you last installed Augmentations.
|
||||||
|
@ -272,6 +272,8 @@ export function SidebarRoot(props: IProps): React.ReactElement {
|
|||||||
// Alt-a - Augmentations
|
// Alt-a - Augmentations
|
||||||
// Alt-u - Tutorial
|
// Alt-u - Tutorial
|
||||||
// Alt-o - Options
|
// Alt-o - Options
|
||||||
|
// Alt-b - Bladeburner
|
||||||
|
// Alt-g - Gang
|
||||||
function handleShortcuts(this: Document, event: KeyboardEvent): any {
|
function handleShortcuts(this: Document, event: KeyboardEvent): any {
|
||||||
if (Settings.DisableHotkeys) return;
|
if (Settings.DisableHotkeys) return;
|
||||||
if ((props.player.isWorking && props.player.focus) || props.router.page() === Page.BitVerse) return;
|
if ((props.player.isWorking && props.player.focus) || props.router.page() === Page.BitVerse) return;
|
||||||
@ -315,6 +317,9 @@ export function SidebarRoot(props: IProps): React.ReactElement {
|
|||||||
} else if (event.code === KEYCODE.U && event.altKey) {
|
} else if (event.code === KEYCODE.U && event.altKey) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
clickTutorial();
|
clickTutorial();
|
||||||
|
} else if (event.code === KEYCODE.O && event.altKey) {
|
||||||
|
event.preventDefault();
|
||||||
|
clickOptions();
|
||||||
} else if (event.code === KEYCODE.B && event.altKey && props.player.bladeburner) {
|
} else if (event.code === KEYCODE.B && event.altKey && props.player.bladeburner) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
clickBladeburner();
|
clickBladeburner();
|
||||||
|
@ -35,7 +35,7 @@ export const TerminalHelpText: string[] = [
|
|||||||
" rm [file] Delete a file from the server",
|
" rm [file] Delete a file from the server",
|
||||||
" run [name] [-t n] [--tail] [args...] Execute a program or script",
|
" run [name] [-t n] [--tail] [args...] Execute a program or script",
|
||||||
" scan Prints all immediately-available network connections",
|
" scan Prints all immediately-available network connections",
|
||||||
" scan-analyze [d] [-a] Prints info for all servers up to <i>d</i> nodes away",
|
" scan-analyze [d] [-a] Prints info for all servers up to d nodes away",
|
||||||
" scp [file ...] [server] Copies a file to a destination server",
|
" scp [file ...] [server] Copies a file to a destination server",
|
||||||
" sudov Shows whether you have root access on this computer",
|
" sudov Shows whether you have root access on this computer",
|
||||||
" tail [script] [args...] Displays dynamic logs for the specified script",
|
" tail [script] [args...] Displays dynamic logs for the specified script",
|
||||||
|
@ -16,6 +16,7 @@ import { BitFlumeModal } from "../../BitNode/ui/BitFlumeModal";
|
|||||||
import { CodingContractModal } from "../../ui/React/CodingContractModal";
|
import { CodingContractModal } from "../../ui/React/CodingContractModal";
|
||||||
|
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
|
import { ANSIITypography } from "../../ui/React/ANSIITypography";
|
||||||
|
|
||||||
interface IActionTimerProps {
|
interface IActionTimerProps {
|
||||||
terminal: ITerminal;
|
terminal: ITerminal;
|
||||||
@ -43,37 +44,6 @@ const useStyles = makeStyles((theme: Theme) =>
|
|||||||
padding: theme.spacing(0),
|
padding: theme.spacing(0),
|
||||||
height: "100%",
|
height: "100%",
|
||||||
},
|
},
|
||||||
|
|
||||||
success: {
|
|
||||||
whiteSpace: "pre-wrap",
|
|
||||||
overflowWrap: "anywhere",
|
|
||||||
margin: theme.spacing(0),
|
|
||||||
color: theme.colors.success,
|
|
||||||
},
|
|
||||||
error: {
|
|
||||||
whiteSpace: "pre-wrap",
|
|
||||||
overflowWrap: "anywhere",
|
|
||||||
margin: theme.spacing(0),
|
|
||||||
color: theme.palette.error.main,
|
|
||||||
},
|
|
||||||
primary: {
|
|
||||||
whiteSpace: "pre-wrap",
|
|
||||||
overflowWrap: "anywhere",
|
|
||||||
margin: theme.spacing(0),
|
|
||||||
color: theme.palette.primary.main,
|
|
||||||
},
|
|
||||||
info: {
|
|
||||||
whiteSpace: "pre-wrap",
|
|
||||||
overflowWrap: "anywhere",
|
|
||||||
margin: theme.spacing(0),
|
|
||||||
color: theme.palette.info.main,
|
|
||||||
},
|
|
||||||
warning: {
|
|
||||||
whiteSpace: "pre-wrap",
|
|
||||||
overflowWrap: "anywhere",
|
|
||||||
margin: theme.spacing(0),
|
|
||||||
color: theme.palette.warning.main,
|
|
||||||
},
|
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -133,194 +103,6 @@ export function TerminalRoot({ terminal, router, player }: IProps): React.ReactE
|
|||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
function lineClass(s: string): string {
|
|
||||||
const lineClassMap: Record<string, string> = {
|
|
||||||
error: classes.error,
|
|
||||||
success: classes.success,
|
|
||||||
info: classes.info,
|
|
||||||
warn: classes.warning,
|
|
||||||
};
|
|
||||||
return lineClassMap[s] || classes.primary;
|
|
||||||
}
|
|
||||||
|
|
||||||
function ansiCodeStyle(code: string | null): Record<string, any> {
|
|
||||||
// The ANSI colors actually have the dark color set as default and require extra work to get
|
|
||||||
// bright colors. But these are rarely used or, if they are, are often re-mapped by the
|
|
||||||
// terminal emulator to brighter colors. So for foreground colors we use the bright color set
|
|
||||||
// and for background colors we use the dark color set. Of course, all colors are available
|
|
||||||
// via the longer ESC[n8;5;c] sequence (n={3,4}, c=color). Ideally, these 8-bit maps could
|
|
||||||
// be managed in the user preferences/theme.
|
|
||||||
const COLOR_MAP_BRIGHT: Record<string | number, string> = {
|
|
||||||
0: "#404040",
|
|
||||||
1: "#ff0000",
|
|
||||||
2: "#00ff00",
|
|
||||||
3: "#ffff00",
|
|
||||||
4: "#0000ff",
|
|
||||||
5: "#ff00ff",
|
|
||||||
6: "#00ffff",
|
|
||||||
7: "#ffffff",
|
|
||||||
};
|
|
||||||
const COLOR_MAP_DARK: Record<string | number, string> = {
|
|
||||||
0: "#000000",
|
|
||||||
1: "#800000",
|
|
||||||
2: "#008000",
|
|
||||||
3: "#808000",
|
|
||||||
4: "#000080",
|
|
||||||
5: "#800080",
|
|
||||||
6: "#008080",
|
|
||||||
7: "#c0c0c0",
|
|
||||||
};
|
|
||||||
|
|
||||||
const ansi2rgb = (code: number): string => {
|
|
||||||
/* eslint-disable yoda */
|
|
||||||
if (0 <= code && code < 8) {
|
|
||||||
// x8 RGB
|
|
||||||
return COLOR_MAP_BRIGHT[code];
|
|
||||||
}
|
|
||||||
if (8 <= code && code < 16) {
|
|
||||||
// x8 RGB - "High Intensity" (but here, actually the dark set)
|
|
||||||
return COLOR_MAP_DARK[code];
|
|
||||||
}
|
|
||||||
if (16 <= code && code < 232) {
|
|
||||||
// x216 RGB
|
|
||||||
const base = code - 16;
|
|
||||||
const ir = Math.floor(base / 36);
|
|
||||||
const ig = Math.floor((base % 36) / 6);
|
|
||||||
const ib = Math.floor((base % 6) / 1);
|
|
||||||
const r = ir <= 0 ? 0 : 55 + ir * 40;
|
|
||||||
const g = ig <= 0 ? 0 : 55 + ig * 40;
|
|
||||||
const b = ib <= 0 ? 0 : 55 + ib * 40;
|
|
||||||
return `rgb(${r}, ${g}, ${b})`;
|
|
||||||
}
|
|
||||||
if (232 <= code && code < 256) {
|
|
||||||
// x32 greyscale
|
|
||||||
const base = code - 232;
|
|
||||||
const grey = base * 10 + 8;
|
|
||||||
return `rgb(${grey}, ${grey}, ${grey})`;
|
|
||||||
}
|
|
||||||
// shouldn't get here (under normal circumstances), but just in case
|
|
||||||
return "initial";
|
|
||||||
};
|
|
||||||
|
|
||||||
type styleKey = "fontWeight" | "textDecoration" | "color" | "backgroundColor" | "display";
|
|
||||||
const style: {
|
|
||||||
fontWeight?: string;
|
|
||||||
textDecoration?: string;
|
|
||||||
color?: string;
|
|
||||||
backgroundColor?: string;
|
|
||||||
display?: string;
|
|
||||||
} = {};
|
|
||||||
|
|
||||||
if (code === null || code === "0") {
|
|
||||||
return style;
|
|
||||||
}
|
|
||||||
|
|
||||||
const codeParts = code
|
|
||||||
.split(";")
|
|
||||||
.map((p) => parseInt(p))
|
|
||||||
.filter(
|
|
||||||
(p, i, arr) =>
|
|
||||||
// If the sequence is 38;5 (x256 foreground color) or 48;5 (x256 background color),
|
|
||||||
// filter out the 5 so the next codePart after {38,48} is the color code.
|
|
||||||
p != 5 || i == 0 || (arr[i - 1] != 38 && arr[i - 1] != 48),
|
|
||||||
);
|
|
||||||
|
|
||||||
let nextStyleKey: styleKey | null = null;
|
|
||||||
codeParts.forEach((codePart) => {
|
|
||||||
/* eslint-disable yoda */
|
|
||||||
if (nextStyleKey !== null) {
|
|
||||||
style[nextStyleKey] = ansi2rgb(codePart);
|
|
||||||
nextStyleKey = null;
|
|
||||||
}
|
|
||||||
// Decorations
|
|
||||||
else if (codePart == 1) {
|
|
||||||
style.fontWeight = "bold";
|
|
||||||
} else if (codePart == 4) {
|
|
||||||
style.textDecoration = "underline";
|
|
||||||
}
|
|
||||||
// Forground Color (x8)
|
|
||||||
else if (30 <= codePart && codePart < 38) {
|
|
||||||
if (COLOR_MAP_BRIGHT[codePart % 10]) {
|
|
||||||
style.color = COLOR_MAP_BRIGHT[codePart % 10];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Background Color (x8)
|
|
||||||
else if (40 <= codePart && codePart < 48) {
|
|
||||||
if (COLOR_MAP_DARK[codePart % 10]) {
|
|
||||||
style.backgroundColor = COLOR_MAP_DARK[codePart % 10];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Forground Color (x256)
|
|
||||||
else if (codePart == 38) {
|
|
||||||
nextStyleKey = "color";
|
|
||||||
}
|
|
||||||
// Background Color (x256)
|
|
||||||
else if (codePart == 48) {
|
|
||||||
nextStyleKey = "backgroundColor";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// If a background color is set, render this as an inline block element (instead of inline)
|
|
||||||
// so that the background between lines (at least those that don't wrap) is uninterrupted.
|
|
||||||
if (style.backgroundColor !== undefined) {
|
|
||||||
style.display = "inline-block";
|
|
||||||
}
|
|
||||||
return style;
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseOutputText(item: Output): React.ReactElement {
|
|
||||||
const parts = [];
|
|
||||||
// Some things, oddly, can cause item.text to not be a string (e.g. expr from the CLI), which
|
|
||||||
// causes .matchAll to throw. Ensure it's a string immediately
|
|
||||||
if (typeof item.text === "string") {
|
|
||||||
// eslint-disable-next-line no-control-regex
|
|
||||||
const ANSI_ESCAPE = new RegExp("\u{001b}\\[(?<code>.*?)m", "ug");
|
|
||||||
// Build a look-alike regex match to place at the front of the matches list
|
|
||||||
const INITIAL = {
|
|
||||||
0: "",
|
|
||||||
index: 0,
|
|
||||||
groups: { code: null },
|
|
||||||
};
|
|
||||||
const matches = [INITIAL, ...item.text.matchAll(ANSI_ESCAPE), null];
|
|
||||||
if (matches.length > 2) {
|
|
||||||
matches.slice(0, -1).forEach((m, i) => {
|
|
||||||
const n = matches[i + 1];
|
|
||||||
if (!m || m.index === undefined || m.groups === undefined) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const startIndex = m.index + m[0].length;
|
|
||||||
const stopIndex = n ? n.index : item.text.length;
|
|
||||||
const partText = item.text.slice(startIndex, stopIndex);
|
|
||||||
if (startIndex !== stopIndex) {
|
|
||||||
// Don't generate "empty" spans
|
|
||||||
parts.push({ code: m.groups.code, text: partText });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (parts.length === 0) {
|
|
||||||
// For example, if the string was empty or there were no escape sequence matches
|
|
||||||
parts.push({ code: null, text: item.text });
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
<Typography classes={{ root: lineClass(item.color) }} paragraph={false}>
|
|
||||||
{parts.map((part, index) => {
|
|
||||||
const spanStyle = ansiCodeStyle(part.code);
|
|
||||||
if (!_.isEmpty(spanStyle)) {
|
|
||||||
// Only wrap parts with spans if the calculated spanStyle is non-empty...
|
|
||||||
return (
|
|
||||||
<Typography key={index} paragraph={false} component="span" sx={spanStyle}>
|
|
||||||
{part.text}
|
|
||||||
</Typography>
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
// ... otherwise yield the unmodified, unwrapped part.
|
|
||||||
return part.text;
|
|
||||||
}
|
|
||||||
})}
|
|
||||||
</Typography>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@ -330,9 +112,7 @@ export function TerminalRoot({ terminal, router, player }: IProps): React.ReactE
|
|||||||
if (item instanceof Output)
|
if (item instanceof Output)
|
||||||
return (
|
return (
|
||||||
<ListItem key={i} classes={{ root: classes.nopadding }}>
|
<ListItem key={i} classes={{ root: classes.nopadding }}>
|
||||||
<Typography classes={{ root: lineClass(item.color) }} paragraph={false}>
|
<ANSIITypography text={item.text} color={item.color} />
|
||||||
{parseOutputText(item)}
|
|
||||||
</Typography>
|
|
||||||
</ListItem>
|
</ListItem>
|
||||||
);
|
);
|
||||||
if (item instanceof RawOutput)
|
if (item instanceof RawOutput)
|
||||||
|
@ -417,7 +417,7 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
|||||||
{
|
{
|
||||||
desc: (arr: number[][]): string => {
|
desc: (arr: number[][]): string => {
|
||||||
return [
|
return [
|
||||||
"Given the following array of array of numbers representing a list of",
|
"Given the following array of arrays of numbers representing a list of",
|
||||||
"intervals, merge all overlapping intervals.\n\n",
|
"intervals, merge all overlapping intervals.\n\n",
|
||||||
`[${convert2DArrayToString(arr)}]\n\n`,
|
`[${convert2DArrayToString(arr)}]\n\n`,
|
||||||
"Example:\n\n",
|
"Example:\n\n",
|
||||||
@ -1546,7 +1546,7 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
|||||||
return [
|
return [
|
||||||
"Lempel-Ziv (LZ) compression is a data compression technique which encodes data using references to",
|
"Lempel-Ziv (LZ) compression is a data compression technique which encodes data using references to",
|
||||||
"earlier parts of the data. In this variant of LZ, data is encoded in two types of chunk. Each chunk",
|
"earlier parts of the data. In this variant of LZ, data is encoded in two types of chunk. Each chunk",
|
||||||
"begins with a length L, encoded as a single ASCII digit from 1 - 9, followed by the chunk data,",
|
"begins with a length L, encoded as a single ASCII digit from 1 to 9, followed by the chunk data,",
|
||||||
"which is either:\n\n",
|
"which is either:\n\n",
|
||||||
"1. Exactly L characters, which are to be copied directly into the uncompressed data.\n",
|
"1. Exactly L characters, which are to be copied directly into the uncompressed data.\n",
|
||||||
"2. A reference to an earlier part of the uncompressed data. To do this, the length is followed",
|
"2. A reference to an earlier part of the uncompressed data. To do this, the length is followed",
|
||||||
@ -1581,7 +1581,7 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
|||||||
return [
|
return [
|
||||||
"Lempel-Ziv (LZ) compression is a data compression technique which encodes data using references to",
|
"Lempel-Ziv (LZ) compression is a data compression technique which encodes data using references to",
|
||||||
"earlier parts of the data. In this variant of LZ, data is encoded in two types of chunk. Each chunk",
|
"earlier parts of the data. In this variant of LZ, data is encoded in two types of chunk. Each chunk",
|
||||||
"begins with a length L, encoded as a single ASCII digit from 1 - 9, followed by the chunk data,",
|
"begins with a length L, encoded as a single ASCII digit from 1 to 9, followed by the chunk data,",
|
||||||
"which is either:\n\n",
|
"which is either:\n\n",
|
||||||
"1. Exactly L characters, which are to be copied directly into the uncompressed data.\n",
|
"1. Exactly L characters, which are to be copied directly into the uncompressed data.\n",
|
||||||
"2. A reference to an earlier part of the uncompressed data. To do this, the length is followed",
|
"2. A reference to an earlier part of the uncompressed data. To do this, the length is followed",
|
||||||
|
@ -58,11 +58,12 @@ export function InteractiveTutorialRoot(): React.ReactElement {
|
|||||||
const [language, setLanguage] = useState(Language.None);
|
const [language, setLanguage] = useState(Language.None);
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
|
|
||||||
const tutorialScriptName = {
|
const tutorialScriptExtension = {
|
||||||
[Language.None]: "n00dles.script",
|
[Language.None]: ".script",
|
||||||
[Language.NS1]: "n00dles.script",
|
[Language.NS1]: ".script",
|
||||||
[Language.NS2]: "n00dles.js",
|
[Language.NS2]: ".js",
|
||||||
}[language];
|
}[language];
|
||||||
|
const tutorialScriptName = `n00dles${tutorialScriptExtension}`;
|
||||||
|
|
||||||
const contents: { [number: string]: IContent | undefined } = {
|
const contents: { [number: string]: IContent | undefined } = {
|
||||||
[iTutorialSteps.Start as number]: {
|
[iTutorialSteps.Start as number]: {
|
||||||
@ -377,7 +378,9 @@ export function InteractiveTutorialRoot(): React.ReactElement {
|
|||||||
</Typography>
|
</Typography>
|
||||||
<Typography classes={{ root: classes.textfield }}>{"[home ~/]> nano"}</Typography>
|
<Typography classes={{ root: classes.textfield }}>{"[home ~/]> nano"}</Typography>
|
||||||
|
|
||||||
<Typography>Scripts must end with the .script extension. Let's make a script now by entering </Typography>
|
<Typography>
|
||||||
|
Scripts must end with the {tutorialScriptExtension} extension. Let's make a script now by entering{" "}
|
||||||
|
</Typography>
|
||||||
<Typography classes={{ root: classes.textfield }}>{`[home ~/]> nano ${tutorialScriptName}`}</Typography>
|
<Typography classes={{ root: classes.textfield }}>{`[home ~/]> nano ${tutorialScriptName}`}</Typography>
|
||||||
|
|
||||||
<Typography>
|
<Typography>
|
||||||
@ -457,7 +460,7 @@ export function InteractiveTutorialRoot(): React.ReactElement {
|
|||||||
<>
|
<>
|
||||||
<Typography>
|
<Typography>
|
||||||
Your script is now running! It will continuously run in the background and will automatically stop if the
|
Your script is now running! It will continuously run in the background and will automatically stop if the
|
||||||
code ever completes (the n00dles.script will never complete because it runs an infinite loop). <br />
|
code ever completes (the {tutorialScriptName} will never complete because it runs an infinite loop). <br />
|
||||||
<br />
|
<br />
|
||||||
These scripts can passively earn you income and hacking experience. Your scripts will also earn money and
|
These scripts can passively earn you income and hacking experience. Your scripts will also earn money and
|
||||||
experience while you are offline, although at a slightly slower rate. <br />
|
experience while you are offline, although at a slightly slower rate. <br />
|
||||||
|
235
src/ui/React/ANSIITypography.tsx
Normal file
235
src/ui/React/ANSIITypography.tsx
Normal file
@ -0,0 +1,235 @@
|
|||||||
|
import { Typography } from "@mui/material";
|
||||||
|
import React from "react";
|
||||||
|
import makeStyles from "@mui/styles/makeStyles";
|
||||||
|
import createStyles from "@mui/styles/createStyles";
|
||||||
|
import { Theme } from "@mui/material/styles";
|
||||||
|
import _ from "lodash";
|
||||||
|
|
||||||
|
// This particular eslint-disable is correct.
|
||||||
|
// In this super specific weird case we in fact do want a regex on an ANSII character.
|
||||||
|
// eslint-disable-next-line no-control-regex
|
||||||
|
const ANSI_ESCAPE = new RegExp("\u{001b}\\[(?<code>.*?)m", "ug");
|
||||||
|
|
||||||
|
const useStyles = makeStyles((theme: Theme) =>
|
||||||
|
createStyles({
|
||||||
|
success: {
|
||||||
|
whiteSpace: "pre-wrap",
|
||||||
|
overflowWrap: "anywhere",
|
||||||
|
margin: theme.spacing(0),
|
||||||
|
color: theme.colors.success,
|
||||||
|
},
|
||||||
|
error: {
|
||||||
|
whiteSpace: "pre-wrap",
|
||||||
|
overflowWrap: "anywhere",
|
||||||
|
margin: theme.spacing(0),
|
||||||
|
color: theme.palette.error.main,
|
||||||
|
},
|
||||||
|
primary: {
|
||||||
|
whiteSpace: "pre-wrap",
|
||||||
|
overflowWrap: "anywhere",
|
||||||
|
margin: theme.spacing(0),
|
||||||
|
color: theme.palette.primary.main,
|
||||||
|
},
|
||||||
|
info: {
|
||||||
|
whiteSpace: "pre-wrap",
|
||||||
|
overflowWrap: "anywhere",
|
||||||
|
margin: theme.spacing(0),
|
||||||
|
color: theme.palette.info.main,
|
||||||
|
},
|
||||||
|
warning: {
|
||||||
|
whiteSpace: "pre-wrap",
|
||||||
|
overflowWrap: "anywhere",
|
||||||
|
margin: theme.spacing(0),
|
||||||
|
color: theme.palette.warning.main,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
const lineClass = (classes: Record<string, string>, s: string): string => {
|
||||||
|
const lineClassMap: Record<string, string> = {
|
||||||
|
error: classes.error,
|
||||||
|
success: classes.success,
|
||||||
|
info: classes.info,
|
||||||
|
warn: classes.warning,
|
||||||
|
};
|
||||||
|
return lineClassMap[s] || classes.primary;
|
||||||
|
};
|
||||||
|
|
||||||
|
interface IProps {
|
||||||
|
text: string;
|
||||||
|
color: "primary" | "error" | "success" | "info" | "warn";
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ANSIITypography = React.memo((props: IProps): React.ReactElement => {
|
||||||
|
const classes = useStyles();
|
||||||
|
const parts = [];
|
||||||
|
|
||||||
|
// Build a look-alike regex match to place at the front of the matches list
|
||||||
|
const INITIAL = {
|
||||||
|
0: "",
|
||||||
|
index: 0,
|
||||||
|
groups: { code: null },
|
||||||
|
};
|
||||||
|
const matches = [INITIAL, ...props.text.matchAll(ANSI_ESCAPE), null];
|
||||||
|
if (matches.length > 2) {
|
||||||
|
matches.slice(0, -1).forEach((m, i) => {
|
||||||
|
const n = matches[i + 1];
|
||||||
|
if (!m || m.index === undefined || m.groups === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const startIndex = m.index + m[0].length;
|
||||||
|
const stopIndex = n ? n.index : props.text.length;
|
||||||
|
const partText = props.text.slice(startIndex, stopIndex);
|
||||||
|
if (startIndex !== stopIndex) {
|
||||||
|
// Don't generate "empty" spans
|
||||||
|
parts.push({ code: m.groups.code, text: partText });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (parts.length === 0) {
|
||||||
|
// For example, if the string was empty or there were no escape sequence matches
|
||||||
|
parts.push({ code: null, text: props.text });
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<Typography classes={{ root: lineClass(classes, props.color) }} paragraph={false}>
|
||||||
|
{parts.map((part, index) => {
|
||||||
|
const spanStyle = ansiCodeStyle(part.code);
|
||||||
|
if (!_.isEmpty(spanStyle)) {
|
||||||
|
// Only wrap parts with spans if the calculated spanStyle is non-empty...
|
||||||
|
return (
|
||||||
|
<Typography key={index} paragraph={false} component="span" sx={spanStyle}>
|
||||||
|
{part.text}
|
||||||
|
</Typography>
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// ... otherwise yield the unmodified, unwrapped part.
|
||||||
|
return part.text;
|
||||||
|
}
|
||||||
|
})}
|
||||||
|
</Typography>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
function ansiCodeStyle(code: string | null): Record<string, any> {
|
||||||
|
// The ANSI colors actually have the dark color set as default and require extra work to get
|
||||||
|
// bright colors. But these are rarely used or, if they are, are often re-mapped by the
|
||||||
|
// terminal emulator to brighter colors. So for foreground colors we use the bright color set
|
||||||
|
// and for background colors we use the dark color set. Of course, all colors are available
|
||||||
|
// via the longer ESC[n8;5;c] sequence (n={3,4}, c=color). Ideally, these 8-bit maps could
|
||||||
|
// be managed in the user preferences/theme.
|
||||||
|
const COLOR_MAP_BRIGHT: Record<number, string> = {
|
||||||
|
0: "#404040",
|
||||||
|
1: "#ff0000",
|
||||||
|
2: "#00ff00",
|
||||||
|
3: "#ffff00",
|
||||||
|
4: "#0000ff",
|
||||||
|
5: "#ff00ff",
|
||||||
|
6: "#00ffff",
|
||||||
|
7: "#ffffff",
|
||||||
|
};
|
||||||
|
const COLOR_MAP_DARK: Record<number, string> = {
|
||||||
|
0: "#000000",
|
||||||
|
1: "#800000",
|
||||||
|
2: "#008000",
|
||||||
|
3: "#808000",
|
||||||
|
4: "#000080",
|
||||||
|
5: "#800080",
|
||||||
|
6: "#008080",
|
||||||
|
7: "#c0c0c0",
|
||||||
|
};
|
||||||
|
|
||||||
|
const ansi2rgb = (code: number): string => {
|
||||||
|
/* eslint-disable yoda */
|
||||||
|
if (0 <= code && code < 8) {
|
||||||
|
// x8 RGB
|
||||||
|
return COLOR_MAP_BRIGHT[code];
|
||||||
|
}
|
||||||
|
if (8 <= code && code < 16) {
|
||||||
|
// x8 RGB - "High Intensity" (but here, actually the dark set)
|
||||||
|
return COLOR_MAP_DARK[code];
|
||||||
|
}
|
||||||
|
if (16 <= code && code < 232) {
|
||||||
|
// x216 RGB
|
||||||
|
const base = code - 16;
|
||||||
|
const ir = Math.floor(base / 36);
|
||||||
|
const ig = Math.floor((base % 36) / 6);
|
||||||
|
const ib = Math.floor((base % 6) / 1);
|
||||||
|
const r = ir <= 0 ? 0 : 55 + ir * 40;
|
||||||
|
const g = ig <= 0 ? 0 : 55 + ig * 40;
|
||||||
|
const b = ib <= 0 ? 0 : 55 + ib * 40;
|
||||||
|
return `rgb(${r}, ${g}, ${b})`;
|
||||||
|
}
|
||||||
|
if (232 <= code && code < 256) {
|
||||||
|
// x32 greyscale
|
||||||
|
const base = code - 232;
|
||||||
|
const grey = base * 10 + 8;
|
||||||
|
return `rgb(${grey}, ${grey}, ${grey})`;
|
||||||
|
}
|
||||||
|
// shouldn't get here (under normal circumstances), but just in case
|
||||||
|
return "initial";
|
||||||
|
};
|
||||||
|
|
||||||
|
type styleKey = "fontWeight" | "textDecoration" | "color" | "backgroundColor" | "display";
|
||||||
|
const style: {
|
||||||
|
fontWeight?: string;
|
||||||
|
textDecoration?: string;
|
||||||
|
color?: string;
|
||||||
|
backgroundColor?: string;
|
||||||
|
display?: string;
|
||||||
|
} = {};
|
||||||
|
|
||||||
|
if (code === null || code === "0") {
|
||||||
|
return style;
|
||||||
|
}
|
||||||
|
|
||||||
|
const codeParts = code
|
||||||
|
.split(";")
|
||||||
|
.map((p) => parseInt(p))
|
||||||
|
.filter(
|
||||||
|
(p, i, arr) =>
|
||||||
|
// If the sequence is 38;5 (x256 foreground color) or 48;5 (x256 background color),
|
||||||
|
// filter out the 5 so the next codePart after {38,48} is the color code.
|
||||||
|
p != 5 || i == 0 || (arr[i - 1] != 38 && arr[i - 1] != 48),
|
||||||
|
);
|
||||||
|
|
||||||
|
let nextStyleKey: styleKey | null = null;
|
||||||
|
codeParts.forEach((codePart) => {
|
||||||
|
/* eslint-disable yoda */
|
||||||
|
if (nextStyleKey !== null) {
|
||||||
|
style[nextStyleKey] = ansi2rgb(codePart);
|
||||||
|
nextStyleKey = null;
|
||||||
|
}
|
||||||
|
// Decorations
|
||||||
|
else if (codePart == 1) {
|
||||||
|
style.fontWeight = "bold";
|
||||||
|
} else if (codePart == 4) {
|
||||||
|
style.textDecoration = "underline";
|
||||||
|
}
|
||||||
|
// Forground Color (x8)
|
||||||
|
else if (30 <= codePart && codePart < 38) {
|
||||||
|
if (COLOR_MAP_BRIGHT[codePart % 10]) {
|
||||||
|
style.color = COLOR_MAP_BRIGHT[codePart % 10];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Background Color (x8)
|
||||||
|
else if (40 <= codePart && codePart < 48) {
|
||||||
|
if (COLOR_MAP_DARK[codePart % 10]) {
|
||||||
|
style.backgroundColor = COLOR_MAP_DARK[codePart % 10];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Forground Color (x256)
|
||||||
|
else if (codePart == 38) {
|
||||||
|
nextStyleKey = "color";
|
||||||
|
}
|
||||||
|
// Background Color (x256)
|
||||||
|
else if (codePart == 48) {
|
||||||
|
nextStyleKey = "backgroundColor";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// If a background color is set, render this as an inline block element (instead of inline)
|
||||||
|
// so that the background between lines (at least those that don't wrap) is uninterrupted.
|
||||||
|
if (style.backgroundColor !== undefined) {
|
||||||
|
style.display = "inline-block";
|
||||||
|
}
|
||||||
|
return style;
|
||||||
|
}
|
@ -19,6 +19,7 @@ import { findRunningScript } from "../../Script/ScriptHelpers";
|
|||||||
import { Player } from "../../Player";
|
import { Player } from "../../Player";
|
||||||
import { debounce } from "lodash";
|
import { debounce } from "lodash";
|
||||||
import { Settings } from "../../Settings/Settings";
|
import { Settings } from "../../Settings/Settings";
|
||||||
|
import { ANSIITypography } from "./ANSIITypography";
|
||||||
|
|
||||||
let layerCounter = 0;
|
let layerCounter = 0;
|
||||||
|
|
||||||
@ -185,20 +186,20 @@ function LogWindow(props: IProps): React.ReactElement {
|
|||||||
setMinimized(!minimized);
|
setMinimized(!minimized);
|
||||||
}
|
}
|
||||||
|
|
||||||
function lineColor(s: string): string {
|
function lineColor(s: string): "error" | "success" | "warn" | "info" | "primary" {
|
||||||
if (s.match(/(^\[[^\]]+\] )?ERROR/) || s.match(/(^\[[^\]]+\] )?FAIL/)) {
|
if (s.match(/(^\[[^\]]+\] )?ERROR/) || s.match(/(^\[[^\]]+\] )?FAIL/)) {
|
||||||
return Settings.theme.error;
|
return "error";
|
||||||
}
|
}
|
||||||
if (s.match(/(^\[[^\]]+\] )?SUCCESS/)) {
|
if (s.match(/(^\[[^\]]+\] )?SUCCESS/)) {
|
||||||
return Settings.theme.success;
|
return "success";
|
||||||
}
|
}
|
||||||
if (s.match(/(^\[[^\]]+\] )?WARN/)) {
|
if (s.match(/(^\[[^\]]+\] )?WARN/)) {
|
||||||
return Settings.theme.warning;
|
return "warn";
|
||||||
}
|
}
|
||||||
if (s.match(/(^\[[^\]]+\] )?INFO/)) {
|
if (s.match(/(^\[[^\]]+\] )?INFO/)) {
|
||||||
return Settings.theme.info;
|
return "info";
|
||||||
}
|
}
|
||||||
return Settings.theme.primary;
|
return "primary";
|
||||||
}
|
}
|
||||||
|
|
||||||
// And trigger fakeDrag when the window is resized
|
// And trigger fakeDrag when the window is resized
|
||||||
@ -319,10 +320,10 @@ function LogWindow(props: IProps): React.ReactElement {
|
|||||||
<span style={{ display: "flex", flexDirection: "column" }}>
|
<span style={{ display: "flex", flexDirection: "column" }}>
|
||||||
{script.logs.map(
|
{script.logs.map(
|
||||||
(line: string, i: number): JSX.Element => (
|
(line: string, i: number): JSX.Element => (
|
||||||
<Typography key={i} sx={{ color: lineColor(line) }}>
|
<React.Fragment key={i}>
|
||||||
{line}
|
<ANSIITypography text={line} color={lineColor(line)} />
|
||||||
<br />
|
<br />
|
||||||
</Typography>
|
</React.Fragment>
|
||||||
),
|
),
|
||||||
)}
|
)}
|
||||||
</span>
|
</span>
|
||||||
|
Loading…
Reference in New Issue
Block a user