If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
I have a job to port an application(from the command line) that requires continuous input from the user. Basically this is the equivalent of using NSTask with Pico. I've looked at Apple's moriarty example. So how would the example need to be changed to handle something like Pico?
//declared in the header
NSFileHandle *readHandle;
NSFileHandle *writeHandle;
//declared in the implementation
- (IBAction)openFileForReading:(NSString *)fileName
{
NSTask *task = [[NStask alloc] init];
NSPipe *readPipe = [[NSPipe alloc] init];
NSPipe *outPipe = [[NSPipe alloc] init];
[task setArguments:[NSArray arrayWithObject:file]];
[task setLaunchPath:@"/usr/bin/pico"];
[task setStandardInput:writePipe];
[task setStandardOutput:readPipe];
[task launch];
readHandle = [readPipe fileHandleForReading];
writeHandle = [writePipe fileHandleForWriting];
NSData *data = [readHandle readDataToEndOfFile];
//display this data appropriately in an NSTextView or something
}
//data should probably be the data form of an NSString
//how do you add stuff like control-X to an NSString? Hmmm...
- (void)writeUserInputData:(NSData *)data
{
[writeHandle writeData:data];
//every time the user types something, the display needs to be updated
NSData *data = [readHandle readDataToEndOfFile];
//display this data appropriately in an NSTextView or something
}
This is just something I threw together in SimpleText (stupid OS 9 machine). No proper memory management or any of that stuff - but it might work.
That might work for a program that continually reads stdin and writes stdout, but it won't work for pico -- pico requires actual terminal emulation, as it draws characters at arbitrary coordinates, allows cursor repositioning, etc.
Thanks for the replies, but I don't see how your example will continuously read and write input/output. Won't there have to be a timer or thread of some sort?