Thread overview | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
February 28, 2006 Single char input in D | ||||
---|---|---|---|---|
| ||||
Correct me if I am wrong, but there seems to be no native support in D for getting a single char from the keyboard. While 'printf' has been elegantly replaced, nothing as simple as a 'getch' or 'getche' equivalent seems to exist in D. The closest I could get to was to rely on Phobos' std.cstream and using 'din.getch'. It is currently not documented (unlike 'din.getc'), but I regarded it as implied that it would work. Unfortunately 'din.getche' has obviously the same bug as its C counterpart in dmc - it simply does not do what it should (echoed 'getch'). The whole think makes me wondering if I have overlooked something or if I am the last person here using D console apps which actually expect characters from the keyboard without EOLs attached to them. Remaining questions are: - Can I rely on 'din.getch' being available in future, even though it is not explicitly mentioned in the Phobos docs? - Will 'getche' eventually work properly one day? - Is there any method available/planned in D for reading extended keycodes from the keyboard? |
February 28, 2006 Re: Single char input in D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bob W | On Tue, 28 Feb 2006 23:14:53 +1100, Bob W <nospam@aol.com> wrote: > Correct me if I am wrong, but there seems to be > no native support in D for getting a single char > from the keyboard. I used 'getch()' and that seemed to work okay. -- Derek Parnell Melbourne, Australia |
February 28, 2006 Re: Single char input in D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Derek Parnell | "Derek Parnell" <derek@psych.ward> wrote in message news:op.s5om75qa6b8z09@ginger.vic.bigpond.net.au... > I used 'getch()' and that seemed to work okay. Yes, we both know that it works (as opposed to getche() ). But it is borrowed from good ol' C and I am wondering if an enthusiastic D (and C) newbie would find a solution just by digging through Phobos .... |
March 02, 2006 Re: Single char input in D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bob W | Bob W wrote: > Correct me if I am wrong, but there seems to be > no native support in D for getting a single char > from the keyboard. > > While 'printf' has been elegantly replaced, nothing > as simple as a 'getch' or 'getche' equivalent seems > to exist in D. > > The closest I could get to was to rely on Phobos' > std.cstream and using 'din.getch'. It is > currently not documented (unlike 'din.getc'), > but I regarded it as implied that it would work. > > Unfortunately 'din.getche' has obviously the > same bug as its C counterpart in dmc - it > simply does not do what it should > (echoed 'getch'). > > The whole think makes me wondering if I have > overlooked something or if I am the last person > here using D console apps which actually expect > characters from the keyboard without EOLs > attached to them. > > Remaining questions are: > > - Can I rely on 'din.getch' being available in future, > even though it is not explicitly mentioned in the > Phobos docs? > > - Will 'getche' eventually work properly one day? > > - Is there any method available/planned in D for > reading extended keycodes from the keyboard? > > > getch() and getche() are not ANSI/ISO C (thus not "good ol' C"). They are Borland extensions if I'm not mistaken. -- Bruno Medeiros - CS/E student "Certain aspects of D are a pathway to many abilities some consider to be... unnatural." |
March 02, 2006 Re: Single char input in D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bruno Medeiros | Bruno Medeiros wrote:
> getch() and getche() are not ANSI/ISO C (thus not "good ol' C"). They
> are Borland extensions if I'm not mistaken.
>
Nevertheless both getch() and getche() are extremely useful and deserve their
places in D, regardless of whether or not they are part of any C standard.
What I'd really like is a full Curses-type, platform-independent (well, *nix/Windows) module in the standard library, but I'm fairly sure that's not going to happen at least any time soon. Curses itself is just such a pain in far too many respects.
|
March 03, 2006 Re: Single char input in D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bruno Medeiros | "Bruno Medeiros" <daiphoenixNO@SPAMlycos.com> wrote in message news:du74jc$1hrs$3@digitaldaemon.com... > getch() and getche() are not ANSI/ISO C (thus not "good ol' C"). They are Borland extensions if I'm not mistaken. > Tell me any major C compiler NOT featuring getch() or _getch(). It simply is a necessity having it as part of a C library. Therefore it is widely available and it does not matter at all whether it is standardized or not. |
March 03, 2006 Re: Single char input in D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bob W | Bob W wrote:
> Tell me any major C compiler NOT featuring getch() or _getch().
> It simply is a necessity having it as part of a C library. Therefore
> it is widely available and it does not matter at all whether it is
> standardized or not.
Mac OS X only has "getchar"... "getch" is in (the bundled) ncurses.h
Of course, to use that you need to link to the libncurses.dylib too.
--anders
|
March 04, 2006 Re: Single char input in D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Anders F Björklund | Anders F Björklund wrote: > Bob W wrote: > >> Tell me any major C compiler NOT featuring getch() or _getch(). >> It simply is a necessity having it as part of a C library. Therefore >> it is widely available and it does not matter at all whether it is >> standardized or not. > > Mac OS X only has "getchar"... "getch" is in (the bundled) ncurses.h > Of course, to use that you need to link to the libncurses.dylib too. > > --anders That's the same for all gcc everywhere, right? -- Bruno Medeiros - CS/E student "Certain aspects of D are a pathway to many abilities some consider to be... unnatural." |
March 04, 2006 Re: Single char input in D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bruno Medeiros | "Bruno Medeiros" <daiphoenixNO@SPAMlycos.com> wrote in message news:dubpb0$tki$1@digitaldaemon.com... > Anders F Björklund wrote: >> >> Mac OS X only has "getchar"... "getch" is in (the bundled) ncurses.h Of course, to use that you need to link to the libncurses.dylib too. >> >> --anders > > That's the same for all gcc everywhere, right? > Not everywhere - gcc based djgpp offers getch() in conio.h |
Copyright © 1999-2021 by the D Language Foundation