home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 January
/
usenetsourcesnewsgroupsinfomagicjanuary1994.iso
/
sources
/
misc
/
volume24
/
mced
/
part01
/
getch.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-10-26
|
3KB
|
151 lines
/*
* This software is Copyright (c) 1989, 1990, 1991 by Patrick J. Wolfe.
*
* Permission is hereby granted to copy, distribute or otherwise
* use any part of this package as long as you do not try to make
* money from it or pretend that you wrote it. This copyright
* notice must be maintained in any copy made.
*
* Use of this software constitutes acceptance for use in an AS IS
* condition. There are NO warranties with regard to this software.
* In no event shall the author be liable for any damages whatsoever
* arising out of or in connection with the use or performance of this
* software. Any use of this software is at the user's own risk.
*
* If you make modifications to this software that you feel
* increases it usefulness for the rest of the community, please
* email the changes, enhancements, bug fixes as well as any and
* all ideas to me. This software is going to be maintained and
* enhanced as deemed necessary by the community.
*
* Patrick J. Wolfe
* uunet!uiucuxc!kailand!pwolfe
* pwolfe@kailand.kai.com
*/
/*****************************************************************
* Modifications made by aknight to support emacs escape functions,
* Sun R function keys and vi escape, wiped out un-needed stuff
* for vt120, vt220
*****************************************************************/
#include "config.h"
#define NORMAL 100
#define ESCAPE 200
#define FKEY 300
extern int edit_mode;
int
pwolfe_getch(winptr)
WINDOW *winptr;
{
char c;
int state = NORMAL;
int fkeycount = 0;
while (1)
{
c = wgetch(winptr); /* call the real getch() */
switch (state)
{
case FKEY:
switch (c)
{
/* numeric function keys */
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
fkeycount = (fkeycount * 10) + (c - '0');
break;
/* lines deleted, aknight*/
case 'A':
return KEY_UP;
case 'B':
return KEY_DOWN;
case 'C':
return KEY_RIGHT;
case 'D':
return KEY_LEFT;
/* added by aknight, R1 - R15 keys on Sun*/
case 'z':
return fkeycount + 1000;
default:
beep();
state = NORMAL;
}
break;
case ESCAPE:
switch (c)
{
case 'O':
case '[':
state = FKEY;
fkeycount = 0;
break;
/* added by aknight, Escape - key functions */
case 'f':
return EscapeF;
case 'b':
return EscapeB;
case 'd':
return EscapeD;
case 'c':
return EscapeC;
case 'l':
return EscapeL;
case 'u':
return EscapeU;
case 'm':
return EscapeM;
case Delete:
return EscapeDEL;
case Escape:
state = ESCAPE;
break;
default:
state = NORMAL;
beep();
}
break;
default:
switch (c)
{
case Escape:
state = ESCAPE;
/* added by aknight */
if (edit_mode == VI_INS_MODE || edit_mode == VI_R_MODE)
return Escape;
break;
case CSI:
state = FKEY;
fkeycount = 0;
break;
default:
return (c);
}
}
}
}