Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!cs.utexas.edu!sun-barr!apple!well!svc From: svc@well.UUCP (Leonard Rosenthol) Newsgroups: comp.sys.mac.programmer Subject: Re: Wanted: Code for simple text interface Summary: Just use TextEdit... Message-ID: <12973@well.UUCP> Date: 2 Aug 89 06:22:20 GMT References: <9674@phoenix.Princeton.EDU> Lines: 51 In article <9674@phoenix.Princeton.EDU>, bskendig@phoenix.Princeton.EDU (Brian Kendig) writes: > A while ago, I made a thorough search for a command-line interface for a > Macintosh. The only one I found did not quite suit my needs, so I decided > to take the most logical route and create my own. > > 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? > > 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. 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. > Just because the default interaction of TE does what you describe above does NOT mean that it HAS to. Since all events go through your application (or whatever) BEFORE TE gets them, you can do all sorts of preprocessing to decide whether TE should get them at as is, modified, or not at all. For example, to prevent editing of previous text, you can check the selection point/rect (TE^^.selStart, TE^^.selEnd) and if it is not on the last line of the text (current entry line, I am assuming one line at a time) (you can get lines using the TE^^.lineStarts array) then don't process keydowns, edit commands, etc. As to trapping the return/enter keys you get the keyDown first, and simply check to see what the key is and if CR or Enter than get the last line using the lineStarts array and TE^^.length and parse it, etc. If you need some example code for using the lineStarts array I can dig some up and post it. > 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. 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. > As mentioned above, TE will work just fine. If, however, you want to write your own then you will need to do certain things to emulate TE. For example, you site one of the best examples, the handling of backspace. The backspace character is a character in teh font just like any other, and as such you really do want to call DrawChar on it. What you want to do is to back the 'cursor' up one character (probably erasing it as well), just like TE does. the other major problem would be handling of scrolling, storage, etc. I think your tiem would be best spent working with my above suggestions to use TE rathe than reinventing the wheel for this 'simple' taks. -- +--------------------------------------------------+ Leonard Rosenthol | GEnie : MACgician Lazerware, inc. | MacNet: MACgician UUCP: svc@well.UUCP | ALink : D0025