Changeset 1514

Show
Ignore:
Timestamp:
08/21/04 13:43:33 (4 years ago)
Author:
morris
Message:

nicer logging interface to console

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • WiredClient/trunk/WCConnection.m

    r1512 r1514  
    1 /* $Id: WCConnection.m,v 1.32 2004/08/19 13:10:21 morris Exp $ */ 
     1/* $Id: WCConnection.m,v 1.33 2004/08/21 11:43:33 morris Exp $ */ 
    22 
    33/* 
     
    766766         
    767767        // --- write to console 
    768         [_console print:[NSString stringWithFormat:@"%@\n", string] 
    769                           color:[NSColor blackColor]]; 
     768        [_console logOutput:string]; 
    770769         
    771770        // --- get data 
     
    788787- (void)receiveData:(NSData *)data { 
    789788        NSString        *string, *argument; 
    790         NSColor         *color; 
    791789        int                     message; 
    792790         
     
    800798        message = [[string substringToIndex:WCMessageLength] intValue]; 
    801799        argument = [string substringFromIndex:WCMessageLength + 1]; 
    802         color = [NSColor blueColor]; 
    803800         
    804801        switch(message) { 
     
    10781075                                object:[NSArray arrayWithObjects:self, argument, NULL]]; 
    10791076                        break; 
    1080                  
    1081                 default: 
    1082                         color = [NSColor redColor]; 
    1083                         break; 
    10841077        } 
    10851078         
    10861079        // --- log to console 
    1087         [_console print:[NSString stringWithFormat:@"%d %@\n", message, argument] color:color]; 
     1080        [_console logInput:string]; 
    10881081        [string release]; 
    10891082} 
  • WiredClient/trunk/WCConsole.h

    r944 r1514  
    1 /* $Id: WCConsole.h,v 1.1 2004/03/08 19:23:42 morris Exp $ */ 
     1/* $Id: WCConsole.h,v 1.2 2004/08/21 11:43:33 morris Exp $ */ 
    22 
    33/* 
     
    3838- (id)                                                  initWithConnection:(WCConnection *)connection; 
    3939 
    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; 
    4144 
    4245@end 
  • WiredClient/trunk/WCConsole.m

    r1499 r1514  
    1 /* $Id: WCConsole.m,v 1.8 2004/08/16 17:37:26 morris Exp $ */ 
     1/* $Id: WCConsole.m,v 1.9 2004/08/21 11:43:33 morris Exp $ */ 
    22 
    33/* 
     
    124124#pragma mark - 
    125125 
    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; 
    130129         
    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]; 
    134132 
    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
    140140 
    141         [string replaceOccurrencesOfString:WCGroupSeparator 
    142                         withString:@"\t" 
    143                         options:0 
    144                         range:NSMakeRange(0, [string length])]; 
    145141 
    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; 
    150158         
    151159        // --- create attributed string 
    152160        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]; 
    157168         
    158         // --- print 
    159         [[_consoleTextView textStorage] appendAttributedString:output]; 
    160  
    161169        // --- scroll with it 
    162170        [_consoleTextView scrollRangeToVisible:NSMakeRange([[_consoleTextView textStorage] length], 0)]; 
    163171         
    164         // --- release strings 
    165         [output release]; 
    166         [string release]; 
     172        // --- release 
     173        [attributedString release]; 
    167174} 
    168175