From: paul-ml AT is DOT lg DOT ua (Paul Sokolovsky) Subject: Re[2]: console mode and \r, \n, etc. 5 Dec 1998 05:11:45 -0800 Message-ID: <15578.981204.cygnus.cygwin32.developers@is.lg.ua> References: <36671B0B DOT B843770A AT cityweb DOT de> Reply-To: Paul Sokoilovsky Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: Corinna Vinschen , cygwin32-developers AT cygnus DOT com Hello Corinna, Corinna Vinschen wrote: CV> Christopher Faylor wrote: >> I'm investigating Corinna's problems with console mode stuff. >> >> What a mess. CV> Yes, isn't it? >> [...] >> So my question is, does anybody object to doing "character at a time" >> reads on the console? This will slow down console reads slightly but >> I'm hoping to get as much right as possible with console input. For one >> thing, I think I've identified the consistently reported problem of >> cursor keys not working on Windows 95. That should be fixable. CV> IMHO, cygwin should read from console with ReadConsoleInput in raw mode CV> and should do cooking all self. This has more advantages then drawbacks, CV> I think. New possibilities: ENABLE_WINDOW_INPUT and ENABLE_MOUSE_INPUT CV> are making sense now! And the code would be more 'reader friendly'. And CV> nearly all stty modes are possible. And possible more features... Yes, but it has problems too, even bugs. For example, if you care about it, win95 has problems with localization features when using ReadConsoleInput() - it just bypass keyboard localizer (which is dos program at all). Here's how it worked around: int rl_getch() { int key=0; int mask=0; if (pending_flag) { pending_flag=0; return pending_key; } for (;;) { WaitForSingleObject(STDIN,INFINITE); if (!PeekConsoleInput(STDIN,&ir,1,&dummy)) goto FromFile; if (ir.EventType==KEY_EVENT && ir.Event.KeyEvent.bKeyDown) { if (!(KE.wVirtualKeyCode>=VK_SHIFT && KE.wVirtualKeyCode<=VK_MENU)) { if (KEYSTATE&(LEFT_ALT_PRESSED|RIGHT_ALT_PRESSED)) mask=0x100; if (!KE.uChar.AsciiChar) { /* Non-ascii, so will be prefixed */ if (mask) mask=4; if (KEYSTATE&SHIFT_PRESSED) mask|=1; if (KEYSTATE&(LEFT_CTRL_PRESSED|RIGHT_CTRL_PRESSED)) mask|=2; ReadConsoleInput(STDIN,&ir,1,&dummy); pending_flag=pending_key=ir.Event.KeyEvent.wVirtualKeyCode; return mask|EXT_PREFIX; } else { /* Ascii, return directly */ if (mask) { ReadConsoleInput(STDIN,&ir,1,&dummy); return tolower(ir.Event.KeyEvent.uChar.AsciiChar)|mask; } FromFile: ReadFile(STDIN,&key,1,&dummy,NULL); return key; } } } ReadConsoleInput(STDIN,&ir,1,&dummy); } } void rl_getch_init() { SetConsoleMode(STDIN,ENABLE_PROCESSED_INPUT); } CV> Regards, CV> Corinna Best regards, Paul mailto:paul-ml AT is DOT lg DOT ua