How can I respond to a key press, without a CRLF, in Raku?
Asked Answered
J

1

8

I would like to implement:

Press any key to continue...

That responds to, well, any key without pressing the Return or Enter key.

Term::ReadKey does not implement this behavior. It requires a CRLF.

I'm using iTerm2.

[19] > $*KERNEL
darwin
[20] > $*DISTRO
macos (13.0.1)
[21] > $*RAKU
Raku (6.d)
[22] > $*VM
moar (2022.12)
Jube answered 23/12, 2022 at 2:0 Comment(3)
Raku has prompt, but I don't believe it suits your requirements.Novercal
Windows-only: raku -MNativeCall -e"sub _getch(--> int32) is native(q|msvcrt|) {*}; print q|press any key to continue...| andthen _getch;"Fumed
Aiui the terminal API (for any consumer, eg any programming language) only allows that sort of thing if you use "raw" or "rare" modes see Wikipedia, and, conversely, if you do that, you can do more or less anything you want to. If I'm right, then I presume the things to consider include relevant SO Qs (eg [raku] ones) and/or existing packages that support raw mode -- either Raku ones? or foreign ones (a plain C lib would likely be most appropriate).Decibel
M
5

I think you will have to use a module to be able to do that in Raku. Term::termios comes to mind.

Monmouthshire answered 23/12, 2022 at 10:52 Comment(1)
There is also Terminal::Print and family. CAVEAT: Using raw input like this will put your terminal into raw mode, which means that...at minimum... you will need to use "\r\n" instead of just "\n" when outputting to the terminal.Hallvard

© 2022 - 2024 — McMap. All rights reserved.