digitalmars.D - Single char input in D
- Bob W (26/26) Feb 28 2006 Correct me if I am wrong, but there seems to be
- Derek Parnell (5/8) Feb 28 2006 I used 'getch()' and that seemed to work okay.
- Bob W (6/7) Feb 28 2006 Yes, we both know that it works (as opposed to getche() ).
- Bruno Medeiros (7/44) Mar 02 2006 getch() and getche() are not ANSI/ISO C (thus not "good ol' C"). They
- Deewiant (7/10) Mar 02 2006 Nevertheless both getch() and getche() are extremely useful and deserve ...
- Bob W (6/8) Mar 03 2006 Tell me any major C compiler NOT featuring getch() or _getch().
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (4/8) Mar 03 2006 Mac OS X only has "getchar"... "getch" is in (the bundled) ncurses.h
- Bruno Medeiros (6/17) Mar 04 2006 That's the same for all gcc everywhere, right?
- Bob W (3/10) Mar 04 2006 Not everywhere - gcc based djgpp offers getch() in conio.h
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?
Feb 28 2006
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
Feb 28 2006
"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 ....
Feb 28 2006
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."
Mar 02 2006
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.
Mar 02 2006
"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.
Mar 03 2006
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
Mar 03 2006
Anders F Björklund wrote:Bob W wrote: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."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
Mar 04 2006
"Bruno Medeiros" <daiphoenixNO SPAMlycos.com> wrote in message news:dubpb0$tki$1 digitaldaemon.com...Anders F Björklund wrote:Not everywhere - gcc based djgpp offers getch() in conio.hMac 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. --andersThat's the same for all gcc everywhere, right?
Mar 04 2006