THRIFT-4473 Move Thrift.Console.pas out of the Library
Client: Delphi
Patch: Jens Geyer
This closes #1478
diff --git a/lib/delphi/test/ConsoleHelper.pas b/lib/delphi/test/ConsoleHelper.pas
new file mode 100644
index 0000000..0a8ddcf
--- /dev/null
+++ b/lib/delphi/test/ConsoleHelper.pas
@@ -0,0 +1,132 @@
+(*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *)
+
+unit ConsoleHelper;
+
+interface
+
+uses Classes;
+
+type
+ TThriftConsole = class
+ public
+ procedure Write( const S: string); virtual;
+ procedure WriteLine( const S: string); virtual;
+ end;
+
+ TGUIConsole = class( TThriftConsole )
+ private
+ FLineBreak : Boolean;
+ FMemo : TStrings;
+
+ procedure InternalWrite( const S: string; bWriteLine: Boolean);
+ public
+ procedure Write( const S: string); override;
+ procedure WriteLine( const S: string); override;
+ constructor Create( AMemo: TStrings);
+ end;
+
+function Console: TThriftConsole;
+procedure ChangeConsole( AConsole: TThriftConsole );
+procedure RestoreConsoleToDefault;
+
+implementation
+
+var
+ FDefaultConsole : TThriftConsole;
+ FConsole : TThriftConsole;
+
+function Console: TThriftConsole;
+begin
+ Result := FConsole;
+end;
+
+{ TThriftConsole }
+
+procedure TThriftConsole.Write(const S: string);
+begin
+ System.Write( S );
+end;
+
+procedure TThriftConsole.WriteLine(const S: string);
+begin
+ System.Writeln( S );
+end;
+
+procedure ChangeConsole( AConsole: TThriftConsole );
+begin
+ FConsole := AConsole;
+end;
+
+procedure RestoreConsoleToDefault;
+begin
+ FConsole := FDefaultConsole;
+end;
+
+{ TGUIConsole }
+
+constructor TGUIConsole.Create( AMemo: TStrings);
+begin
+ inherited Create;
+ FMemo := AMemo;
+ FLineBreak := True;
+end;
+
+procedure TGUIConsole.InternalWrite(const S: string; bWriteLine: Boolean);
+var
+ idx : Integer;
+begin
+ if FLineBreak then
+ begin
+ FMemo.Add( S );
+ end else
+ begin
+ idx := FMemo.Count - 1;
+ if idx < 0 then
+ FMemo.Add( S )
+ else
+ FMemo[idx] := FMemo[idx] + S;
+ end;
+ FLineBreak := bWriteLine;
+end;
+
+procedure TGUIConsole.Write(const S: string);
+begin
+ InternalWrite( S, False);
+end;
+
+procedure TGUIConsole.WriteLine(const S: string);
+begin
+ InternalWrite( S, True);
+end;
+
+initialization
+begin
+ FDefaultConsole := TThriftConsole.Create;
+ FConsole := FDefaultConsole;
+end;
+
+finalization
+begin
+ FDefaultConsole.Free;
+end;
+
+end.
+
+
diff --git a/lib/delphi/test/TestClient.pas b/lib/delphi/test/TestClient.pas
index be6b8b5..8c01080 100644
--- a/lib/delphi/test/TestClient.pas
+++ b/lib/delphi/test/TestClient.pas
@@ -37,6 +37,7 @@
DateUtils,
Generics.Collections,
TestConstants,
+ ConsoleHelper,
Thrift,
Thrift.Protocol.Compact,
Thrift.Protocol.JSON,
@@ -46,8 +47,7 @@
Thrift.Stream,
Thrift.Test,
Thrift.Utils,
- Thrift.Collections,
- Thrift.Console;
+ Thrift.Collections;
type
TThreadConsole = class
diff --git a/lib/delphi/test/TestServer.pas b/lib/delphi/test/TestServer.pas
index 97041d0..4400c34 100644
--- a/lib/delphi/test/TestServer.pas
+++ b/lib/delphi/test/TestServer.pas
@@ -29,7 +29,6 @@
uses
Windows, SysUtils,
Generics.Collections,
- Thrift.Console,
Thrift.Server,
Thrift.Transport,
Thrift.Transport.Pipes,
@@ -42,6 +41,7 @@
Thrift,
TestConstants,
TestServerEvents,
+ ConsoleHelper,
Contnrs;
type
diff --git a/lib/delphi/test/TestServerEvents.pas b/lib/delphi/test/TestServerEvents.pas
index 2e776d2..2208cd4 100644
--- a/lib/delphi/test/TestServerEvents.pas
+++ b/lib/delphi/test/TestServerEvents.pas
@@ -27,7 +27,7 @@
Thrift.Protocol,
Thrift.Transport,
Thrift.Server,
- Thrift.Console;
+ ConsoleHelper;
type
TRequestEventsImpl = class( TInterfacedObject, IRequestEvents)
diff --git a/lib/delphi/test/client.dpr b/lib/delphi/test/client.dpr
index f2e5250..1791c18 100644
--- a/lib/delphi/test/client.dpr
+++ b/lib/delphi/test/client.dpr
@@ -37,7 +37,6 @@
Thrift.Collections in '..\src\Thrift.Collections.pas',
Thrift.Server in '..\src\Thrift.Server.pas',
Thrift.Stream in '..\src\Thrift.Stream.pas',
- Thrift.Console in '..\src\Thrift.Console.pas',
Thrift.TypeRegistry in '..\src\Thrift.TypeRegistry.pas',
Thrift.Utils in '..\src\Thrift.Utils.pas';
diff --git a/lib/delphi/test/multiplexed/Multiplex.Server.Main.pas b/lib/delphi/test/multiplexed/Multiplex.Server.Main.pas
index 37f84bb..3860f5a 100644
--- a/lib/delphi/test/multiplexed/Multiplex.Server.Main.pas
+++ b/lib/delphi/test/multiplexed/Multiplex.Server.Main.pas
@@ -28,7 +28,6 @@
uses
Windows, SysUtils,
Generics.Collections,
- Thrift.Console,
Thrift.Server,
Thrift.Transport,
Thrift.Transport.Pipes,
@@ -41,6 +40,7 @@
Benchmark, // in gen-delphi folder
Aggr, // in gen-delphi folder
Multiplex.Test.Common,
+ ConsoleHelper,
Contnrs;
type
diff --git a/lib/delphi/test/multiplexed/Multiplex.Test.Client.dpr b/lib/delphi/test/multiplexed/Multiplex.Test.Client.dpr
index d6f93a1..14d6431 100644
--- a/lib/delphi/test/multiplexed/Multiplex.Test.Client.dpr
+++ b/lib/delphi/test/multiplexed/Multiplex.Test.Client.dpr
@@ -34,7 +34,6 @@
Thrift.Collections in '..\..\src\Thrift.Collections.pas',
Thrift.Server in '..\..\src\Thrift.Server.pas',
Thrift.Stream in '..\..\src\Thrift.Stream.pas',
- Thrift.Console in '..\..\src\Thrift.Console.pas',
Thrift.TypeRegistry in '..\..\src\Thrift.TypeRegistry.pas',
Thrift.Utils in '..\..\src\Thrift.Utils.pas';
diff --git a/lib/delphi/test/multiplexed/Multiplex.Test.Server.dpr b/lib/delphi/test/multiplexed/Multiplex.Test.Server.dpr
index 5550036..0e51a9c 100644
--- a/lib/delphi/test/multiplexed/Multiplex.Test.Server.dpr
+++ b/lib/delphi/test/multiplexed/Multiplex.Test.Server.dpr
@@ -24,6 +24,7 @@
uses
SysUtils,
Multiplex.Server.Main in 'Multiplex.Server.Main.pas',
+ ConsoleHelper in '..\ConsoleHelper.pas',
Thrift in '..\..\src\Thrift.pas',
Thrift.Socket in '..\..\src\Thrift.Socket.pas',
Thrift.Transport in '..\..\src\Thrift.Transport.pas',
@@ -33,7 +34,6 @@
Thrift.Processor.Multiplex in '..\..\src\Thrift.Processor.Multiplex.pas',
Thrift.Collections in '..\..\src\Thrift.Collections.pas',
Thrift.Server in '..\..\src\Thrift.Server.pas',
- Thrift.Console in '..\..\src\Thrift.Console.pas',
Thrift.Utils in '..\..\src\Thrift.Utils.pas',
Thrift.TypeRegistry in '..\..\src\Thrift.TypeRegistry.pas',
Thrift.Stream in '..\..\src\Thrift.Stream.pas';
diff --git a/lib/delphi/test/serializer/TestSerializer.dpr b/lib/delphi/test/serializer/TestSerializer.dpr
index 14be502..a621b7e 100644
--- a/lib/delphi/test/serializer/TestSerializer.dpr
+++ b/lib/delphi/test/serializer/TestSerializer.dpr
@@ -30,7 +30,6 @@
Thrift.Protocol.JSON in '..\..\src\Thrift.Protocol.JSON.pas',
Thrift.Collections in '..\..\src\Thrift.Collections.pas',
Thrift.Server in '..\..\src\Thrift.Server.pas',
- Thrift.Console in '..\..\src\Thrift.Console.pas',
Thrift.Utils in '..\..\src\Thrift.Utils.pas',
Thrift.Serializer in '..\..\src\Thrift.Serializer.pas',
Thrift.Stream in '..\..\src\Thrift.Stream.pas',
diff --git a/lib/delphi/test/server.dpr b/lib/delphi/test/server.dpr
index d87a331..9af8542 100644
--- a/lib/delphi/test/server.dpr
+++ b/lib/delphi/test/server.dpr
@@ -37,7 +37,6 @@
Thrift.Processor.Multiplex in '..\src\Thrift.Processor.Multiplex.pas',
Thrift.Collections in '..\src\Thrift.Collections.pas',
Thrift.Server in '..\src\Thrift.Server.pas',
- Thrift.Console in '..\src\Thrift.Console.pas',
Thrift.TypeRegistry in '..\src\Thrift.TypeRegistry.pas',
Thrift.Utils in '..\src\Thrift.Utils.pas',
Thrift.Stream in '..\src\Thrift.Stream.pas';
diff --git a/lib/delphi/test/skip/skiptest_version1.dpr b/lib/delphi/test/skip/skiptest_version1.dpr
index 40d025f..219db6d 100644
--- a/lib/delphi/test/skip/skiptest_version1.dpr
+++ b/lib/delphi/test/skip/skiptest_version1.dpr
@@ -31,7 +31,6 @@
Thrift.Protocol.JSON in '..\..\src\Thrift.Protocol.JSON.pas',
Thrift.Collections in '..\..\src\Thrift.Collections.pas',
Thrift.Server in '..\..\src\Thrift.Server.pas',
- Thrift.Console in '..\..\src\Thrift.Console.pas',
Thrift.Utils in '..\..\src\Thrift.Utils.pas',
Thrift.TypeRegistry in '..\..\src\Thrift.TypeRegistry.pas',
Thrift.Stream in '..\..\src\Thrift.Stream.pas';
diff --git a/lib/delphi/test/skip/skiptest_version2.dpr b/lib/delphi/test/skip/skiptest_version2.dpr
index 9cb6ff6..e0c3111 100644
--- a/lib/delphi/test/skip/skiptest_version2.dpr
+++ b/lib/delphi/test/skip/skiptest_version2.dpr
@@ -31,7 +31,6 @@
Thrift.Protocol.JSON in '..\..\src\Thrift.Protocol.JSON.pas',
Thrift.Collections in '..\..\src\Thrift.Collections.pas',
Thrift.Server in '..\..\src\Thrift.Server.pas',
- Thrift.Console in '..\..\src\Thrift.Console.pas',
Thrift.Utils in '..\..\src\Thrift.Utils.pas',
Thrift.TypeRegistry in '..\..\src\Thrift.TypeRegistry.pas',
Thrift.Stream in '..\..\src\Thrift.Stream.pas';
diff --git a/lib/delphi/test/typeregistry/TestTypeRegistry.dpr b/lib/delphi/test/typeregistry/TestTypeRegistry.dpr
index 3a77aae..3a1fd2b 100644
--- a/lib/delphi/test/typeregistry/TestTypeRegistry.dpr
+++ b/lib/delphi/test/typeregistry/TestTypeRegistry.dpr
@@ -30,7 +30,6 @@
Thrift.Protocol.JSON in '..\..\src\Thrift.Protocol.JSON.pas',
Thrift.Collections in '..\..\src\Thrift.Collections.pas',
Thrift.Server in '..\..\src\Thrift.Server.pas',
- Thrift.Console in '..\..\src\Thrift.Console.pas',
Thrift.Utils in '..\..\src\Thrift.Utils.pas',
Thrift.Serializer in '..\..\src\Thrift.Serializer.pas',
Thrift.Stream in '..\..\src\Thrift.Stream.pas',