www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - is there a way to pause a program and resume with just a key press (or

reply "WhatMeWorry" <kc_heaser yahoo.com> writes:
Sorry if this is an incredibly naive question.

I prefer to pragmatically pause my programs periodically so that 
I can peruse output statements. Ideally, I'd like to continue by 
just hitting any old key. My feeble attempt below requires I 
enter at least one character and then the enter key.

char ignore;
writeln("Enter to continue");
readf(" %s", &ignore);

Is there a way to continue with any old key press? or just the 
enter key?

Thanks in advance.
Jul 14 2014
next sibling parent reply "H. S. Teoh via Digitalmars-d-learn" <digitalmars-d-learn puremagic.com> writes:
On Tue, Jul 15, 2014 at 02:49:55AM +0000, WhatMeWorry via Digitalmars-d-learn
wrote:
 Sorry if this is an incredibly naive question.
 
 I prefer to pragmatically pause my programs periodically so that I can
 peruse output statements. Ideally, I'd like to continue by just hitting any
 old key. My feeble attempt below requires I enter at least one character and
 then the enter key.
 
 char ignore;
 writeln("Enter to continue");
 readf(" %s", &ignore);
 
 Is there a way to continue with any old key press? or just the enter key?
[...] I don't know about Windows, but on Linux, you can just press ctrl-s and ctrl-q to pause/resume the console. (This is a Linux terminal function, not specific to D.) T -- Ruby is essentially Perl minus Wall.
Jul 14 2014
parent "ponce" <contact gam3sfrommars.fr> writes:
 I don't know about Windows, but on Linux, you can just press 
 ctrl-s and
 ctrl-q to pause/resume the console. (This is a Linux terminal 
 function,
 not specific to D.)
In the Windows shell, the "pause" key will halt a program and "return" will resume it.
Jul 15 2014
prev sibling next sibling parent reply "rumbu" <rumbu rumbu.ro> writes:
On Tuesday, 15 July 2014 at 02:49:56 UTC, WhatMeWorry wrote:
 Sorry if this is an incredibly naive question.

 I prefer to pragmatically pause my programs periodically so 
 that I can peruse output statements. Ideally, I'd like to 
 continue by just hitting any old key. My feeble attempt below 
 requires I enter at least one character and then the enter key.

 char ignore;
 writeln("Enter to continue");
 readf(" %s", &ignore);

 Is there a way to continue with any old key press? or just the 
 enter key?

 Thanks in advance.
getch() reads any key and continues; On Windows you can pipe you executable with the "more" command to pause after each page: your.exe | more
Jul 15 2014
parent "Meta" <jared771 gmail.com> writes:
On Tuesday, 15 July 2014 at 10:22:52 UTC, rumbu wrote:
 getch() reads any key and continues;

 On Windows you can pipe you executable with the "more" command 
 to pause after each page: your.exe | more
Don't forget that getch() is also Windows-specific.
Jul 15 2014
prev sibling parent "Adam D. Ruppe" <destructionator gmail.com> writes:
On Tuesday, 15 July 2014 at 02:49:56 UTC, WhatMeWorry wrote:
 Is there a way to continue with any old key press? or just the 
 enter key?
Yeah. It is more complex than you'd think but my terminal library can do it: https://github.com/adamdruppe/arsd/blob/master/terminal.d Example usage: import terminal; void main() { auto terminal = Terminal(ConsoleOutputType.linear); // gives real time input capability auto input = RealTimeConsoleInput(&terminal, ConsoleInputFlags.raw); // write to them terminal.writeln("Press any key to exit"); // get a single key auto ch = input.getch(); terminal.writeln("Bye!"); } PS this is also described in my book http://www.packtpub.com/discover-advantages-of-programming-in-d-cookbook/book
Jul 15 2014