diff --git a/packages/project-editor/flow/components/actions/stream.tsx b/packages/project-editor/flow/components/actions/stream.tsx index 7f41dec3..5d897918 100644 --- a/packages/project-editor/flow/components/actions/stream.tsx +++ b/packages/project-editor/flow/components/actions/stream.tsx @@ -41,13 +41,10 @@ registerActionComponents("Dashboard Specific", [ streamValue instanceof Readable || streamValue instanceof Duplex ) { - let accData = ""; - context.startAsyncExecution(); streamValue.on("data", (data: Buffer) => { - accData += data.toString(); - context.propagateValue("data", accData); + context.propagateValue("data", data.toString()); }); let isDone = false; diff --git a/packages/project-editor/flow/components/widgets/dashboard/terminal.tsx b/packages/project-editor/flow/components/widgets/dashboard/terminal.tsx index 77aa6e07..80caf6bb 100644 --- a/packages/project-editor/flow/components/widgets/dashboard/terminal.tsx +++ b/packages/project-editor/flow/components/widgets/dashboard/terminal.tsx @@ -1,7 +1,7 @@ import React from "react"; import { Duplex, Readable } from "stream"; -import type { IDashboardComponentContext } from "eez-studio-types"; +import type { IDashboardComponentContext, ValueType } from "eez-studio-types"; import { registerClass, @@ -27,6 +27,7 @@ import { TERMINAL_WIDGET_ICON } from "project-editor/ui-components/icons"; class ExecutionState { data: string = ""; onData: ((value: string) => void) | undefined = undefined; + clear: (() => void) | undefined = undefined; } export class TerminalWidget extends Widget { @@ -53,6 +54,18 @@ export class TerminalWidget extends Widget { execute: (context: IDashboardComponentContext) => { Widget.classInfo.execute!(context); + const clearTerminal = context.getInputValue("clear"); + if (clearTerminal) { + context.clearInputValue("clear"); + + let executionState = + context.getComponentExecutionState(); + if (executionState && executionState.clear) { + executionState.clear(); + } + return; + } + const data = context.evalProperty("data"); if (typeof data === "string" && data.length > 0) { @@ -87,6 +100,18 @@ export class TerminalWidget extends Widget { } }); + getInputs() { + return [ + { + name: "clear", + type: "any" as ValueType, + isSequenceInput: false, + isOptionalInput: true + }, + ...super.getInputs() + ]; + } + getOutputs(): ComponentOutput[] { return [ { @@ -198,6 +223,9 @@ const TerminalElement = observer( executionState.onData = data => { this.terminal.write(data); }; + executionState.clear = () => { + this.terminal.clear(); + }; if (executionState.data) { this.terminal.write(executionState.data); executionState.data = "";