Skip to content

Commit

Permalink
Terminal widget clear input and CollectStream fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Nov 12, 2024
1 parent 760af24 commit 9d30da0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
5 changes: 1 addition & 4 deletions packages/project-editor/flow/components/actions/stream.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 {
Expand All @@ -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<ExecutionState>();
if (executionState && executionState.clear) {
executionState.clear();
}
return;
}

const data = context.evalProperty("data");

if (typeof data === "string" && data.length > 0) {
Expand Down Expand Up @@ -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 [
{
Expand Down Expand Up @@ -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 = "";
Expand Down

0 comments on commit 9d30da0

Please sign in to comment.