blob: 324efc3a8ad0155bbc8b8597d4ae2eb5e69e6fa6 [file] [log] [blame]
Jake Farrell7ae13e12011-10-18 14:35:26 +00001(*
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 FMemo := AMemo;
88 FLineBreak := True;
89end;
90
91procedure TGUIConsole.InternalWrite(const S: string; bWriteLine: Boolean);
92var
93 idx : Integer;
94begin
95 if FLineBreak then
96 begin
97 FMemo.Lines.Add( S );
98 end else
99 begin
100 idx := FMemo.Lines.Count - 1;
101 if idx < 0 then
102 begin
103 FMemo.Lines.Add( S );
104 end;
105 FMemo.Lines[idx] := FMemo.Lines[idx] + S;
106 end;
107 FLineBreak := bWriteLine;
108end;
109
110procedure TGUIConsole.Write(const S: string);
111begin
112 InternalWrite( S, False);
113end;
114
115procedure TGUIConsole.WriteLine(const S: string);
116begin
117 InternalWrite( S, True);
118end;
119
120initialization
121begin
122 FDefaultConsole := TThriftConsole.Create;
123 FConsole := FDefaultConsole;
124end;
125
126finalization
127begin
128 FDefaultConsole.Free;
129end;
130
131end.
132