Thread overview
is there a way to pause a program and resume with just a key press (or enter key)
Jul 15, 2014
WhatMeWorry
Jul 15, 2014
H. S. Teoh
Jul 15, 2014
ponce
Jul 15, 2014
rumbu
Jul 15, 2014
Meta
Jul 15, 2014
Adam D. Ruppe
July 15, 2014
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.
July 15, 2014
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.
July 15, 2014
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
July 15, 2014
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.
July 15, 2014
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
July 15, 2014
>
> 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.