public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* RE: Character at a time input (was Re: Where is less source?)
@ 2002-08-23 14:02 Dan Kegel
  0 siblings, 0 replies; 6+ messages in thread
From: Dan Kegel @ 2002-08-23 14:02 UTC (permalink / raw)
  To: 'J. Scott Edwards ', 'cygwin@cygwin.com'

See
http://www.cygwin.com/ml/cygwin/2000-11/msg01097.html
See also
http://www.opengroup.org/onlinepubs/007904975/functions/tcsetattr.html
- Dan

-----Original Message-----
From: J. Scott Edwards
To: Gerrit @ cygwin
Sent: 22.08.2002 15:23
Subject: Character at a time input (was Re: Where is less source?)


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?

Thanks
 -Scott


On Thu, 22 Aug 2002, Gerrit P. Haase wrote:

> Hallo,
>
> >> Anyway if someone could point me to the 'less' source it would be
> >> greatly appreciated.
>
> Lookup one of the mirrors that is near to you:
> http://cygwin.com/mirrors.html
>
> less is in the directory: release/less/
>
>
> Gerrit
> --
> Try 'sevenzip': http://www.7-zip.org/
>
>
> --
> 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/
>
>


--
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/

--
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/

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

* RE: Character at a time input (was Re: Where is less source?)
@ 2002-08-24 11:38 Dan Kegel
  0 siblings, 0 replies; 6+ messages in thread
From: Dan Kegel @ 2002-08-24 11:38 UTC (permalink / raw)
  To: 'J. Scott Edwards ', 'cygwin@cygwin.com '

"man isatty"

-----Original Message-----
From: J. Scott Edwards

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@xmission.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/

--
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/

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

* RE: Character at a time input (was Re: Where is less source?)
  2002-08-23  6:05 Rick Hellicar (QMP)
@ 2002-08-24 10:49 ` J. Scott Edwards
  0 siblings, 0 replies; 6+ messages in thread
From: J. Scott Edwards @ 2002-08-24 10:49 UTC (permalink / raw)
  To: cygwin


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@xmission.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/

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

* RE: Character at a time input (was Re: Where is less source?)
@ 2002-08-23  6:05 Rick Hellicar (QMP)
  2002-08-24 10:49 ` J. Scott Edwards
  0 siblings, 1 reply; 6+ messages in thread
From: Rick Hellicar (QMP) @ 2002-08-23  6:05 UTC (permalink / raw)
  To: 'cygwin@cygwin.com'; +Cc: 'J. Scott Edwards'

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@xmission.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/

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

* Re: Character at a time input (was Re: Where is less source?)
       [not found] ` <Pine.GSO.4.44.0208221603080.13008-100000@xmission.xmission .com>
@ 2002-08-23  2:11   ` Randall R Schulz
  0 siblings, 0 replies; 6+ messages in thread
From: Randall R Schulz @ 2002-08-23  2:11 UTC (permalink / raw)
  To: cygwin

Scott,

I'm afraid to do that on Windows you'll have to reboot after reading each 
character.


OK. Not to be totally frivolous: Yes, "cbreak" and "raw" modes work under 
Cygwin. You can see it work from the command line:

% stty cbreak
% cat
tthhiiss  iiss  aa  tteesstt

%

Just to be clear, I typed "this is a test<RETURN>". For reasons I don't 
understand, CTRL-D (which I verified is my tty's eof character) did not 
generate a end-of-file condition--I had to use CTRL-C to terminate the 
"cat" command. What seems even stranger is that "raw" mode behaved the same 
way. I suppose those symptoms occur because I don't include the "tty" 
option in $CYGWIN.

Randall Schulz
Mountain View, CA USA


At 15:23 2002-08-22, J. Scott Edwards wrote:

>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?
>
>Thanks
>  -Scott


--
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/

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

* Character at a time input (was Re: Where is less source?)
  2002-08-21 17:39 Where is less source? Gerrit P. Haase
@ 2002-08-22 19:34 ` J. Scott Edwards
       [not found] ` <Pine.GSO.4.44.0208221603080.13008-100000@xmission.xmission .com>
  1 sibling, 0 replies; 6+ messages in thread
From: J. Scott Edwards @ 2002-08-22 19:34 UTC (permalink / raw)
  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?

Thanks
 -Scott


On Thu, 22 Aug 2002, Gerrit P. Haase wrote:

> Hallo,
>
> >> Anyway if someone could point me to the 'less' source it would be
> >> greatly appreciated.
>
> Lookup one of the mirrors that is near to you:
> http://cygwin.com/mirrors.html
>
> less is in the directory: release/less/
>
>
> Gerrit
> --
> Try 'sevenzip': http://www.7-zip.org/
>
>
> --
> 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/
>
>


--
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/

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

end of thread, other threads:[~2002-08-23 22:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-23 14:02 Character at a time input (was Re: Where is less source?) Dan Kegel
  -- strict thread matches above, loose matches on Subject: below --
2002-08-24 11:38 Dan Kegel
2002-08-23  6:05 Rick Hellicar (QMP)
2002-08-24 10:49 ` J. Scott Edwards
2002-08-21 17:39 Where is less source? Gerrit P. Haase
2002-08-22 19:34 ` Character at a time input (was Re: Where is less source?) J. Scott Edwards
     [not found] ` <Pine.GSO.4.44.0208221603080.13008-100000@xmission.xmission .com>
2002-08-23  2:11   ` Randall R Schulz

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).