Re: is there a way to pause a program and resume with just a key press (or enter key)

2014-07-15 Thread rumbu via Digitalmars-d-learn

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


Re: is there a way to pause a program and resume with just a key press (or enter key)

2014-07-15 Thread Meta via Digitalmars-d-learn

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.


Re: is there a way to pause a program and resume with just a key press (or enter key)

2014-07-15 Thread Adam D. Ruppe via Digitalmars-d-learn

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


Re: is there a way to pause a program and resume with just a key press (or enter key)

2014-07-15 Thread ponce via Digitalmars-d-learn


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.




is there a way to pause a program and resume with just a key press (or enter key)

2014-07-14 Thread WhatMeWorry via Digitalmars-d-learn

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.


Re: is there a way to pause a program and resume with just a key press (or enter key)

2014-07-14 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jul 15, 2014 at 02:49:55AM +, 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.