blob: a52eeb967db60d05a5270e7fe0cda386e7177c62 [file] [log] [blame]
Jens Geyerd5436f52014-10-03 19:50:38 +02001(*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 *)
19
20unit Thrift.Console;
21
22interface
23
24uses
25 StdCtrls;
26
27type
28 TThriftConsole = class
29 public
30 procedure Write( const S: string); virtual;
31 procedure WriteLine( const S: string); virtual;
32 end;
33
34 TGUIConsole = class( TThriftConsole )
35 private
36 FLineBreak : Boolean;
37 FMemo : TMemo;
38
39 procedure InternalWrite( const S: string; bWriteLine: Boolean);
40 public
41 procedure Write( const S: string); override;
42 procedure WriteLine( const S: string); override;
43 constructor Create( AMemo: TMemo);
44 end;
45
46function Console: TThriftConsole;
47procedure ChangeConsole( AConsole: TThriftConsole );
48procedure RestoreConsoleToDefault;
49
50implementation
51
52var
53 FDefaultConsole : TThriftConsole;
54 FConsole : TThriftConsole;
55
56function Console: TThriftConsole;
57begin
58 Result := FConsole;
59end;
60
61{ TThriftConsole }
62
63procedure TThriftConsole.Write(const S: string);
64begin
65 System.Write( S );
66end;
67
68procedure TThriftConsole.WriteLine(const S: string);
69begin
70 System.Writeln( S );
71end;
72
73procedure ChangeConsole( AConsole: TThriftConsole );
74begin
75 FConsole := AConsole;
76end;
77
78procedure RestoreConsoleToDefault;
79begin
80 FConsole := FDefaultConsole;
81end;
82
83{ TGUIConsole }
84
85constructor TGUIConsole.Create( AMemo: TMemo);
86begin
87 inherited Create;
88 FMemo := AMemo;
89 FLineBreak := True;
90end;
91
92procedure TGUIConsole.InternalWrite(const S: string; bWriteLine: Boolean);
93var
94 idx : Integer;
95begin
96 if FLineBreak then
97 begin
98 FMemo.Lines.Add( S );
99 end else
100 begin
101 idx := FMemo.Lines.Count - 1;
102 if idx < 0 then
103 begin
104 FMemo.Lines.Add( S );
105 end;
106 FMemo.Lines[idx] := FMemo.Lines[idx] + S;
107 end;
108 FLineBreak := bWriteLine;
109end;
110
111procedure TGUIConsole.Write(const S: string);
112begin
113 InternalWrite( S, False);
114end;
115
116procedure TGUIConsole.WriteLine(const S: string);
117begin
118 InternalWrite( S, True);
119end;
120
121initialization
122begin
123 FDefaultConsole := TThriftConsole.Create;
124 FConsole := FDefaultConsole;
125end;
126
127finalization
128begin
129 FDefaultConsole.Free;
130end;
131
132end.
133