Changeset 1514
- Timestamp:
- 08/21/04 13:43:33 (4 years ago)
- Files:
-
- WiredClient/trunk/WCConnection.m (modified) (5 diffs)
- WiredClient/trunk/WCConsole.h (modified) (2 diffs)
- WiredClient/trunk/WCConsole.m (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
WiredClient/trunk/WCConnection.m
r1512 r1514 1 /* $Id: WCConnection.m,v 1.3 2 2004/08/19 13:10:21morris Exp $ */1 /* $Id: WCConnection.m,v 1.33 2004/08/21 11:43:33 morris Exp $ */ 2 2 3 3 /* … … 766 766 767 767 // --- write to console 768 [_console print:[NSString stringWithFormat:@"%@\n", string] 769 color:[NSColor blackColor]]; 768 [_console logOutput:string]; 770 769 771 770 // --- get data … … 788 787 - (void)receiveData:(NSData *)data { 789 788 NSString *string, *argument; 790 NSColor *color;791 789 int message; 792 790 … … 800 798 message = [[string substringToIndex:WCMessageLength] intValue]; 801 799 argument = [string substringFromIndex:WCMessageLength + 1]; 802 color = [NSColor blueColor];803 800 804 801 switch(message) { … … 1078 1075 object:[NSArray arrayWithObjects:self, argument, NULL]]; 1079 1076 break; 1080 1081 default:1082 color = [NSColor redColor];1083 break;1084 1077 } 1085 1078 1086 1079 // --- log to console 1087 [_console print:[NSString stringWithFormat:@"%d %@\n", message, argument] color:color];1080 [_console logInput:string]; 1088 1081 [string release]; 1089 1082 } WiredClient/trunk/WCConsole.h
r944 r1514 1 /* $Id: WCConsole.h,v 1. 1 2004/03/08 19:23:42morris Exp $ */1 /* $Id: WCConsole.h,v 1.2 2004/08/21 11:43:33 morris Exp $ */ 2 2 3 3 /* … … 38 38 - (id) initWithConnection:(WCConnection *)connection; 39 39 40 - (void) print:(NSString *)string color:(NSColor *)color; 40 - (NSString *) stringByReplacingSeparators:(NSString *)string; 41 - (void) logInput:(NSString *)string; 42 - (void) logOutput:(NSString *)string; 43 - (void) log:(NSString *)string color:(NSColor *)color; 41 44 42 45 @end WiredClient/trunk/WCConsole.m
r1499 r1514 1 /* $Id: WCConsole.m,v 1. 8 2004/08/16 17:37:26morris Exp $ */1 /* $Id: WCConsole.m,v 1.9 2004/08/21 11:43:33 morris Exp $ */ 2 2 3 3 /* … … 124 124 #pragma mark - 125 125 126 - (void)print:(NSString *)input color:(NSColor *)color { 127 NSMutableString *string; 128 NSAttributedString *output; 129 NSDictionary *attributes; 126 - (NSString *)stringByReplacingSeparators:(NSString *)string { 127 NSMutableString *mutableString; 128 NSRange range; 130 129 131 // --- create mutable string 132 string = [[NSMutableString alloc] initWithCapacity:[input length]]; 133 [string appendString:input]; 130 range = NSMakeRange(0, [string length]); 131 mutableString = [string mutableCopy]; 134 132 135 // --- perform replacement 136 [string replaceOccurrencesOfString:WCFieldSeparator 137 withString:@"\t" 138 options:0 139 range:NSMakeRange(0, [string length])]; 133 [mutableString replaceOccurrencesOfString:WCFieldSeparator withString:@"\t" options:0 range:range]; 134 [mutableString replaceOccurrencesOfString:WCGroupSeparator withString:@"\t" options:0 range:range]; 135 [mutableString replaceOccurrencesOfString:WCRecordSeparator withString:@"\t" options:0 range:range]; 136 [mutableString appendString:@"\n"]; 137 138 return [mutableString autorelease]; 139 } 140 140 141 [string replaceOccurrencesOfString:WCGroupSeparator142 withString:@"\t"143 options:0144 range:NSMakeRange(0, [string length])];145 141 146 [string replaceOccurrencesOfString:WCRecordSeparator 147 withString:@"\t" 148 options:0 149 range:NSMakeRange(0, [string length])]; 142 143 - (void)logInput:(NSString *)string { 144 [self log:[self stringByReplacingSeparators:string] color:[NSColor blueColor]]; 145 } 146 147 148 149 - (void)logOutput:(NSString *)string { 150 [self log:[self stringByReplacingSeparators:string] color:[NSColor blackColor]]; 151 } 152 153 154 155 - (void)log:(NSString *)string color:(NSColor *)color { 156 NSDictionary *attributes; 157 NSAttributedString *attributedString; 150 158 151 159 // --- create attributed string 152 160 attributes = [NSDictionary dictionaryWithObjectsAndKeys: 153 color, NSForegroundColorAttributeName, 154 [NSFont fontWithName:@"Helvetica" size:11], NSFontAttributeName, 155 NULL]; 156 output = [[NSAttributedString alloc] initWithString:string attributes:attributes]; 161 color, NSForegroundColorAttributeName, 162 [NSFont fontWithName:@"Helvetica" size:11], NSFontAttributeName, 163 NULL]; 164 attributedString = [[NSAttributedString alloc] initWithString:string attributes:attributes]; 165 166 // --- print 167 [[_consoleTextView textStorage] appendAttributedString:attributedString]; 157 168 158 // --- print159 [[_consoleTextView textStorage] appendAttributedString:output];160 161 169 // --- scroll with it 162 170 [_consoleTextView scrollRangeToVisible:NSMakeRange([[_consoleTextView textStorage] length], 0)]; 163 171 164 // --- release strings 165 [output release]; 166 [string release]; 172 // --- release 173 [attributedString release]; 167 174 } 168 175
