www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Begining with D

reply "Alejandro" <alexgyg msn.com> writes:
Hi

I'm new in D, have some experience in JavaScript and PHP, and 
learned, for long time ago, C and a bit little C++

I remember that when I learned C with console output, it was two 
easy ways to catch input : one witch a required  <Enter> keydown, 
and an other witch catched a single character, a single keydown. 
I liked very much this last function (I think it was get()), very 
useful when making small programs for learning purposes.

I'm looking for something like that in D, widthout finding it. 
I'm sorry coming here width my bad English asking a question like 
that, I see everyone here has a hight level in coding D, but 
since there is no much documentation around Internet, I don't 
find another solution.
Oct 10 2013
next sibling parent reply =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 10/10/2013 11:56 AM, Alejandro wrote:

 catched a single character, a single keydown
The following program is based on the following newsgroup post: http://forum.dlang.org/post/mailman.2665.1300747084.4748.digitalmars-d-learn puremagic.com The program prints character codes in hex until it sees Ctrl-D: import std.stdio : writef, writeln; import std.c.stdio; import std.c.linux.termios; /* The declaration of cfmakeraw, which is missing from standard D modules. */ extern(C) void cfmakeraw(termios *termios_p); void main() { /* Saving the existing state of tty. */ termios oldState; tcgetattr(1, &oldState); /* Ensuring that it will be restored upon exit. */ scope (exit) tcsetattr(1, TCSADRAIN, &oldState); /* Make a new state and set it to raw mode. */ termios newState; tcgetattr(1, &newState); cfmakeraw(&newState); /* Use the new state in this terminal. */ tcsetattr(1, TCSADRAIN, &newState); /* * We are ready to read characters in this raw mode... */ /* This is Ctrl-D, the EOF character under Linux. */ enum endOfFile = '\4'; for (char c; c != endOfFile; ) { c = cast(char)fgetc(stdin); writef("%02x ", c); } writeln(); }
 my bad English
Please don't say that. :) Thank you very much for communicating in English. Ali
Oct 10 2013
parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
On Thursday, 10 October 2013 at 19:19:53 UTC, Ali Çehreli wrote:
 import std.c.linux.termios;
worth noting that this is Linux only. doing it on Windows is a little different. Working with console/terminal input and output can get surprisingly complex, and doing it cross-platform is easiest with a library. Robik's consoleD is one: https://github.com/robik/ConsoleD/blob/master/consoled.d it focuses on enabling color and drawing mainly, and also has functions to turn off the line buffering and getch(). If you use his library, you can do this: import consoled; void main() { int a = getch(); // gets just one character writecln(a); // prints back out what you got } and other nice things.
Oct 10 2013
parent reply 1100110 <0b1100110 gmail.com> writes:
On 10/10/2013 02:36 PM, Adam D. Ruppe wrote:
 On Thursday, 10 October 2013 at 19:19:53 UTC, Ali Çehreli wrote:
 import std.c.linux.termios;
worth noting that this is Linux only. doing it on Windows is a little different. Working with console/terminal input and output can get surprisingly complex, and doing it cross-platform is easiest with a library. Robik's consoleD is one: https://github.com/robik/ConsoleD/blob/master/consoled.d it focuses on enabling color and drawing mainly, and also has functions to turn off the line buffering and getch(). If you use his library, you can do this: import consoled; void main() { int a = getch(); // gets just one character writecln(a); // prints back out what you got } and other nice things.
I had issues with getch() on ConsoleD... If you too have issue, you can try github.com/D-Programming-Deimos/ncurses which has similar functions, but is also way more complex...
Oct 12 2013
next sibling parent "Adam D. Ruppe" <destructionator gmail.com> writes:
On Saturday, 12 October 2013 at 21:27:18 UTC, 1100110 wrote:
 I had issues with getch() on ConsoleD...
What was it? I fixed a bug in it right before posting that message the other day so it might be fixed now.
 If you too have issue, you can try 
 github.com/D-Programming-Deimos/ncurses which has similar 
 functions, but is also way more complex...
yeah. there's also my own terminal.d (also available in robik's repo) that can do it all but is again even more complex.
Oct 12 2013
prev sibling parent "Robik" <nomail foo.com> writes:
On Saturday, 12 October 2013 at 21:27:18 UTC, 1100110 wrote:
 On 10/10/2013 02:36 PM, Adam D. Ruppe wrote:
 On Thursday, 10 October 2013 at 19:19:53 UTC, Ali Çehreli 
 wrote:
 import std.c.linux.termios;
worth noting that this is Linux only. doing it on Windows is a little different. Working with console/terminal input and output can get surprisingly complex, and doing it cross-platform is easiest with a library. Robik's consoleD is one: https://github.com/robik/ConsoleD/blob/master/consoled.d it focuses on enabling color and drawing mainly, and also has functions to turn off the line buffering and getch(). If you use his library, you can do this: import consoled; void main() { int a = getch(); // gets just one character writecln(a); // prints back out what you got } and other nice things.
I had issues with getch() on ConsoleD... If you too have issue, you can try github.com/D-Programming-Deimos/ncurses which has similar functions, but is also way more complex...
I guess its was on linux right? Probably because some last quickfixes i added wasn't propely (read never) tested on linux :P Soon I'll try to finally start working on merging terminald and consoled somehow.
Oct 13 2013
prev sibling parent reply "Elvis Zhou" <elvis.x.zhou gmail.com> writes:
On Thursday, 10 October 2013 at 18:56:58 UTC, Alejandro wrote:
 Hi

 I'm new in D, have some experience in JavaScript and PHP, and 
 learned, for long time ago, C and a bit little C++

 I remember that when I learned C with console output, it was 
 two easy ways to catch input : one witch a required  <Enter> 
 keydown, and an other witch catched a single character, a 
 single keydown. I liked very much this last function (I think 
 it was get()), very useful when making small programs for 
 learning purposes.

 I'm looking for something like that in D, widthout finding it. 
 I'm sorry coming here width my bad English asking a question 
 like that, I see everyone here has a hight level in coding D, 
 but since there is no much documentation around Internet, I 
 don't find another solution.
I think what you want is as simple as following. import std.process; void main() { //try and learn here system("pause"); }
Oct 13 2013
parent "Elvis Zhou" <elvis.x.zhou gmail.com> writes:
On Sunday, 13 October 2013 at 11:45:39 UTC, Elvis Zhou wrote:
 On Thursday, 10 October 2013 at 18:56:58 UTC, Alejandro wrote:
 Hi

 I'm new in D, have some experience in JavaScript and PHP, and 
 learned, for long time ago, C and a bit little C++

 I remember that when I learned C with console output, it was 
 two easy ways to catch input : one witch a required  <Enter> 
 keydown, and an other witch catched a single character, a 
 single keydown. I liked very much this last function (I think 
 it was get()), very useful when making small programs for 
 learning purposes.

 I'm looking for something like that in D, widthout finding it. 
 I'm sorry coming here width my bad English asking a question 
 like that, I see everyone here has a hight level in coding D, 
 but since there is no much documentation around Internet, I 
 don't find another solution.
I think what you want is as simple as following. import std.process; void main() { //try and learn here system("pause"); }
windows only
Oct 13 2013