summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Benkard <mulk@minimulk.mst-plus>2008-08-28 11:01:33 +0200
committerMatthias Benkard <mulk@minimulk.mst-plus>2008-08-28 11:01:33 +0200
commitcefd7e1d8de67a4054eaaebbff1871d3a24b1c64 (patch)
tree97faa48c76f8b0728ae75ede6e7c8ddb172ba9a0
parentd90d52db13d663db1c045ac7f6b5f148f1f24ba8 (diff)
Listener: Take input from the user and print the forms read back.
-rw-r--r--MLKListenerController.m44
1 files changed, 44 insertions, 0 deletions
diff --git a/MLKListenerController.m b/MLKListenerController.m
index c43aff9..6e225d3 100644
--- a/MLKListenerController.m
+++ b/MLKListenerController.m
@@ -17,13 +17,19 @@
*/
#import "MLKListenerController.h"
+
+#import "MLKDynamicContext.h"
+#import "MLKPackage.h"
#import "MLKReader.h"
+#import "util.h"
@implementation MLKListenerController
- (IBAction)submit:(id)sender
{
id object;
+ NSDictionary *attrs;
NSString *input = [inputField stringValue];
+ MLKPackage *package;
NS_DURING
{
@@ -40,5 +46,43 @@
NS_ENDHANDLER;
[inputField setStringValue:@""];
+
+ package = [[MLKDynamicContext currentContext]
+ valueForSymbol:[[MLKPackage findPackage:@"COMMON-LISP"]
+ intern:@"*PACKAGE*"]];
+
+ NSMutableAttributedString *text = [outputTextView textStorage];
+ [text beginEditing];
+
+ attrs = [NSDictionary dictionaryWithObjectsAndKeys:
+ [NSColor blueColor], NSForegroundColorAttributeName, nil];
+ NSString *barePrompt = [NSString stringWithFormat:@"%@> ", [package name]];
+ NSAttributedString *prompt =
+ LAUTORELEASE ([[NSAttributedString alloc] initWithString:barePrompt
+ attributes:attrs]);
+ [text appendAttributedString:prompt];
+
+ attrs = [NSDictionary dictionaryWithObjectsAndKeys:
+ [NSColor blackColor], NSForegroundColorAttributeName, nil];
+ NSAttributedString *inputFeedback =
+ LAUTORELEASE ([[NSAttributedString alloc] initWithString:input attributes:attrs]);
+ [text appendAttributedString:inputFeedback];
+
+ [[text mutableString] appendString:@"\n"];
+ [text endEditing];
+
+ // ...
+
+ [text beginEditing];
+ attrs = [NSDictionary dictionaryWithObjectsAndKeys:
+ [NSColor purpleColor], NSForegroundColorAttributeName, nil];
+ NSAttributedString *response =
+ LAUTORELEASE ([[NSAttributedString alloc] initWithString:MLKPrintToString(object)
+ attributes:attrs]);
+ [text appendAttributedString:response];
+
+ [[text mutableString] appendString:@"\n"];
+
+ [text endEditing];
}
@end