Generally about UNIX text editors
All of my friends who use Linux always told me that text editors is very important problem under this OS (I mean text-mode editors with 100K executable for writing programs). As I understand, this problem is not a problem of Linux itself, but it's a problem of every UNIX. What's more I know which reasons cause this trouble. There is two reasons: putc output to screen and getc input from keyboard. In other OS-es user (programmer) can catch Alt+<letter> or Shift+<letter> keystrokes and use it as a commands of editor. In UNIX user has only 256 ASCII-codes avialable (really, much less than 256) and because of it every UNIX editor uses either very long sequences of keystrokes as editing commands (as emacs or joe) or it has two editing modes (command mode and typing mode in VI for example). On X-s everything is better, because here we can get scan code (not real scan, but this code is anough for all my needs) of the key pressed and status of Shift-keys (Alt, Caps, Shift, Ctrl and mouse buttons), so we can use functional keys, arrow-keys and everything else You can find on Your keyboard (everybody knows how to do that).
But even with text mode editors under Linux everything is not so bad: You can switch keyboard to RAW mode and do with it all You want (don't forget to get another console from which You will execute shutdown -r now command during beta-testing Your program). But it's very important to understand that RAW-keyboard programs will not work through telnet. Also is very important to set SIGSEGV and SIGKILL signal handlers so that they'll switch keyboard back to normal mode from RAW when something happens. Once I heard about kernel patching so that You can use ScrollLock key to switch between raw and normal mode, but I don't know how to apply this patch.
What I'd like to have in text editor
Caution : This section is very private. Maybe someone will find something useful for him(here) here, but probably not. This section is mostly about my own text editor, so, if You got used to Turbo-Vision-like editors and You're satisfied, then probably You will find the follwing not interesting. So don't read it, don't waste Your time.
If You're interested in all that, You can try our example of such a text editor. I think it isn't the best editor, but I got used to it. May It will be useful for someone. To get it, go to http://shade.msu.ru/~machulsk and download 330K zip file, which contains sources and 5 executables for Linux console, Linux X11, OS/2, DOS and Win32 (95/nt). Docs are also included in HTML / plainTeX format.
Example of switching to RAW keyboard mode (C++ syntax)
#include < stdio.h > #include < stdlib.h > #include < unistd.h > #include < errno.h > #include < linux/kd.h > #include < signal.h > #include < sys/ioctl.h > /*.................*/ void Terminate(int a) { if( ioctl(con_fd,KDSKBMODE,om)<0 ) {puts("Press RESET?");exit(-1);} /*trying to set old keydoard mode*/ } /*.................*/ class TKeyboard{ int om; /* old keyboard mode descriptor */ int con_fd; /* console descriptor */ TKeyboard(){ signal(SIGKILL, Terminate ); /*setting SIGKILL signal handler*/ signal(SIGQUIT, Terminate ); /*setting SIGQUIT signal handler*/ signal(SIGSEGV, Terminate ); /*setting SIGSEGV signal handler*/ if( 0==(con_fd=open("/dev/tty",O_RDWR)) ) {puts("error");exit(-1);} /*getting console descriptor*/ if( ioctl(con_fd,KDGKBMODE,&om)<0 ) {puts("error");exit(-1);} /*getting old keydoard mode*/ if( ioctl(con_fd,KDSKBMODE,K_RAW)<0 ) {puts("error");exit(-1);} /*setting RAW keydoard mode*/ } ~TKeyboard(){ Terminate(0); } int GetScanCode(){ int c; ioctl(con_fd,TIOCINQ,&cd); /*query*/ if(cd==0) /*keyboard buffer is empty*/ read(con_fd,&c,1); /*get next scancode from console*/ } } KBD; /*.................*/ void main() { /*.................*/ /*................. program body */ /*.................*/ }
Thank You!
My addresses: homepage on(in?) Shadescuze me for bad english, but my native language is Russian