-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.m
48 lines (37 loc) · 1.27 KB
/
main.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
Mac OSX 10.6 Screen Recorder
by Daniel Dixon
assistance from Ben Spratling and Graham Booker
A fun exercise in Objective-C during the month of March 2010.
*/
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
#include "Console.h"
int main (int argc, char * argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[NSApplication sharedApplication];
// Class to manage user interaction
Console *console = [[Console alloc] initWithArgc:argc withArgv:argv];
if(console == nil) {
[pool release];
return 1;
}
// File reader for standard input
NSFileHandle *fileHandle = [[NSFileHandle fileHandleWithStandardInput] retain];
// Register console for notifications in a non-blocking manner
[[NSNotificationCenter defaultCenter] addObserver:console
selector:@selector(dataAvailable:)
name:NSFileHandleDataAvailableNotification
object:fileHandle];
// Wait for user input on the background thread
[fileHandle waitForDataInBackgroundAndNotify];
// Run the main event loop (application stays open)
[NSApp run];
// Proper memory management on closing
[[NSNotificationCenter defaultCenter] removeObserver:console];
[fileHandle closeFile];
[fileHandle release];
[console release];
[pool drain];
return 0;
}