diff --git a/src/application/State/Code/ApplicationCode.ts b/src/application/State/Code/ApplicationCode.ts index b39de706..293f5fcb 100644 --- a/src/application/State/Code/ApplicationCode.ts +++ b/src/application/State/Code/ApplicationCode.ts @@ -1,4 +1,4 @@ -import { CodeBuilder } from './CodeBuilder'; +import { UserScriptGenerator } from './UserScriptGenerator'; import { IUserSelection } from './../Selection/IUserSelection'; import { Signal } from '@/infrastructure/Events/Signal'; import { IApplicationCode } from './IApplicationCode'; @@ -8,12 +8,12 @@ export class ApplicationCode implements IApplicationCode { public readonly changed = new Signal(); public current: string; - private readonly codeBuilder: CodeBuilder; + private readonly generator: UserScriptGenerator; constructor(userSelection: IUserSelection, private readonly version: string) { if (!userSelection) { throw new Error('userSelection is null or undefined'); } if (!version) { throw new Error('version is null or undefined'); } - this.codeBuilder = new CodeBuilder(); + this.generator = new UserScriptGenerator(); this.setCode(userSelection.selectedScripts); userSelection.changed.on((scripts) => { this.setCode(scripts); @@ -21,7 +21,7 @@ export class ApplicationCode implements IApplicationCode { } private setCode(scripts: ReadonlyArray) { - this.current = this.codeBuilder.buildCode(scripts, this.version); + this.current = scripts.length === 0 ? '' : this.generator.buildCode(scripts, this.version); this.changed.notify(this.current); } } diff --git a/src/application/State/Code/CodeBuilder.ts b/src/application/State/Code/CodeBuilder.ts index 0fbde570..aa416843 100644 --- a/src/application/State/Code/CodeBuilder.ts +++ b/src/application/State/Code/CodeBuilder.ts @@ -1,27 +1,51 @@ -import { AdminRightsFunctionRenderer } from './Renderer/AdminRightsFunctionRenderer'; -import { AsciiArtRenderer } from './Renderer/AsciiArtRenderer'; -import { FunctionRenderer } from './Renderer/FunctionRenderer'; -import { Script } from '@/domain/Script'; +const NewLine = '\n'; +const TotalFunctionSeparatorChars = 58; export class CodeBuilder { - private readonly functionRenderer: FunctionRenderer; - private readonly adminRightsFunctionRenderer: AdminRightsFunctionRenderer; - private readonly asciiArtRenderer: AsciiArtRenderer; + private readonly lines = new Array(); - public constructor() { - this.functionRenderer = new FunctionRenderer(); - this.adminRightsFunctionRenderer = new AdminRightsFunctionRenderer(); - this.asciiArtRenderer = new AsciiArtRenderer(); + public appendLine(code?: string): CodeBuilder { + this.lines.push(code); + return this; } - public buildCode(scripts: ReadonlyArray