Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 1 | (*
|
| 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 |
|
| 20 | unit Thrift.Console;
|
| 21 |
|
| 22 | interface
|
| 23 |
|
| 24 | uses
|
| 25 | StdCtrls;
|
| 26 |
|
| 27 | type
|
| 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 |
|
| 46 | function Console: TThriftConsole;
|
| 47 | procedure ChangeConsole( AConsole: TThriftConsole );
|
| 48 | procedure RestoreConsoleToDefault;
|
| 49 |
|
| 50 | implementation
|
| 51 |
|
| 52 | var
|
| 53 | FDefaultConsole : TThriftConsole;
|
| 54 | FConsole : TThriftConsole;
|
| 55 |
|
| 56 | function Console: TThriftConsole;
|
| 57 | begin
|
| 58 | Result := FConsole;
|
| 59 | end;
|
| 60 |
|
| 61 | { TThriftConsole }
|
| 62 |
|
| 63 | procedure TThriftConsole.Write(const S: string);
|
| 64 | begin
|
| 65 | System.Write( S );
|
| 66 | end;
|
| 67 |
|
| 68 | procedure TThriftConsole.WriteLine(const S: string);
|
| 69 | begin
|
| 70 | System.Writeln( S );
|
| 71 | end;
|
| 72 |
|
| 73 | procedure ChangeConsole( AConsole: TThriftConsole );
|
| 74 | begin
|
| 75 | FConsole := AConsole;
|
| 76 | end;
|
| 77 |
|
| 78 | procedure RestoreConsoleToDefault;
|
| 79 | begin
|
| 80 | FConsole := FDefaultConsole;
|
| 81 | end;
|
| 82 |
|
| 83 | { TGUIConsole }
|
| 84 |
|
| 85 | constructor TGUIConsole.Create( AMemo: TMemo);
|
| 86 | begin
|
| 87 | FMemo := AMemo;
|
| 88 | FLineBreak := True;
|
| 89 | end;
|
| 90 |
|
| 91 | procedure TGUIConsole.InternalWrite(const S: string; bWriteLine: Boolean);
|
| 92 | var
|
| 93 | idx : Integer;
|
| 94 | begin
|
| 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;
|
| 108 | end;
|
| 109 |
|
| 110 | procedure TGUIConsole.Write(const S: string);
|
| 111 | begin
|
| 112 | InternalWrite( S, False);
|
| 113 | end;
|
| 114 |
|
| 115 | procedure TGUIConsole.WriteLine(const S: string);
|
| 116 | begin
|
| 117 | InternalWrite( S, True);
|
| 118 | end;
|
| 119 |
|
| 120 | initialization
|
| 121 | begin
|
| 122 | FDefaultConsole := TThriftConsole.Create;
|
| 123 | FConsole := FDefaultConsole;
|
| 124 | end;
|
| 125 |
|
| 126 | finalization
|
| 127 | begin
|
| 128 | FDefaultConsole.Free;
|
| 129 | end;
|
| 130 |
|
| 131 | end.
|
| 132 |
|