working on timestamps and make netscript function highlight more specific.

This commit is contained in:
Olivier Gagnon 2021-11-11 10:07:16 -05:00
parent 1e7da4c610
commit 3f28b066b0
6 changed files with 20 additions and 15 deletions

@ -8,7 +8,7 @@ import { IMap } from "../types";
import { Terminal } from "../Terminal";
import { Generic_fromJSON, Generic_toJSON, Reviver } from "../utils/JSONReviver";
import { getTimestamp } from "../utils/helpers/getTimestamp";
import { formatTime } from "../utils/helpers/formatTime";
export class RunningScript {
// Script arguments
@ -74,8 +74,8 @@ export class RunningScript {
}
let logEntry = txt;
if (Settings.EnableTimestamps) {
logEntry = "[" + getTimestamp() + "] " + logEntry;
if (Settings.TimestampsFormat) {
logEntry = "[" + formatTime(Settings.TimestampsFormat) + "] " + logEntry;
}
this.logs.push(logEntry);

@ -354,7 +354,8 @@ export function Root(props: IProps): React.ReactElement {
.find((l: any) => l.id === "javascript")
.loader();
l.language.tokenizer.root.unshift(["ns", { token: "ns" }]);
for (const symbol of symbols) l.language.tokenizer.root.unshift([symbol, { token: "netscriptfunction" }]);
for (const symbol of symbols)
l.language.tokenizer.root.unshift(["[^a-zA-Z]" + symbol + "[^a-zA-Z]", { token: "netscriptfunction" }]);
const otherKeywords = ["let", "const", "var", "function"];
const otherKeyvars = ["true", "false", "null", "undefined"];
otherKeywords.forEach((k) => l.language.tokenizer.root.unshift([k, { token: "otherkeywords" }]));

@ -44,9 +44,9 @@ interface IDefaultSettings {
EnableBashHotkeys: boolean;
/**
* Enable timestamps
* Timestamps format
*/
EnableTimestamps: boolean;
TimestampsFormat: string;
/**
* Locale used for display numbers
@ -166,7 +166,7 @@ export const defaultSettings: IDefaultSettings = {
DisableHotkeys: false,
DisableTextEffects: false,
EnableBashHotkeys: false,
EnableTimestamps: false,
TimestampsFormat: "YYYY-MM-DD HH:MM:SS",
Locale: "en",
MaxLogCapacity: 50,
MaxPortCapacity: 50,
@ -225,7 +225,7 @@ export const Settings: ISettings & ISelfInitializer & ISelfLoading = {
DisableHotkeys: defaultSettings.DisableHotkeys,
DisableTextEffects: defaultSettings.DisableTextEffects,
EnableBashHotkeys: defaultSettings.EnableBashHotkeys,
EnableTimestamps: defaultSettings.EnableTimestamps,
TimestampsFormat: defaultSettings.TimestampsFormat,
Locale: "en",
MaxLogCapacity: defaultSettings.MaxLogCapacity,
MaxPortCapacity: defaultSettings.MaxPortCapacity,
@ -282,5 +282,6 @@ export const Settings: ISettings & ISelfInitializer & ISelfLoading = {
Object.assign(Settings.theme, save.theme);
delete save.theme;
Object.assign(Settings, save);
console.log(Settings.TimestampsFormat);
},
};

@ -4,7 +4,7 @@ import { Script } from "../Script/Script";
import { IPlayer } from "../PersonObjects/IPlayer";
import { IRouter } from "../ui/Router";
import { Settings } from "../Settings/Settings";
import { getTimestamp } from "../utils/helpers/getTimestamp";
import { formatTime } from "../utils/helpers/formatTime";
export class Output {
text: string;
@ -13,7 +13,7 @@ export class Output {
text: string,
color: "inherit" | "initial" | "primary" | "secondary" | "error" | "textPrimary" | "textSecondary" | undefined,
) {
if (Settings.EnableTimestamps) text = "[" + getTimestamp() + "] " + text;
if (Settings.TimestampsFormat) text = "[" + formatTime(Settings.TimestampsFormat) + "] " + text;
this.text = text;
this.color = color;
}
@ -22,10 +22,10 @@ export class Output {
export class RawOutput {
raw: React.ReactNode;
constructor(node: React.ReactNode) {
if (Settings.EnableTimestamps)
if (Settings.TimestampsFormat)
node = (
<>
[{getTimestamp()}] {node}
[{formatTime(Settings.TimestampsFormat)}] {node}
</>
);
this.raw = node;
@ -36,7 +36,7 @@ export class Link {
hostname: string;
dashes: string;
constructor(dashes: string, hostname: string) {
if (Settings.EnableTimestamps) dashes = "[" + getTimestamp() + "] " + dashes;
if (Settings.TimestampsFormat) dashes = "[" + formatTime(Settings.TimestampsFormat) + "] " + dashes;
this.hostname = hostname;
this.dashes = dashes;
}

@ -73,7 +73,7 @@ export function GameOptionsRoot(props: IProps): React.ReactElement {
const [disableASCIIArt, setDisableASCIIArt] = useState(Settings.DisableASCIIArt);
const [disableTextEffects, setDisableTextEffects] = useState(Settings.DisableTextEffects);
const [enableBashHotkeys, setEnableBashHotkeys] = useState(Settings.EnableBashHotkeys);
const [enableTimestamps, setEnableTimestamps] = useState(Settings.EnableTimestamps);
const [enableTimestamps, setEnableTimestamps] = useState(!!Settings.TimestampsFormat);
const [saveGameOnFileSave, setSaveGameOnFileSave] = useState(Settings.SaveGameOnFileSave);
const [locale, setLocale] = useState(Settings.Locale);
@ -156,7 +156,7 @@ export function GameOptionsRoot(props: IProps): React.ReactElement {
}
function handleEnableTimestampsChange(event: React.ChangeEvent<HTMLInputElement>): void {
setEnableTimestamps(event.target.checked);
Settings.EnableTimestamps = event.target.checked;
Settings.TimestampsFormat = event.target.checked ? "YYYY-MM-DD HH:MM:SS" : "";
}
function handleSaveGameOnFile(event: React.ChangeEvent<HTMLInputElement>): void {
setSaveGameOnFileSave(event.target.checked);

@ -0,0 +1,3 @@
export function formatTime(format: string): string {
return "";
}