From cefd7e1d8de67a4054eaaebbff1871d3a24b1c64 Mon Sep 17 00:00:00 2001 From: Matthias Benkard Date: Thu, 28 Aug 2008 11:01:33 +0200 Subject: Listener: Take input from the user and print the forms read back. --- MLKListenerController.m | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) 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 -- cgit v1.2.3