From 48ba6d5263da9c41825b60f2d48ddf6bff372fab Mon Sep 17 00:00:00 2001 From: Megan Woodruff Date: Wed, 31 Oct 2018 14:14:57 -0700 Subject: [PATCH 1/2] Add title, clear, hide/show, and pause methods to TextWindow --- .../components/common/text-window/index.tsx | 79 +++++++++++++++---- .../components/common/text-window/style.css | 14 +++- src/compiler/runtime/libraries-metadata.ts | 15 +++- src/compiler/runtime/libraries/text-window.ts | 75 +++++++++++++++++- src/strings/documentation.ts | 7 ++ tests/compiler/helpers.ts | 25 +++++- .../compiler/runtime/libraries/text-window.ts | 15 ++++ 7 files changed, 208 insertions(+), 22 deletions(-) diff --git a/src/app/components/common/text-window/index.tsx b/src/app/components/common/text-window/index.tsx index cf6ec2d..4997e9f 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.appendOutput(exception @@ -85,24 +94,30 @@ 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 +186,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") From a17ffbf17e896a921741ac7ccb99a6db8c84c695 Mon Sep 17 00:00:00 2001 From: Megan Woodruff Date: Wed, 31 Oct 2018 14:20:01 -0700 Subject: [PATCH 2/2] Remove unnecessary focus --- src/app/components/common/text-window/index.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/app/components/common/text-window/index.tsx b/src/app/components/common/text-window/index.tsx index 4997e9f..1c99298 100644 --- a/src/app/components/common/text-window/index.tsx +++ b/src/app/components/common/text-window/index.tsx @@ -69,7 +69,6 @@ export class TextWindowComponent extends React.Component { this.appendOutput(exception