How to read a single character in D language?

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Nov 19 23:03:39 UTC 2021


On Fri, Nov 19, 2021 at 10:21:42PM +0000, Adam Ruppe via Digitalmars-d-learn wrote:
[...]
> The OS functions for getch alone though are actually pretty simple:
> 
> 1) change the terminal to "raw" mode. the default is to buffer lines,
> which means your application doesn't get anything until a line is
> complete. You need to turn that off.
[...]
> 2) Read the terminal's event stream.
[...]
> 3) Again, remember to set it back how you found it before you exit by
> callling the SetConsoleMode/tcsetattr again before you exit.

And *this* is why you want to use a library for this.  Doing this by
hand is certainly possible, but very tedious, error-prone, and requires
a lot of knowledge about OS system calls.  Why bother when you could
just drop arsd.terminal into your workspace and call it a day?  :-)

(Of course, learning how things work under the hood for the sake of
educating yourself is definitely worthwhile. Just don't do that when you
need to get stuff done.)


T

-- 
Let's not fight disease by killing the patient. -- Sean 'Shaleh' Perry


More information about the Digitalmars-d-learn mailing list