nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.55k stars 1.47k forks source link

Reading a single character in NimScript (without pressing Enter) #23141

Closed rgpublic closed 10 months ago

rgpublic commented 10 months ago

Summary

I've just started using NimScript and I want to replace existing Bash scripts. In Bash I can easily get a single character like Y/N. The user won't have to press Enter. I found this surprisingly hard to achieve in NimScript. It seems there's only readLineFromStdin() but this waits for a whole line. How can I read a single character? Isn't this possible?

Description

It'd be nice if getCh() or sth. like this was available in NimScript.

Alternatives

No response

Examples

No response

Backwards Compatibility

No response

Links

No response

Araq commented 10 months ago

It is not supported and my general advice is to replace Bash scripts with Nim programs, not with NimScript.

rgpublic commented 10 months ago

Okay, not exactly what I was expecting but OTOH I've followed your advice and I'm now using this shebang line:

!/usr/bin/env -S nim c --hints=off -r 

It works. And it solves a lot of problems I had with NimScript and stuff that doesn't exist there. Only ugly thing is the complicated shebang line. IMHO nim should auto-dect it's running from a script and use default arguments. But that's for another issue report one day ;-)

Thanks a lot for pointing me to the right direction! I wonder if NimScript should be abandoned altogether. It's just confusing for newbies. You can't even print a character without newline at the end because stdout is available etc etc. In its current state it's just a waste of time.