Skip to content

Commit

Permalink
#56 fix inline command result isn't inserted into document any more
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Bentele committed Apr 6, 2023
1 parent 92849f0 commit 772cc18
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 32 deletions.
1 change: 0 additions & 1 deletion Classes/FRAVariousPerformer.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
- (void)checkIfDocumentsHaveBeenUpdatedByAnotherApplication;
- (NSString *)performCommand:(NSString *)command;
- (void)performCommandAsynchronously:(NSString *)command;
- (void)asynchronousTaskCompleted;

- (BOOL)isChangingSyntaxDefinitionsProgrammatically;

Expand Down
45 changes: 14 additions & 31 deletions Classes/FRAVariousPerformer.m
Original file line number Diff line number Diff line change
Expand Up @@ -434,55 +434,38 @@ - (void)performCommandAsynchronously:(NSString *)command
[splitArray removeObjectAtIndex:0];
[asynchronousTask setArguments:splitArray];

[asynchronousTask setStandardOutput:[NSPipe pipe]];
[asynchronousTask setStandardError:[asynchronousTask standardOutput]];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(asynchronousDataReceived:) name:NSFileHandleReadCompletionNotification object:[[asynchronousTask standardOutput] fileHandleForReading]];
NSPipe *stdout = [NSPipe pipe];
[asynchronousTask setStandardOutput:stdout];
[asynchronousTask setStandardError:stdout];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(asynchronousTaskCompleted:) name:NSTaskDidTerminateNotification object:nil];

[[[asynchronousTask standardOutput] fileHandleForReading] readInBackgroundAndNotify];

[asynchronousTask launch];
}


- (void)asynchronousDataReceived:(NSNotification *)aNotification
{
NSData *data = [[aNotification userInfo] valueForKey:@"NSFileHandleNotificationDataItem"];

if ([data length]) {
NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
if (string != nil) {
[asynchronousTaskResult appendString:string];
}

[[[asynchronousTask standardOutput] fileHandleForReading] readInBackgroundAndNotify];
} else {
//[self asynchronousTaskCompleted];
}

}

- (void)asynchronousTaskCompleted:(NSNotification *)aNotification
{
[asynchronousTask waitUntilExit];
[self asynchronousTaskCompleted];
}


- (void)asynchronousTaskCompleted
{
[[NSNotificationCenter defaultCenter] removeObserver:self];

[asynchronousTask terminate];

NSData *data;
while ((data = [[[asynchronousTask standardOutput] fileHandleForReading] availableData]) && [data length]) {
NSData *data = [[[asynchronousTask standardOutput] fileHandleForReading] readDataToEndOfFile];
if ([data length]) {
NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
if (string != nil) {
[asynchronousTaskResult appendString:string];
}
NSLog(@"Append task result: %@", string);
} else {
// fallback to ASCII encoded string
NSString *string = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
if (string != nil) {
[asynchronousTaskResult appendString:string];
NSLog(@"Append task result: %@", string);
}
}
}

[[FRACommandsController sharedInstance] setCommandRunning:NO];
Expand Down

0 comments on commit 772cc18

Please sign in to comment.