Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!hoptoad!tim From: tim@hoptoad.uucp (Tim Maroney) Newsgroups: comp.sys.mac.programmer Subject: Re: Wanted: Code for simple text interface Message-ID: <8188@hoptoad.uucp> Date: 31 Jul 89 21:29:13 GMT References: <9674@phoenix.Princeton.EDU> Reply-To: tim@hoptoad.UUCP (Tim Maroney) Organization: Eclectic Software, San Francisco Lines: 86 In article <9674@phoenix.Princeton.EDU> bskendig@phoenix.Princeton.EDU (Brian Kendig) writes: >Here's my problem: I want to be able to open a simple window into which the >user can type commands. When he types a character, it is displayed; when he >types delete, a character is erased; when he types return or enter, the >entire command is parsed by the program. Simple enough, right? (Too bad no women will be using the software, eh?) Simple, yes, but it seems like you want something so simple that it violates users' expectations of the Mac user interface. >When I use TextEdit for the text window, the user is able to go back into the >stuff already displayed and edit it. I don't want this. Why? If you're going to be displaying text, I assure you that you *do* want users to be able to copy and paste it at least. If you don't want them to be able to change it, then that's easy enough -- don't allow any typing while there's a selection anywhere but at the end of the text, and don't pass on Cut or Clear commands. However, this is an inferior solution -- it implies that users can't use the normal text editing mechanisms on the Macintosh to edit their command lines. That's a mess. I recommend that you re-examine this assumption that editing the command text is bad. It works quite well in the MPW Shell, after all. >Besides, I can't >trap for the return or enter keys easily, and even when I do, I don't know >how to go back to the beginning of the line and retrieve the whole thing. Why? You are getting event records with the character codes stored in them in a not very subtle fashion. What prevents you from checking for them? Getting the text line is admittedly a bit harder, but the line starts array stored in the text edit record is not hard to use either. Just look in the last line start entry, add the offset to the start of the text area (a handle to which is stored in the text edit record) and extract the line there to the end of the record. >A simpler way would be to ignore TextEdit. I can listen for characters and >echo them to the screen when I get them, and when I get a return or enter, I >can parse the line. How is getting a return or enter here any different from if you are calling TextEdit to handle characters? You're dealing in the same commodity, key down event records. >Scrolling is a tad difficult and unwieldy, but that can >be overcome. The problem here is that when the user types delete, the delete >appears as a *character* on the screen - one of those little white rectangles. Yes, of course, if you call Quickdraw with that character code, you get whatever the Font Manager says is the appearance of that character. If you want to do editing, then you'll have to do your own using other Quickdraw calls, specifically, MoveTo (to backspace over the previous character) and EraseRect (to get rid of the image of the previous character). You will also have to draw your own flashing caret using MoveTo and LineTo calls. And your own selection handling, with all the mouse tracking and InvertRect calls and so forth. If you don't do all this, you haven't really written a Mac program. >So, how do I do this? I want to have an IBM-style interface (hold your cries; >there's a method to my madness) in a window. There's got to be an easy way! The easy way is to use TextEdit. That puts an effective length limitation on the size of your text, but you can cope with a screenful. But I have to question whether there really is a method to this. I feel that your comments are rife in assumptions that conflict with the basic goals of the Mac interface, and which seem to show that you don't have a lot of Mac experience yet. Most of us went through this stage; a horrible example is the MacNosy interface. You will likely find that after you assimilate more of the basic Mac concpets, you will decide that your decision to provide a command line interface was not a very good one. It may be that you do have some reason, but you haven't shared it with us. Nonetheless, because of your Mac inexperience, I am inclined to think that your design decisions have a great deal to do with a mental model that speaks well to the tty-interface problem and very badly to the Mac-interface problem. -- Tim Maroney, Mac Software Consultant, sun!hoptoad!tim, tim@toad.com "The pride of the peacock is the glory of God. The lust of the goat is the bounty of God. The wrath of the lion is the wisdom of God. The nakedness of woman is the work of God." - Blake, "The Marriage of Heaven and Hell"