Advertisement
Guest User

Untitled

a guest
Sep 17th, 2014
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. - (id)initWithWindow:(NSWindow *)window {
  2. self = [super initWithWindow:window];
  3. if (self) {
  4. // Initialization code here.
  5. }
  6. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(readPipe:) name:NSFileHandleReadCompletionNotification object:nil];
  7. return self;
  8. }
  9.  
  10.  
  11. -(void) watchFile:(NSNotification *)notification {
  12. NSString *path = [[notification userInfo] valueForKey:@"path"];
  13.  
  14. task = [[NSTask alloc] init];
  15. [task setLaunchPath:@"/usr/bin/compass"];
  16. [task setCurrentDirectoryPath:path];
  17.  
  18. NSArray *arguments;
  19. arguments = [NSArray arrayWithObjects: @"watch",@"--boring", nil];
  20. [task setArguments: arguments];
  21.  
  22. NSPipe *outPipe, *errPipe;
  23. outPipe = [NSPipe pipe];
  24. errPipe = [NSPipe pipe];
  25. [task setStandardOutput: outPipe];
  26. [task setStandardError: errPipe];
  27. [task setStandardInput: [NSPipe pipe]];
  28.  
  29. standardHandle = [outPipe fileHandleForReading];
  30. [standardHandle readInBackgroundAndNotify];
  31.  
  32. errorHandle = [errPipe fileHandleForReading];
  33. [errorHandle readInBackgroundAndNotify];
  34.  
  35. [self setSplitterPosition:0.0f];
  36.  
  37. [task launch];
  38.  
  39. }
  40.  
  41. -(void)readPipe:(NSNotification *)notification {
  42. NSLog(@"reading pipe");
  43. NSData *data;
  44. NSString *text;
  45.  
  46. if(!([notification object] == standardHandle) && !([notification object] == errorHandle)) {
  47. return;
  48. }
  49.  
  50. data = [[notification userInfo] objectForKey:NSFileHandleNotificationDataItem];
  51. text = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
  52.  
  53. if ([data length] == 0) {
  54. //error
  55. [self setSplitterPosition:150.0f];
  56. return;
  57. }
  58.  
  59. [terminalViewController updateTerminal:text];
  60. if(![text isEqualToString:@"n"]) [self growlAlert:text title:@"Compapp"];
  61.  
  62. [text release];
  63. if(task) [[notification object] readInBackgroundAndNotify];
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement