public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* tty raw mode
@ 1997-10-17  9:51 Kees van Veen
  0 siblings, 0 replies; 2+ messages in thread
From: Kees van Veen @ 1997-10-17  9:51 UTC (permalink / raw)
  To: gnu-win32

Hi,

A while ago I posted a question about getting the console in raw mode.
In the meantime I found a partially working solution using
GetConsoleMode and
SetConsoleMode.

Here's a piece of code:

#include <stdio.h>
#include <fcntl.h>
#include <windows.h>

main()
{
        DWORD dwMode;
        HANDLE hStdIn = GetStdHandle(STD_INPUT_HANDLE);
        
        if (GetConsoleMode(hStdIn, &dwMode) == TRUE)
                SetConsoleMode(hStdIn, 
                    dwMode & ~(ENABLE_LINE_INPUT |		/* No buffering */
                               ENABLE_PROCESSED_INPUT |
                               ENABLE_ECHO_INPUT |		/* No echo
*/            			               ENABLE_WINDOW_INPUT));
        for (;;)
        {
                int c = getchar();
                printf("%d <%c>\n", c, c);
        }
}

Now all works fine except for two things:

1) getchar() does not distinguish between <CR> and <LF>
2) <LF) produces <CR><LF>

I've also tried a version using ReadConsole(), I've tried _setmode(0,
O_BINARY), but
without any success.

Does any of you have any idea ?

Thanks in advance for your time.

Kees
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

^ permalink raw reply	[flat|nested] 2+ messages in thread

* tty raw mode
@ 1997-10-29  8:46 Kees van Veen
  0 siblings, 0 replies; 2+ messages in thread
From: Kees van Veen @ 1997-10-29  8:46 UTC (permalink / raw)
  To: gnu-win32

Hi,

Just for your information:

I have managed to sort of get where I wanted to be, i.e. run a console
application in raw mode using GetConsoleMode and SetConsoleMode.

I use isatty() to find out whether I'm connected to a tty and then call
GetConsoleMode() to check whether I'm running on a console.

If GetConsoleMode returns FALSE, and isatty() returns TRUE I assume
I'm running from a pseudo tty and then there is no problem, because,
thanks
to the great work of Sergey, Mike Bernson and others, I'm now able to
run my
application using telnet and all my ioctl() settings work.

If I'm running from a console, I use SetConsoleMode to get to a kind of
raw mode (see below).

This does not avoid LF being interpreted as CR/LF though (sigh), so I
switch to
the escape sequence for arrow key down when running from a console.

One thing that struck me is that when I use getc(stdin) to read from the
console
CR (13) is always returned as LF (10) whereas using ReadConsole()
returns 13 upon CR,
even with the SetConsoleMode settings.

Cheers,
Kees

P.S.

For those interested in the Get/SetConsoleMode calls:


        DWORD input_mode, output_mode;
        if (GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE),
&input_mode)==TRUE)
        {
                SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE),
                        input_mode & ~( ENABLE_LINE_INPUT |
                                        ENABLE_ECHO_INPUT |
                                        ENABLE_PROCESSED_INPUT |
                                        ENABLE_WINDOW_INPUT));
        }
        if (GetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE),
&output_mode)==TRUE)
        {
                SetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE),
                        output_mode & ~(ENABLE_WRAP_AT_EOL_OUTPUT));
        }
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1997-10-29  8:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-10-17  9:51 tty raw mode Kees van Veen
1997-10-29  8:46 Kees van Veen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).