| Line 17... |
Line 17... |
| 17 |
// high water-mark of the buffer - it's [length - x] where x is the smallest possible size to be flushed before a new string will be split.
|
17 |
// high water-mark of the buffer - it's [length - x] where x is the smallest possible size to be flushed before a new string will be split.
|
| 18 |
#define writeBufferHighWaterMark (DEFAULT_WRITE_BUFFER_SIZE-4096)
|
18 |
#define writeBufferHighWaterMark (DEFAULT_WRITE_BUFFER_SIZE-4096)
|
| 19 |
// low water-mark of the buffer - if less than the water mark is available then the buffer will be flushed
|
19 |
// low water-mark of the buffer - if less than the water mark is available then the buffer will be flushed
|
| 20 |
#define writeBufferLowWaterMark 2048
|
20 |
#define writeBufferLowWaterMark 2048
|
| 21 |
|
21 |
|
| 22 |
|
- |
|
| 23 |
// FIXME: those colors should become configurable
|
22 |
// class-level colors
|
| 24 |
#define outputColor [NSColor colorWithCalibratedRed: 0.0 green: 0.0 blue: 0.5 alpha: 1.0]
|
23 |
static NSColor *outputColor, *promptColor, *inputColor;
|
| 25 |
#define promptColor [NSColor colorWithCalibratedRed: 0.5 green: 0.0 blue: 0.5 alpha: 1.0]
|
- |
|
| 26 |
#define inputColor [NSColor colorWithCalibratedRed: 0.0 green: 0.0 blue: 0.0 alpha: 1.0]
|
- |
|
| 27 |
|
- |
|
| 28 |
|
24 |
|
| 29 |
@implementation RConsoleWinCtrl
|
25 |
@implementation RConsoleWinCtrl
|
| 30 |
|
26 |
|
| 31 |
#pragma mark --- Initialization ---
|
27 |
#pragma mark --- Initialization ---
|
| 32 |
|
28 |
|
| - |
|
29 |
+ (void) initialize
|
| - |
|
30 |
{
|
| - |
|
31 |
NSLog(@"RConsoleWinCtrl.initialize (allocate default colors)");
|
| - |
|
32 |
outputColor = [[NSColor colorWithCalibratedRed: 0.0 green: 0.0 blue: 0.5 alpha: 1.0] retain];
|
| - |
|
33 |
promptColor = [[NSColor colorWithCalibratedRed: 0.5 green: 0.0 blue: 0.5 alpha: 1.0] retain];
|
| - |
|
34 |
inputColor = [[NSColor colorWithCalibratedRed: 0.0 green: 0.0 blue: 0.0 alpha: 1.0] retain];
|
| - |
|
35 |
}
|
| - |
|
36 |
|
| 33 |
- (id)initWithWindowNibName:(NSString *)windowNibName
|
37 |
- (id)initWithWindowNibName:(NSString *)windowNibName
|
| 34 |
{
|
38 |
{
|
| 35 |
self = [super initWithWindowNibName:windowNibName];
|
39 |
self = [super initWithWindowNibName:windowNibName];
|
| 36 |
if (self) {
|
40 |
if (self) {
|
| 37 |
outputPosition = promptPosition = committedLength = 0;
|
41 |
outputPosition = promptPosition = committedLength = 0;
|
| Line 48... |
Line 52... |
| 48 |
hist = [[History alloc] init];
|
52 |
hist = [[History alloc] init];
|
| 49 |
|
53 |
|
| 50 |
currentFontSize = [Preferences floatForKey: kConsoleFontSize withDefault: 11.0];
|
54 |
currentFontSize = [Preferences floatForKey: kConsoleFontSize withDefault: 11.0];
|
| 51 |
textFont = [[NSFont userFixedPitchFontOfSize:currentFontSize] retain];
|
55 |
textFont = [[NSFont userFixedPitchFontOfSize:currentFontSize] retain];
|
| 52 |
}
|
56 |
}
|
| - |
|
57 |
NSLog(@"RConsoleWinCtrl%@: initWithWindowNibName: %@", self, windowNibName);
|
| 53 |
return self;
|
58 |
return self;
|
| 54 |
}
|
59 |
}
|
| 55 |
|
60 |
|
| 56 |
/* initializes R engine used by this console instance, sets engine cv accordingly */
|
61 |
/* initializes R engine used by this console instance, sets engine cv accordingly */
|
| 57 |
- (void) initEngine
|
62 |
- (void) initEngine
|
| Line 93... |
Line 98... |
| 93 |
SLog(@" - start REPL thread");
|
98 |
SLog(@" - start REPL thread");
|
| 94 |
[NSThread detachNewThreadSelector:@selector(run:) toTarget:engine withObject:self];
|
99 |
[NSThread detachNewThreadSelector:@selector(run:) toTarget:engine withObject:self];
|
| 95 |
}
|
100 |
}
|
| 96 |
}
|
101 |
}
|
| 97 |
|
102 |
|
| - |
|
103 |
|
| - |
|
104 |
#pragma mark --- NSWindowController delegate methods ---
|
| - |
|
105 |
|
| 98 |
- (void)windowDidLoad
|
106 |
- (void)windowDidLoad
|
| 99 |
{
|
107 |
{
|
| 100 |
SLog(@"RConsoleWinCtrl: windowDidLoad, name=%@, window=%@", [self windowNibName], [self window]);
|
108 |
SLog(@"RConsoleWinCtrl: windowDidLoad, name=%@, window=%@", [self windowNibName], [self window]);
|
| 101 |
SLog(@" - font = %@", textFont);
|
109 |
SLog(@" - font = %@", textFont);
|
| 102 |
[textView setFont:textFont];
|
110 |
[textView setFont:textFont];
|
| 103 |
//[textView setTypingAttributes:[NSDictionary dictionaryWithObject:textFont forKey:@"NSFont"]];
|
111 |
//[textView setTypingAttributes:[NSDictionary dictionaryWithObject:textFont forKey:@"NSFont"]];
|
| 104 |
[textView setString:@"\n"];
|
112 |
[textView setString:@"\n"];
|
| 105 |
|
- |
|
| 106 |
[self initEngine];
|
113 |
[self initEngine];
|
| 107 |
}
|
114 |
}
|
| 108 |
|
115 |
|
| - |
|
116 |
- (NSString *)windowTitleForDocumentDisplayName:(NSString *)displayName
|
| - |
|
117 |
{
|
| - |
|
118 |
// the title is always "R Console" regardless of the file name
|
| - |
|
119 |
return @"R Console";
|
| - |
|
120 |
}
|
| - |
|
121 |
|
| - |
|
122 |
|
| - |
|
123 |
#pragma mark --- console API ---
|
| 109 |
|
124 |
|
| 110 |
/* console input - the string passed here is handled as if it was typed on the console */
|
125 |
/* console input - the string passed here is handled as if it was typed on the console */
|
| 111 |
- (void) consoleInput: (NSString*) cmd interactive: (BOOL) inter
|
126 |
- (void) consoleInput: (NSString*) cmd interactive: (BOOL) inter
|
| 112 |
{
|
127 |
{
|
| 113 |
//@synchronized(textViewSync) {
|
128 |
//@synchronized(textViewSync) {
|
| Line 129... |
Line 144... |
| 129 |
//}
|
144 |
//}
|
| 130 |
}
|
145 |
}
|
| 131 |
|
146 |
|
| 132 |
- (BOOL) processSingleEventBlocking: (BOOL) blocking
|
147 |
- (BOOL) processSingleEventBlocking: (BOOL) blocking
|
| 133 |
{
|
148 |
{
|
| - |
|
149 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
| 134 |
NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask
|
150 |
NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask
|
| 135 |
untilDate:blocking?[NSDate distantFuture]:nil
|
151 |
untilDate:blocking?[NSDate distantFuture]:nil
|
| 136 |
inMode:NSDefaultRunLoopMode
|
152 |
inMode:NSDefaultRunLoopMode
|
| 137 |
dequeue:YES];
|
153 |
dequeue:YES];
|
| 138 |
if (event)
|
154 |
if (event)
|
| 139 |
[NSApp sendEvent:event];
|
155 |
[NSApp sendEvent:event];
|
| - |
|
156 |
[pool release];
|
| 140 |
return event?YES:NO;
|
157 |
return event?YES:NO;
|
| 141 |
}
|
158 |
}
|
| 142 |
|
159 |
|
| 143 |
/* this writes R output to the Console window directly, i.e. without using a buffer. Use handleWriteConsole: for the regular way. */
|
160 |
/* this writes R output to the Console window directly, i.e. without using a buffer. Use handleWriteConsole: for the regular way. */
|
| 144 |
- (void) writeConsoleDirectly: (NSString*) txt withColor: (NSColor*) color {
|
161 |
- (void) writeConsoleDirectly: (NSString*) txt withColor: (NSColor*) color {
|
| Line 167... |
Line 184... |
| 167 |
[textView scrollRangeToVisible:origSel];
|
184 |
[textView scrollRangeToVisible:origSel];
|
| 168 |
}
|
185 |
}
|
| 169 |
//}
|
186 |
//}
|
| 170 |
}
|
187 |
}
|
| 171 |
|
188 |
|
| - |
|
189 |
|
| 172 |
#pragma mark --- REngine callbacks ---
|
190 |
#pragma mark --- REngine callbacks ---
|
| 173 |
/* --- REngine callbacks --- */
|
191 |
/* --- REngine callbacks --- */
|
| 174 |
|
192 |
|
| 175 |
- (int) handleChooseFile:(char *)buf len:(int)len isNew:(int)isNew
|
193 |
- (int) handleChooseFile:(char *)buf len:(int)len isNew:(int)isNew
|
| 176 |
{
|
194 |
{
|