* Add SendoutputToConsole boolean for better control of output

This commit is contained in:
Michael Van Canneyt 2025-03-24 10:31:07 +01:00
parent d019335646
commit 74fbb1f24f

View File

@ -94,6 +94,7 @@ Type
FHost : TWASIHost; FHost : TWASIHost;
FSendOutputToBrowser: Boolean; FSendOutputToBrowser: Boolean;
FConsoleChannel: TJSBroadcastChannel; FConsoleChannel: TJSBroadcastChannel;
FSendOutputToConsole: Boolean;
function GetAfterStart: TAfterStartEvent; function GetAfterStart: TAfterStartEvent;
function GetBeforeStart: TBeforeStartEvent; function GetBeforeStart: TBeforeStartEvent;
function GetcPredefinedConsoleInput: TStrings; function GetcPredefinedConsoleInput: TStrings;
@ -141,6 +142,8 @@ Type
Property BeforeStart : TBeforeStartEvent Read GetBeforeStart Write SetBeforeStart; Property BeforeStart : TBeforeStartEvent Read GetBeforeStart Write SetBeforeStart;
// Send output to browser window process? // Send output to browser window process?
Property SendOutputToBrowser : Boolean Read FSendOutputToBrowser Write FSendOutputToBrowser; Property SendOutputToBrowser : Boolean Read FSendOutputToBrowser Write FSendOutputToBrowser;
// Send output to console ?
Property SendOutputToConsole : Boolean Read FSendOutputToConsole Write FSendOutputToConsole;
// Default console input // Default console input
Property PredefinedConsoleInput : TStrings Read GetcPredefinedConsoleInput Write SetPredefinedConsoleInput; Property PredefinedConsoleInput : TStrings Read GetcPredefinedConsoleInput Write SetPredefinedConsoleInput;
// Called when reading from console (stdin). If not set, PredefinedConsoleinput is used. // Called when reading from console (stdin). If not set, PredefinedConsoleinput is used.
@ -636,6 +639,7 @@ begin
inherited Create(aOwner); inherited Create(aOwner);
FHost:=CreateHost; FHost:=CreateHost;
FConsoleChannel:=TJSBroadcastChannel.new(channelConsole); FConsoleChannel:=TJSBroadcastChannel.new(channelConsole);
FSendOutputToConsole:=true;
end; end;
destructor TWorkerWASIHostApplication.Destroy; destructor TWorkerWASIHostApplication.Destroy;
@ -673,6 +677,8 @@ end;
procedure TWorkerThreadRunnerApplication.HandleConsoleWrite(Sender: TObject; aOutput: string); procedure TWorkerThreadRunnerApplication.HandleConsoleWrite(Sender: TObject; aOutput: string);
begin begin
if SendOutputToConsole then
Writeln(aOutput);
if SendOutputToBrowser then if SendOutputToBrowser then
ConsoleChannel.postMessage(TWorkerConsoleCommand.Create(aOutput)); ConsoleChannel.postMessage(TWorkerConsoleCommand.Create(aOutput));
end; end;
@ -846,6 +852,8 @@ end;
procedure TWorkerThreadControllerApplication.HandleConsoleWrite(Sender: TObject; aOutput: string); procedure TWorkerThreadControllerApplication.HandleConsoleWrite(Sender: TObject; aOutput: string);
begin begin
if SendOutputToConsole then
Writeln(aOutput);
if SendOutputToBrowser then if SendOutputToBrowser then
FConsoleChannel.postMessage(TWorkerConsoleCommand.Create(aOutput,0)); FConsoleChannel.postMessage(TWorkerConsoleCommand.Create(aOutput,0));
end; end;