[comp.unix.wizards] handling escape characters

paul@jane.jpl.nasa.gov (Paul Asmar) (08/02/89)

	Has anyone had to write some sort of an editor, and had to deal
with the escape key carrying on several meanings (i.e. the escape
sequences, and the key itself).  I was wondering if someone can help
me figure out what is a good way to implement this.  And, does anyone
know how "vi" deals with this problem?

Paul

--
Paul Asmar (paul@jane.jpl.nasa.gov)

bob@wyse.wyse.com (Bob McGowen Wyse Technology Training) (08/03/89)

In article <1989Aug2.164100.7912@elroy.jpl.nasa.gov> paul@jane.jpl.nasa.gov (Paul Asmar) writes:
>
>	Has anyone had to write some sort of an editor, and had to deal
>with the escape key carrying on several meanings (i.e. the escape
>sequences, and the key itself).  I was wondering if someone can help
>me figure out what is a good way to implement this.  And, does anyone
>know how "vi" deals with this problem?
>
>Paul
>
>--
>Paul Asmar (paul@jane.jpl.nasa.gov)

In one of the texts I once read, it was stated that vi using a timing
method to determine the difference.  If the character following the
ESC is inside the timeout, then it is an escape sequence, otherwise
it was entered by the user.

This can cause problems if the system introduces a delay between the
ESC and the next character (I have had this happen to users who hit
an up or down arrow key rapidly several times).  The result is finding
the cursor somewhere else, often in text entry mode.

Bob McGowan  (standard disclaimer, these are my own ...)
Customer Education, Wyse Technology, San Jose, CA
..!uunet!wyse!bob
bob@wyse.com

ott@guug.UUCP (OTT GmbH) (08/10/89)

In article <1989Aug2.164100.7912@elroy.jpl.nasa.gov>, paul@jane.jpl.nasa.gov (Paul Asmar) writes:
> 
> 	Has anyone had to write some sort of an editor, and had to deal
> with the escape key carrying on several meanings (i.e. the escape
> sequences, and the key itself).  /etc /etc

I have written a command-line-editor (like dosedit) for unix with the
same syntax like in dos, that is cursor-up and -down move thru the commands
and ESC only clears the current command-line. The way to do this is to set
up the terminal into raw-mode and to make the read-call return after 1 char
being read or after 1/10 seconds of no input. This is the same way vi does
it and differs between ESC only and a cursor-key (like ESC [ A). On slow
terminals however vi receives the ESC of a cursor-key, beeps and interprets
[ and A as commands (try it by editing a file and keep a cursor key pressed).
If you can avoid using the ESC-key in your program, do it.
Joachim Ott, Munich, West Germany