delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2002/08/23/18:35:53

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Date: Fri, 23 Aug 2002 16:35:44 -0600 (MDT)
From: "J. Scott Edwards" <sedwards AT xmission DOT com>
To: cygwin AT cygwin DOT com
Subject: RE: Character at a time input (was Re: Where is less source?)
In-Reply-To: <E3117AE4EC45D511BEC10002A55CB09CFFB2B2@eukbant102.uk.eu.ericsson.se>
Message-ID: <Pine.GSO.4.44.0208231631380.26458-100000@xmission.xmission.com>
MIME-Version: 1.0
X-Spam-Status: No, hits=-2.3 required=8.0
tests=IN_REP_TO,DOUBLE_CAPSWORD
version=2.31
X-Spam-Level:

Thanks that worked great!

I have another dumb question: is there a simple way to determine if the
stdin is from a terminal or is pipe'd in?

Thanks again
  -Scott


On Fri, 23 Aug 2002, Rick Hellicar (QMP) wrote:

> Don't know about ioctl, but termios will do it.  I've included a
> simple program that shows it working.
>
> If you're planning on detecting arrow keys, function keys, etc., then
> you have to remember that they produce an escape-sequence of several
> characters, which you'll have to detect and decode.
>
> Hope this helps,
>
> Rick
>
>
>
>
> #include <unistd.h>
> #include <stdio.h>
> #include <termios.h>
>
> int
> main (void)
> {
>   struct termios new_settings;
>   struct termios stored_settings;
>   char c;
>
>   /* record the old settings to restore the terminal when finished */
>   tcgetattr (0, &stored_settings);
>   new_settings = stored_settings;
>
>   /* set things up for character-at-a-time */
>   new_settings.c_lflag &= ~(ICANON | ECHO);
>   new_settings.c_cc[VTIME] = 0; /* don't think this is relevant if VMIN=1 */
>   new_settings.c_cc[VMIN] = 1;
>   tcsetattr (0, TCSANOW, &new_settings);
>
>   /* main loop - press q to exit */
>   do
>     {
>       c = getchar ();
>       printf ("%d\t%c\n", c, c);
>     }
>   while (c != 'q');
>
>   /* restore the old settings */
>   tcsetattr (0, TCSANOW, &stored_settings);
>   return 1;
> }
>
>
>
> > -----Original Message-----
> > From: J. Scott Edwards [mailto:sedwards AT xmission DOT com]
> > Sent: 22 August 2002 23:23
> > To: Gerrit @ cygwin
> >
> > Thanks, I found it.  But unfortunately it didn't answer my question:
> >
> > Can ioctl be used to change the standard input into character
> > at a time
> > mode or do I have to use ncurses or is there a better way to
> > just get a
> > character at a time?
>


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019