diff --git a/src/app/components/common/text-window/index.tsx b/src/app/components/common/text-window/index.tsx index cf6ec2d..1c99298 100644 --- a/src/app/components/common/text-window/index.tsx +++ b/src/app/components/common/text-window/index.tsx @@ -15,6 +15,8 @@ interface TextWindowComponentProps { } interface TextWindowComponentState { + isVisible: boolean; + isCursorVisible: boolean; foreground: TextWindowColor; @@ -25,6 +27,8 @@ interface TextWindowComponentState { inputLines: BaseValue[]; outputLines: OutputChunk[]; + + title: string; } const inputColor: TextWindowColor = TextWindowColor.Gray; @@ -45,6 +49,8 @@ export class TextWindowComponent extends React.Component - - {this.state.outputLines.map((line, i) => [ - {line.text}, - line.appendNewLine ?
: null - ])} - -
this.inputDiv = inputDiv!}> - {this.state.inputBuffer} - + style={{ backgroundColor: EditorUtils.textWindowColorToCssColor(this.state.background) }} + > +
+ {this.state.title} +
+
+ {this.state.outputLines.map((line, i) => [ + {line.text}, + line.appendNewLine ?
: null + ])} + +
this.inputDiv = inputDiv!}> + {this.state.inputBuffer} + +
-
+ : null ); } @@ -171,6 +185,22 @@ export class TextWindowComponent extends React.Component this.executeClearMethod() }, + Hide: { execute: () => this.executeSetVisibility(false) }, Read: { execute: engine => this.executeReadMethod(engine, ValueKind.String) }, ReadNumber: { execute: engine => this.executeReadMethod(engine, ValueKind.Number) }, Write: { execute: engine => this.executeWriteMethod(engine, false) }, - WriteLine: { execute: engine => this.executeWriteMethod(engine, true) } + WriteLine: { execute: engine => this.executeWriteMethod(engine, true) }, + Pause: { execute: engine => this.executePause(engine) }, + PauseIfVisible: { execute: engine => this.executePauseIfVisible(engine) }, + PauseWithoutMessage: { execute: engine => this.executePauseWithoutMessage(engine) }, + Show: { execute: () => this.executeSetVisibility(true) } }; public readonly properties: { readonly [name: string]: LibraryPropertyInstance } = { ForegroundColor: { getter: this.getForegroundColor.bind(this), setter: this.setForegroundColor.bind(this) }, - BackgroundColor: { getter: this.getBackgroundColor.bind(this), setter: this.setBackgroundColor.bind(this) } + BackgroundColor: { getter: this.getBackgroundColor.bind(this), setter: this.setBackgroundColor.bind(this) }, + Title: { getter: this.getTitle.bind(this), setter: this.setTitle.bind(this) } }; public readonly events: { readonly [name: string]: LibraryEventInstance } = {}; diff --git a/src/strings/documentation.ts b/src/strings/documentation.ts index dfc5cd5..e2107b1 100644 --- a/src/strings/documentation.ts +++ b/src/strings/documentation.ts @@ -178,6 +178,13 @@ export module DocumentationResources { export const TextWindow_WriteLine_Data = "The string or number to be written to the text window."; export const TextWindow_ForegroundColor = "Gets or sets the foreground color of the text to be output in the text window."; export const TextWindow_BackgroundColor = "Gets or sets the background color of the text to be output in the text window."; + export const TextWindow_Title = "Gets or sets the title for the text window."; + export const TextWindow_Hide = "Hides the text window. Content is preserved when the window is shown again."; + export const TextWindow_Show = "Shows the text window and enables interactions with it."; + export const TextWindow_Clear = "Clears the text window."; + export const TextWindow_Pause = "Waits for user input before returning. Outputs a 'Press any key to continue...' message to the text window."; + export const TextWindow_PauseWithoutMessage = "Waits for user input before returning. Does not output a message."; + export const TextWindow_PauseIfVisible = "Waits for user input only when the text window is already open."; export const Turtle = "The Turtle provides Logo-like functionality to draw shapes by manipulating the properties of a pen and drawing primitives."; export const Turtle_Speed = "Specifies how fast the turtle should move. Valid values are 1 to 10. If Speed is set to 10, the turtle moves and rotates instantly."; export const Turtle_Angle = "Gets or sets the current angle of the turtle. While setting, this will turn the turtle instantly to the new angle."; diff --git a/tests/compiler/helpers.ts b/tests/compiler/helpers.ts index d319f95..b3ca157 100644 --- a/tests/compiler/helpers.ts +++ b/tests/compiler/helpers.ts @@ -101,6 +101,7 @@ export class TextWindowTestBuffer implements ITextWindowLibraryPlugin { private foreground: TextWindowColor = TextWindowColor.White; private background: TextWindowColor = TextWindowColor.Black; + private title: string = ""; public constructor( private readonly input: (string | number)[], @@ -111,7 +112,13 @@ export class TextWindowTestBuffer implements ITextWindowLibraryPlugin { // Nothing for now } - public checkInputBuffer(): BaseValue | undefined { + public clearOutput(): void {} + + public setVisibility(): void {} + + public getIsVisible(): boolean { return true; } + + public checkInputLines(): BaseValue | undefined { if (this.inputIndex < this.input.length) { const value = this.input[this.inputIndex++]; switch (typeof value) { @@ -124,6 +131,14 @@ export class TextWindowTestBuffer implements ITextWindowLibraryPlugin { return undefined; } + public checkInputBuffer(): string { + return "input"; + } + + public clearInputBuffer(): void { + + } + public writeText(value: string, appendNewLine: boolean): void { if (this.outputIndex < this.output.length) { this.currentPartialLine += value; @@ -149,6 +164,14 @@ export class TextWindowTestBuffer implements ITextWindowLibraryPlugin { return this.background; } + public getTitle(): string { + return this.title; + } + + public setTitle(title: string): void { + this.title = title; + } + public setBackgroundColor(color: TextWindowColor): void { this.background = color; } diff --git a/tests/compiler/runtime/libraries/text-window.ts b/tests/compiler/runtime/libraries/text-window.ts index 026c896..2c08ec9 100644 --- a/tests/compiler/runtime/libraries/text-window.ts +++ b/tests/compiler/runtime/libraries/text-window.ts @@ -147,6 +147,21 @@ TextWindow.WriteLine(TextWindow.ForegroundColor) ]); }); + it("sets title correctly", () => { + verifyRuntimeResult(` +TextWindow.WriteLine(TextWindow.Title) +TextWindow.Title = "My Program" +TextWindow.WriteLine(TextWindow.Title) +TextWindow.Title = 2 +TextWindow.WriteLine(TextWindow.Title)`, + [], + [ + "", + "My Program", + "2" + ]); + }); + it("writes partial chunks", () => { verifyRuntimeResult(` TextWindow.Write("1")