diff --git a/.vscode/settings.json b/.vscode/settings.json index b61eb26..1708396 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,6 +7,7 @@ "Landmarker", "onlineworkspace", "onnotice", + "Renderable", "solidjs", "unmaximize" ], diff --git a/instance/src/log.ts b/instance/src/log.ts index 0602401..1eb2a9f 100644 --- a/instance/src/log.ts +++ b/instance/src/log.ts @@ -7,7 +7,6 @@ export enum LogType { ERROR, SUCCESS, DEBUG, - RAW, } export enum LogMessageStyle { @@ -31,56 +30,20 @@ class Logger { return `${LogMessageStyle.EMPHASIZED}${message}${LogMessageStyle.RESET}`; } - rawLog(...message: (string | Uint8Array)[]) { - if (message.length === 0) { - throw new Error("log message is empty"); - } - - return this.logMessage(LogType.RAW, ...message); - } - info(...message: (string | Uint8Array)[]) { - if (this.level.length === 0) { - throw new Error("log level is empty"); - } - - if (message.length === 0) { - throw new Error("log message is empty"); - } - return this.logMessage(LogType.INFO, ...message); } success(...message: (string | Uint8Array)[]) { - if (this.level.length === 0) { - throw new Error("log level is empty"); - } - - if (message.length === 0) { - throw new Error("log message is empty"); - } - return this.logMessage(LogType.SUCCESS, ...message); } warning(...message: (string | Uint8Array)[]) { - if (this.level.length === 0) { - throw new Error("log level is empty"); - } - - if (message.length === 0) { - throw new Error("log message is empty"); - } - return this.logMessage(LogType.WARNING, ...message); } // biome-ignore lint/suspicious/noExplicitAny: can be of any type error(...message: any[]) { - if (message.length === 0) { - this.logMessage(LogType.ERROR, "log", new Error("log message is empty").stack); - } - this.logMessage(LogType.ERROR, ...message); return this; @@ -91,20 +54,19 @@ class Logger { // return this; // } - if (this.level.length === 0) { - throw new Error("log level is empty"); - } - - if (message.length === 0) { - throw new Error("log message is empty"); - } - return this.logMessage(LogType.DEBUG, ...message); } // biome-ignore lint/suspicious/noExplicitAny: the message can be of any type private logMessage(type: LogType, ...message: any[]): this { - this.writeMessage(type, message.length === 1 ? (typeof message[0] === "string" ? message[0] : util.inspect(message)) : util.inspect(message)); + this.writeMessage( + type, + message.length === 1 + ? typeof message[0] === "string" + ? message[0] + : util.inspect(message, { colors: false, compact: false }) + : util.inspect(message, { colors: false, compact: false }), + ); return this; } diff --git a/instance/src/systems/configuration.ts b/instance/src/systems/configuration.ts index 3d4a947..4545369 100644 --- a/instance/src/systems/configuration.ts +++ b/instance/src/systems/configuration.ts @@ -1,203 +1,204 @@ -import { promises as fs, existsSync as fsExistsSync, readFileSync as fsReadFileSync } from "node:fs"; -import path from "node:path"; -import type { Instance } from "../index.ts"; -import System from "../system.ts"; - -export enum WorkspacesFeatureFlags { - SlashCommands = "slash_commands", - ShootYourselfInTheFoot = "shoot_yourself_in_the_foot", - AllowUserSignups = "allow_user_signups", -} - -export const FEATURE_FLAG_DESCRIPTIONS = { - [WorkspacesFeatureFlags.SlashCommands]: "Enable the ability to use slash commands in the instance's console", - [WorkspacesFeatureFlags.ShootYourselfInTheFoot]: - "Allow administrators to alter settings / configuration options which may cause the instance to malfunction. (Only enable this if you are sure you know what you are doing!)", - [WorkspacesFeatureFlags.AllowUserSignups]: "Allow new users to create accounts from the instance user login page", -}; - -export default class ConfigurationSystem extends System { - isDevMode: boolean = true; - databases: { - postgres: { - user: string; - password: string; - host: string; - port: number; - database: string; - }; - }; - proxyUrl: string; - enabledFeatures: (WorkspacesFeatureFlags | string)[]; - signupRequirements: { - email: boolean; - twoFactorAuthentication: boolean; - passwordMinimumLength?: number; - passwordContains?: { - minimumUppercase?: number; - minimumLowercase?: number; - minimumNumbers?: number; - minimumSymbols?: number; - }; - }; - displayName: string; - mailServer: { - host: string; - port: number; - secure: boolean; - auth: { - user: string; - pass: string; - }; - }; - termsOfUse: { message: string; lastUpdated: number }; - defaultQuickShortcuts: string[]; - defaultApplications: { id: string; uri: string }[]; - caddyfile: string | undefined; - - constructor(instance: Instance) { - super("configuration", instance); - - this.enabledFeatures = [WorkspacesFeatureFlags.SlashCommands]; - this.databases = { - postgres: { - user: "postgres", - password: "postgres", - host: "localhost", - port: 5432, - database: "onlineworkspace_workspace", - }, - }; - if (process.env.POSTGRES_DATABASE_HOST) this.databases.postgres.host = process.env.POSTGRES_DATABASE_HOST; - this.proxyUrl = "https://localhost"; - this.signupRequirements = { - email: false, - twoFactorAuthentication: false, - passwordMinimumLength: 5, - passwordContains: { - minimumLowercase: 1, - minimumNumbers: 1, - minimumSymbols: 1, - minimumUppercase: 1, - }, - }; - this.displayName = "Workspace"; - this.mailServer = { - host: "smtp.example.com", - port: 587, - secure: true, - auth: { - user: "user", - pass: "password", - }, - }; - this.termsOfUse = { - message: `1. Acceptance of Terms - - By logging in, you agree to these rules. If you do not agree, please do not use the service. -2. Account Security - - You are the gatekeeper of your account. Keep your password private, as you are responsible for all activity that happens under your login. -3. Content Ownership - - What is yours remains yours. We claim no ownership over the files, photos, or data you upload to this instance. -4. Acceptable Use - - Do not use this space for anything illegal, malicious, or harmful. This includes uploading malware or attempting to disrupt the service for others. -5. Privacy and Access - - We value your privacy. We will not access your stored data unless it is strictly necessary for technical support or required by legal authorities. -6. Storage and Maintenance - - While we strive for 100% uptime, this service is provided "as is." We may occasionally perform maintenance that results in temporary downtime. -7. Personal Responsibility - - Hardware and software can fail. You agree to maintain your own external backups of any mission-critical data. We are not liable for data loss. -8. Termination - - We reserve the right to suspend or close accounts that violate these terms or compromise the security of the server. -9. Policy Updates - - These terms may change. If we make significant updates, we will post a notification within the app or send an email.`, - lastUpdated: Date.now(), - }; - this.defaultQuickShortcuts = ["uk.ewsgit.dashboard", "uk.ewsgit.store", "uk.ewsgit.settings", "uk.ewsgit.photos", "uk.ewsgit.files"]; - this.defaultApplications = [ - { id: "uk.ewsgit.dashboard", uri: "local:uk.ewsgit.dashboard" }, - { id: "uk.ewsgit.store", uri: "local:uk.ewsgit.store" }, - { id: "uk.ewsgit.settings", uri: "local:uk.ewsgit.settings" }, - { id: "uk.ewsgit.photos", uri: "local:uk.ewsgit.photos" }, - { id: "uk.ewsgit.files", uri: "local:uk.ewsgit.files" }, - ]; - this.caddyfile = "../Caddyfile"; - if (fsExistsSync(path.join(this.instance.sys.filesystem.AUTOINSTALL_PATH, "configuration.json"))) { - this.log.info("Auto-install configuration detected. Loading configuration from auto-install."); - - const autoInstallConfig = JSON.parse(fsReadFileSync(path.join(this.instance.sys.filesystem.AUTOINSTALL_PATH, "configuration.json")).toString()); - - for (const key of Object.keys(autoInstallConfig)) { - if (key in this) { - // @ts-ignore - this[key] = autoInstallConfig[key]; - } - } - } - } - - hasFeature(feature: WorkspacesFeatureFlags | string): boolean { - return !!this.enabledFeatures.find((f) => f === feature); - } - - async enableFeature(feature: WorkspacesFeatureFlags | string) { - if (!this.enabledFeatures.includes(feature)) this.enabledFeatures.push(feature); - - await this.saveConfiguration(); - - return true; - } - - async disableFeature(feature: WorkspacesFeatureFlags | string) { - this.enabledFeatures = this.enabledFeatures.filter((feat) => feat !== feature); - - await this.saveConfiguration(); - - return true; - } - - async saveConfiguration(): Promise { - const CONFIGURATION_FILE_PATH = path.join(this.instance.sys.filesystem.FS_ROOT, "configuration.json"); - - const allowedProperties = (Object.keys(this) as (keyof ConfigurationSystem)[]).filter((property) => { - return typeof this[property] !== "function" && property !== "instance" && property !== "id" && property !== "log"; - }); - - const configurationFileContents: Record = {}; - - for (const propertyKey of allowedProperties) { - console.log(propertyKey); - configurationFileContents[propertyKey] = this[propertyKey]; - } - - await fs.writeFile(CONFIGURATION_FILE_PATH, JSON.stringify(configurationFileContents, null, 2)); - - return true; - } - - override async startup(): Promise { - const CONFIGURATION_FILE_PATH = path.join(this.instance.sys.filesystem.FS_ROOT, "configuration.json"); - - if (!fsExistsSync(CONFIGURATION_FILE_PATH)) { - await this.saveConfiguration(); - } - - const configurationFile = JSON.parse((await fs.readFile(CONFIGURATION_FILE_PATH)).toString()); - - const allowedProperties = (Object.keys(this) as (keyof ConfigurationSystem)[]).filter((property) => { - return typeof this[property] !== "function" && property !== "instance" && property !== "id" && property !== "log"; - }); - - for (const propertyKey of allowedProperties) { - if (propertyKey in configurationFile) { - // @ts-expect-error We can ignore this as the properties which are read-only are already removed from the allowedProperties by this stage. - this[propertyKey] = configurationFile[propertyKey]; - } - } - - for (const feature of Object.keys(WorkspacesFeatureFlags) as (keyof typeof WorkspacesFeatureFlags)[]) { - this.log.info(`Feature ${feature} -> ${this.enabledFeatures.includes(WorkspacesFeatureFlags[feature])}`); - } - - return true; - } -} +import { promises as fs, existsSync as fsExistsSync, readFileSync as fsReadFileSync } from "node:fs"; +import path from "node:path"; +import type { Instance } from "../index.ts"; +import System from "../system.ts"; + +export enum WorkspacesFeatureFlags { + SlashCommands = "slash_commands", + ShootYourselfInTheFoot = "shoot_yourself_in_the_foot", + AllowUserSignups = "allow_user_signups", + TerminalGui = "terminal_gui", +} + +export const FEATURE_FLAG_DESCRIPTIONS = { + [WorkspacesFeatureFlags.SlashCommands]: "Enable the ability to use slash commands in the instance's console", + [WorkspacesFeatureFlags.ShootYourselfInTheFoot]: + "Allow administrators to alter settings / configuration options which may cause the instance to malfunction. (Only enable this if you are sure you know what you are doing!)", + [WorkspacesFeatureFlags.AllowUserSignups]: "Allow new users to create accounts from the instance user login page", +}; + +export default class ConfigurationSystem extends System { + isDevMode: boolean = true; + databases: { + postgres: { + user: string; + password: string; + host: string; + port: number; + database: string; + }; + }; + proxyUrl: string; + enabledFeatures: (WorkspacesFeatureFlags | string)[]; + signupRequirements: { + email: boolean; + twoFactorAuthentication: boolean; + passwordMinimumLength?: number; + passwordContains?: { + minimumUppercase?: number; + minimumLowercase?: number; + minimumNumbers?: number; + minimumSymbols?: number; + }; + }; + displayName: string; + mailServer: { + host: string; + port: number; + secure: boolean; + auth: { + user: string; + pass: string; + }; + }; + termsOfUse: { message: string; lastUpdated: number }; + defaultQuickShortcuts: string[]; + defaultApplications: { id: string; uri: string }[]; + caddyfile: string | undefined; + + constructor(instance: Instance) { + super("configuration", instance); + + this.enabledFeatures = [WorkspacesFeatureFlags.SlashCommands]; + this.databases = { + postgres: { + user: "postgres", + password: "postgres", + host: "localhost", + port: 5432, + database: "onlineworkspace_workspace", + }, + }; + if (process.env.POSTGRES_DATABASE_HOST) this.databases.postgres.host = process.env.POSTGRES_DATABASE_HOST; + this.proxyUrl = "https://localhost"; + this.signupRequirements = { + email: false, + twoFactorAuthentication: false, + passwordMinimumLength: 5, + passwordContains: { + minimumLowercase: 1, + minimumNumbers: 1, + minimumSymbols: 1, + minimumUppercase: 1, + }, + }; + this.displayName = "Workspace"; + this.mailServer = { + host: "smtp.example.com", + port: 587, + secure: true, + auth: { + user: "user", + pass: "password", + }, + }; + this.termsOfUse = { + message: `1. Acceptance of Terms + - By logging in, you agree to these rules. If you do not agree, please do not use the service. +2. Account Security + - You are the gatekeeper of your account. Keep your password private, as you are responsible for all activity that happens under your login. +3. Content Ownership + - What is yours remains yours. We claim no ownership over the files, photos, or data you upload to this instance. +4. Acceptable Use + - Do not use this space for anything illegal, malicious, or harmful. This includes uploading malware or attempting to disrupt the service for others. +5. Privacy and Access + - We value your privacy. We will not access your stored data unless it is strictly necessary for technical support or required by legal authorities. +6. Storage and Maintenance + - While we strive for 100% uptime, this service is provided "as is." We may occasionally perform maintenance that results in temporary downtime. +7. Personal Responsibility + - Hardware and software can fail. You agree to maintain your own external backups of any mission-critical data. We are not liable for data loss. +8. Termination + - We reserve the right to suspend or close accounts that violate these terms or compromise the security of the server. +9. Policy Updates + - These terms may change. If we make significant updates, we will post a notification within the app or send an email.`, + lastUpdated: Date.now(), + }; + this.defaultQuickShortcuts = ["uk.ewsgit.dashboard", "uk.ewsgit.store", "uk.ewsgit.settings", "uk.ewsgit.photos", "uk.ewsgit.files"]; + this.defaultApplications = [ + { id: "uk.ewsgit.dashboard", uri: "local:uk.ewsgit.dashboard" }, + { id: "uk.ewsgit.store", uri: "local:uk.ewsgit.store" }, + { id: "uk.ewsgit.settings", uri: "local:uk.ewsgit.settings" }, + { id: "uk.ewsgit.photos", uri: "local:uk.ewsgit.photos" }, + { id: "uk.ewsgit.files", uri: "local:uk.ewsgit.files" }, + ]; + this.caddyfile = "../Caddyfile"; + if (fsExistsSync(path.join(this.instance.sys.filesystem.AUTOINSTALL_PATH, "configuration.json"))) { + this.log.info("Auto-install configuration detected. Loading configuration from auto-install."); + + const autoInstallConfig = JSON.parse(fsReadFileSync(path.join(this.instance.sys.filesystem.AUTOINSTALL_PATH, "configuration.json")).toString()); + + for (const key of Object.keys(autoInstallConfig)) { + if (key in this) { + // @ts-ignore + this[key] = autoInstallConfig[key]; + } + } + } + } + + hasFeature(feature: WorkspacesFeatureFlags | string): boolean { + return !!this.enabledFeatures.find((f) => f === feature); + } + + async enableFeature(feature: WorkspacesFeatureFlags | string) { + if (!this.enabledFeatures.includes(feature)) this.enabledFeatures.push(feature); + + await this.saveConfiguration(); + + return true; + } + + async disableFeature(feature: WorkspacesFeatureFlags | string) { + this.enabledFeatures = this.enabledFeatures.filter((feat) => feat !== feature); + + await this.saveConfiguration(); + + return true; + } + + async saveConfiguration(): Promise { + const CONFIGURATION_FILE_PATH = path.join(this.instance.sys.filesystem.FS_ROOT, "configuration.json"); + + const allowedProperties = (Object.keys(this) as (keyof ConfigurationSystem)[]).filter((property) => { + return typeof this[property] !== "function" && property !== "instance" && property !== "id" && property !== "log"; + }); + + const configurationFileContents: Record = {}; + + for (const propertyKey of allowedProperties) { + console.log(propertyKey); + configurationFileContents[propertyKey] = this[propertyKey]; + } + + await fs.writeFile(CONFIGURATION_FILE_PATH, JSON.stringify(configurationFileContents, null, 2)); + + return true; + } + + override async startup(): Promise { + const CONFIGURATION_FILE_PATH = path.join(this.instance.sys.filesystem.FS_ROOT, "configuration.json"); + + if (!fsExistsSync(CONFIGURATION_FILE_PATH)) { + await this.saveConfiguration(); + } + + const configurationFile = JSON.parse((await fs.readFile(CONFIGURATION_FILE_PATH)).toString()); + + const allowedProperties = (Object.keys(this) as (keyof ConfigurationSystem)[]).filter((property) => { + return typeof this[property] !== "function" && property !== "instance" && property !== "id" && property !== "log"; + }); + + for (const propertyKey of allowedProperties) { + if (propertyKey in configurationFile) { + // @ts-expect-error We can ignore this as the properties which are read-only are already removed from the allowedProperties by this stage. + this[propertyKey] = configurationFile[propertyKey]; + } + } + + for (const feature of Object.keys(WorkspacesFeatureFlags) as (keyof typeof WorkspacesFeatureFlags)[]) { + this.log.info(`Feature ${feature} -> ${this.enabledFeatures.includes(WorkspacesFeatureFlags[feature])}`); + } + + return true; + } +} diff --git a/instance/src/systems/terminal.ts b/instance/src/systems/terminal.ts index 64c2d83..535ba9b 100644 --- a/instance/src/systems/terminal.ts +++ b/instance/src/systems/terminal.ts @@ -1,24 +1,24 @@ -import { BoxRenderable, CliRenderer, createCliRenderer, InputRenderable, RGBA, ScrollBoxRenderable, TextRenderable } from "@opentui/core"; +import { BoxRenderable, CliRenderer, ConsolePosition, createCliRenderer, InputRenderable, RGBA, ScrollBoxRenderable, TextRenderable } from "@opentui/core"; +import chalk from "chalk"; import type { Instance } from "../index.ts"; import { LogMessageStyle, LogType } from "../log.ts"; import System from "../system.ts"; -import yargs from "yargs"; +import { WorkspacesFeatureFlags } from "./configuration.ts"; const COMPACT_LOG_TYPE = false; -const BACKGROUND_COLOR = RGBA.fromInts(15, 15, 20, 255); -const BORDER_COLOR = RGBA.fromInts(60, 60, 75, 255); -const TEXT_COLOR = RGBA.fromInts(220, 220, 225, 255); -const EMPHASIZED_TEXT_COLOR = RGBA.fromInts(242, 106, 141, 255); -const MESSAGE_TYPE_COLORS: { [type in LogType]: RGBA } = { - [LogType.INFO]: RGBA.fromInts(58, 134, 255, 255), - [LogType.WARNING]: RGBA.fromInts(247, 184, 1, 255), - [LogType.ERROR]: RGBA.fromInts(240, 80, 80, 255), - [LogType.SUCCESS]: RGBA.fromInts(6, 214, 160, 255), - [LogType.DEBUG]: RGBA.fromInts(131, 56, 236, 255), - [LogType.RAW]: RGBA.fromInts(240, 80, 80, 255), +const BACKGROUND_COLOR: [number, number, number] = [15, 15, 20]; +const BORDER_COLOR: [number, number, number] = [60, 60, 75]; +const TEXT_COLOR: [number, number, number] = [220, 220, 225]; +const EMPHASIZED_TEXT_COLOR: [number, number, number] = [242, 106, 141]; +const MESSAGE_TYPE_COLORS: { [type in LogType]: [number, number, number] } = { + [LogType.INFO]: [58, 134, 255], + [LogType.WARNING]: [247, 184, 1], + [LogType.ERROR]: [240, 80, 80], + [LogType.SUCCESS]: [6, 214, 160], + [LogType.DEBUG]: [131, 56, 236], }; -const MESSAGE_LEVEL_COLOR = RGBA.fromInts(250, 163, 7, 255); +const MESSAGE_LEVEL_COLOR: [number, number, number] = [250, 163, 7]; export default class TerminalUISystem extends System { private renderer!: CliRenderer; @@ -32,25 +32,129 @@ export default class TerminalUISystem extends System { await super.startup(); + if (!this.instance.sys.configuration.hasFeature(WorkspacesFeatureFlags.TerminalGui)) { + function addLogMessage(log: { type: LogType; level: string; message: string }) { + let consoleLogOutput: string = ""; + const currentTypeColor = MESSAGE_TYPE_COLORS[log.type]; + + if (COMPACT_LOG_TYPE) { + consoleLogOutput += chalk.rgb(...currentTypeColor)("▌"); + } else { + let typeString = ""; + + switch (log.type) { + case LogType.INFO: + typeString = `${"INF"}`; + break; + case LogType.WARNING: + typeString = `${"WAR"}`; + break; + case LogType.ERROR: + typeString = `${"ERR"}`; + break; + case LogType.SUCCESS: + typeString = `${"SUC"}`; + break; + case LogType.DEBUG: + typeString = `${"DBG"}`; + break; + } + + consoleLogOutput += chalk.rgb(...currentTypeColor)(`${typeString} `); + } + + consoleLogOutput += chalk.rgb(...MESSAGE_LEVEL_COLOR)(`${log.level.padEnd(16)} `); + + const styledSegments = log.message.split("%"); + let currentMessageStyle: LogMessageStyle = LogMessageStyle.NORMAL; + let customColorDef: [number, number, number] | undefined; + for (let segmentIdx = 0; segmentIdx < styledSegments.length; segmentIdx++) { + const segmentContent = styledSegments[segmentIdx]; + + if (segmentContent === "") continue; + + switch (`%${segmentContent}%`) { + case LogMessageStyle.EMPHASIZED: { + currentMessageStyle = LogMessageStyle.EMPHASIZED; + continue; + } + case LogMessageStyle.NORMAL: { + currentMessageStyle = LogMessageStyle.NORMAL; + continue; + } + case LogMessageStyle.CUSTOM: { + currentMessageStyle = LogMessageStyle.CUSTOM; + continue; + } + case LogMessageStyle.END_CUSTOM: { + currentMessageStyle = LogMessageStyle.END_CUSTOM; + const colorValSegments = styledSegments[segmentIdx - 1].split(",").map((val) => Number(val)); + + if (colorValSegments.length === 4) { + customColorDef = [colorValSegments[0], colorValSegments[1], colorValSegments[2]]; + } + + continue; + } + case LogMessageStyle.RESET: + currentMessageStyle = LogMessageStyle.RESET; + continue; + } + + switch (currentMessageStyle) { + case LogMessageStyle.RESET: + case LogMessageStyle.NORMAL: + consoleLogOutput += chalk.rgb(...TEXT_COLOR)(segmentContent); + break; + case LogMessageStyle.EMPHASIZED: + consoleLogOutput += chalk.rgb(...EMPHASIZED_TEXT_COLOR)(segmentContent); + break; + case LogMessageStyle.END_CUSTOM: + if (!customColorDef) { + consoleLogOutput += chalk.bold.red(`UNABLE TO PARSE CUSTOM COLOR '${customColorDef}'`); + } else { + consoleLogOutput += chalk.rgb(...customColorDef)(segmentContent); + } + break; + } + + global.backup.console.log(consoleLogOutput.split("")); + } + } + + for (const message of this.instance.log.allLogHistory) { + addLogMessage(message); + } + + this.instance.log._internal_onNewMessageListeners.push((message) => { + addLogMessage(message); + }); + + return true; + } + const self = this; + function toRGBA(colorArray: [number, number, number]): RGBA { + return RGBA.fromInts(...colorArray, 255); + } this.renderer = await createCliRenderer({ exitOnCtrlC: true, consoleOptions: { - colorDefault: TEXT_COLOR, - backgroundColor: BACKGROUND_COLOR, - colorInfo: MESSAGE_TYPE_COLORS[LogType.INFO], - colorWarn: MESSAGE_TYPE_COLORS[LogType.WARNING], - colorError: MESSAGE_TYPE_COLORS[LogType.ERROR], - colorDebug: MESSAGE_TYPE_COLORS[LogType.DEBUG], + colorDefault: toRGBA(TEXT_COLOR), + colorInfo: toRGBA(MESSAGE_TYPE_COLORS[LogType.INFO]), + colorWarn: toRGBA(MESSAGE_TYPE_COLORS[LogType.WARNING]), + colorError: toRGBA(MESSAGE_TYPE_COLORS[LogType.ERROR]), + colorDebug: toRGBA(MESSAGE_TYPE_COLORS[LogType.DEBUG]), + position: ConsolePosition.TOP, }, - consoleMode: "console-overlay", + consoleMode: "disabled", onDestroy: async () => { await this.instance.shutdown(); }, }); - self.renderer.setBackgroundColor(BACKGROUND_COLOR); + self.renderer.setBackgroundColor(toRGBA(BACKGROUND_COLOR)); const logContainer = new ScrollBoxRenderable(self.renderer, { height: "100%", @@ -60,8 +164,8 @@ export default class TerminalUISystem extends System { contentOptions: { flexDirection: "column", }, - focusedBorderColor: BORDER_COLOR, - borderColor: BORDER_COLOR, + focusedBorderColor: toRGBA(BORDER_COLOR), + borderColor: toRGBA(BORDER_COLOR), stickyScroll: true, stickyStart: "bottom", }); @@ -76,7 +180,7 @@ export default class TerminalUISystem extends System { const currentTypeColor = MESSAGE_TYPE_COLORS[log.type]; if (COMPACT_LOG_TYPE) { - logEntry.add(new TextRenderable(self.renderer, { content: "▌", fg: currentTypeColor })); + logEntry.add(new TextRenderable(self.renderer, { content: "▌", fg: toRGBA(currentTypeColor) })); } else { let typeString = ""; @@ -96,15 +200,12 @@ export default class TerminalUISystem extends System { case LogType.DEBUG: typeString = `${"DBG"}`; break; - case LogType.RAW: - typeString = ` `; - break; } - logEntry.add(new TextRenderable(self.renderer, { content: `${typeString}`, fg: currentTypeColor, paddingRight: 1, flexShrink: 0 })); + logEntry.add(new TextRenderable(self.renderer, { content: `${typeString}`, fg: toRGBA(currentTypeColor), paddingRight: 1, flexShrink: 0 })); } - logEntry.add(new TextRenderable(self.renderer, { content: log.level.padEnd(16), fg: MESSAGE_LEVEL_COLOR, paddingRight: 1, flexShrink: 0 })); + logEntry.add(new TextRenderable(self.renderer, { content: log.level.padEnd(16), fg: toRGBA(MESSAGE_LEVEL_COLOR), paddingRight: 1, flexShrink: 0 })); const logMessageContainer = new BoxRenderable(self.renderer, { flexDirection: "row", flexWrap: "wrap" }); logEntry.add(logMessageContainer); @@ -148,13 +249,15 @@ export default class TerminalUISystem extends System { switch (currentMessageStyle) { case LogMessageStyle.RESET: case LogMessageStyle.NORMAL: - logMessageContainer.add(new TextRenderable(self.renderer, { content: segmentContent, fg: TEXT_COLOR, bg: BACKGROUND_COLOR })); + logMessageContainer.add(new TextRenderable(self.renderer, { content: segmentContent, fg: toRGBA(TEXT_COLOR), bg: toRGBA(BACKGROUND_COLOR) })); break; case LogMessageStyle.EMPHASIZED: - logMessageContainer.add(new TextRenderable(self.renderer, { content: segmentContent, fg: EMPHASIZED_TEXT_COLOR, bg: BACKGROUND_COLOR })); + logMessageContainer.add( + new TextRenderable(self.renderer, { content: segmentContent, fg: toRGBA(EMPHASIZED_TEXT_COLOR), bg: toRGBA(BACKGROUND_COLOR) }), + ); break; case LogMessageStyle.END_CUSTOM: - logMessageContainer.add(new TextRenderable(self.renderer, { content: segmentContent, fg: customColorDef, bg: BACKGROUND_COLOR })); + logMessageContainer.add(new TextRenderable(self.renderer, { content: segmentContent, fg: customColorDef, bg: toRGBA(BACKGROUND_COLOR) })); break; } } @@ -171,11 +274,8 @@ export default class TerminalUISystem extends System { self.renderer.root.add(logContainer); const commandInputContainer = new BoxRenderable(self.renderer, { - border: true, - borderStyle: "rounded", - height: 3, + height: 1, width: "100%", - borderColor: BORDER_COLOR, flexDirection: "row", gap: 1, }); @@ -187,6 +287,7 @@ export default class TerminalUISystem extends System { const promptMessage = new TextRenderable(self.renderer, { content: PROMPT_STRING, fg: RGBA.fromInts(242, 106, 141, 255), + marginLeft: 1, width: PROMPT_STRING.length, }); @@ -194,15 +295,15 @@ export default class TerminalUISystem extends System { const commandInput = new InputRenderable(self.renderer, { placeholder: "Click to start typing...", - width: "100%", - focusedBackgroundColor: BORDER_COLOR, + buffered: true, + flexGrow: 1, onKeyDown(e) { if (e.name === "return") { const trimmedContent = commandInput.plainText.trim(); if (!trimmedContent) return; self.instance.sys.consoleCommands.executeCommandFromString(trimmedContent); - commandInput.clear(); + commandInput.value = ""; } commandInput.requestRender(); }, @@ -214,7 +315,7 @@ export default class TerminalUISystem extends System { } override stop(): this { - this.renderer.destroy(); + this.renderer?.destroy?.(); return this; } diff --git a/instance/src/web/deno.json b/instance/src/web/deno.json new file mode 100644 index 0000000..774515b --- /dev/null +++ b/instance/src/web/deno.json @@ -0,0 +1,5 @@ +{ + "name": "@onlineworkspace/web", + "imports": {}, + "exports": {} +} diff --git a/instance/src/web/package.json b/instance/src/web/package.json index c79eb4b..6be0433 100644 --- a/instance/src/web/package.json +++ b/instance/src/web/package.json @@ -1,35 +1,34 @@ -{ - "name": "@onlineworkspace/workspace-instance-web", - "private": true, - "version": "0.0.0", - "type": "module", - "scripts": { - "dev": "vite --host", - "build": "vite build", - "preview": "vite preview" - }, - "dependencies": { - "@material-symbols/svg-700": "^0.42.3", - "@material/material-color-utilities": "^0.3.0", - "@ewsgit/uikit-solid": "workspace:*", - "@simplewebauthn/browser": "^13.3.0", - "@solid-primitives/media": "^2.3.5", - "@solid-primitives/refs": "^1.1.3", - "@solid-primitives/upload": "^0.1.4", - "@solidjs/router": "^0.16.1", - "@trpc/client": "^11.13.4", - "@trpc/server": "^11.13.4", - "@types/qrcode": "^1.5.6", - "clsx": "^2.1.1", - "qrcode": "^1.5.4", - "solid-devtools": "^0.34.5", - "solid-js": "^1.9.11", - "vite-plugin-compression2": "^2.5.3" - }, - "devDependencies": { - "typescript": "~5.9.3", - "vite": "^8.0.8", - "vite-plugin-solid": "^2.11.11", - "sass-embedded": "^1.98.0" - } -} \ No newline at end of file +{ + "name": "@onlineworkspace/workspace-instance-web", + "private": true, + "version": "0.0.0", + "type": "module", + "scripts": { + "dev": "vite --host", + "build": "vite build", + "preview": "vite preview" + }, + "dependencies": { + "@material-symbols/svg-700": "^0.42.3", + "@material/material-color-utilities": "^0.3.0", + "@simplewebauthn/browser": "^13.3.0", + "@solid-primitives/media": "^2.3.5", + "@solid-primitives/refs": "^1.1.3", + "@solid-primitives/upload": "^0.1.4", + "@solidjs/router": "^0.16.1", + "@trpc/client": "^11.13.4", + "@trpc/server": "^11.13.4", + "@types/qrcode": "^1.5.6", + "clsx": "^2.1.1", + "qrcode": "^1.5.4", + "solid-devtools": "^0.34.5", + "solid-js": "^1.9.11", + "vite-plugin-compression2": "^2.5.3" + }, + "devDependencies": { + "typescript": "~5.9.3", + "vite": "^8.0.8", + "vite-plugin-solid": "^2.11.11", + "sass-embedded": "^1.98.0" + } +} diff --git a/instance/src/web/src/App.tsx b/instance/src/web/src/App.tsx index d89a580..1524769 100644 --- a/instance/src/web/src/App.tsx +++ b/instance/src/web/src/App.tsx @@ -1,35 +1,35 @@ -import { UIKitRoot } from "@ewsgit/uikit-solid/src/index.tsx"; -// @ts-ignore -import ApplicationsRouter from "@onlineworkspace/workspaces-applications"; -import { Route, Router } from "@solidjs/router"; -import { type Component, lazy } from "solid-js"; -import styles from "./App.module.scss"; -import MissingApp from "./MissingApp.tsx"; -import AppIndex from "./pages/app/Index.tsx"; - -const App: Component = () => { - return ( - - - import("./pages/userSelect/Layout.tsx"))}> - import("./pages/userSelect/login/Login.tsx"))} /> - import("./pages/userSelect/signup/Signup.tsx"))} /> - import("./pages/userSelect/forgotPassword/ForgotPassword.tsx"))} /> - - import("./pages/app/AuthCheck.tsx"))}> - import("./pages/app/Layout.tsx"))}> - - - - - - import("./pages/notFound/Index.tsx"))} /> - - - import("./pages/notFound/Index.tsx"))} /> - - - ); -}; - -export default App; +import { UIKitRoot } from "@ewsgit/uikit-solid/src/index.tsx"; +// @ts-ignore +import ApplicationsRouter from "@onlineworkspace/workspaces-applications"; +import { Route, Router } from "@solidjs/router"; +import { type Component, lazy } from "solid-js"; +import styles from "./App.module.scss"; +import MissingApp from "./MissingApp.tsx"; +import AppIndex from "./pages/app/Index.tsx"; + +const App: Component = () => { + return ( + + + import("./pages/userSelect/Layout.tsx"))}> + import("./pages/userSelect/login/Login.tsx"))} /> + import("./pages/userSelect/signup/Signup.tsx"))} /> + import("./pages/userSelect/forgotPassword/ForgotPassword.tsx"))} /> + + import("./pages/app/AuthCheck.tsx"))}> + import("./pages/app/Layout.tsx"))}> + + + + + + import("./pages/notFound/Index.tsx"))} /> + + + import("./pages/notFound/Index.tsx"))} /> + + + ); +}; + +export default App; diff --git a/package.json b/package.json index b6509f6..4229745 100644 --- a/package.json +++ b/package.json @@ -13,5 +13,13 @@ }, "devDependencies": { "@biomejs/biome": "^2.4.14" - } + }, + "workspaces": [ + "instance/", + "instance/src/web/", + "applications/*/web/", + "applications/*/backend/", + "applications/*/electron/", + "uikit-solid" + ] }