Making getch() read from the terminal device

Saniya Maheshwari <[email protected]> Sun, 24 Dec 2023 12:42:42 +0000 (UTC)
Newsgroups gmane.comp.lib.ncurses.general
Message-ID <[email protected]>
------=_Part_1882364_1969660443.1703421762407
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit

Hi,
As a project that I've set myself, I'm working on a simple pager, such as "less". Of course it would be best practice to build this pager on top of ncurses. It's my first time working with ncurses, though I find the API quite easy to understand and I've familiarised myself with it. I'm facing one specific problem for which I'm not able to find a solution:
A pager should be able to take input both from filename arguments:
$ pager foo.txt bar.txt ...
and from standard input:
$ <command> | pager
But a pager's key commands, such as Space for one screenful forward and the b key for one screenful backward, also have to be intercepted, and if the pager's input comes from stdin then it can't intercept these keys by reading stdin.
My reference is an old Unix implementation of a pager, and the idea used there to intercept these keys is to read from the terminal device directly (and not stdin).
As I understand, getch() is the standard way of getting character input in ncurses. Is there any way to make getch() read from the terminal device and not stdin?
I would be grateful for any help!
Thanks,Saniya


------=_Part_1882364_1969660443.1703421762407
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div id=3D"yiv5713615991">Hi,<div><br></div><div>As a project that I've set=
 myself, I'm working on a simple pager, such as "less". Of course it would =
be best practice to build this pager on top of ncurses. It's my first time =
working with ncurses, though I find the API quite easy to understand and I'=
ve familiarised myself with it. I'm facing one specific problem for which I=
'm not able to find a solution:</div><div><br></div><div>A pager should be =
able to take input both from filename arguments:</div><div><br></div><div>$=
 pager foo.txt bar.txt ...</div><div><br></div><div>and from standard input=
:</div><div><br></div><div>$ &lt;command&gt; | pager</div><div><br></div><d=
iv>But a pager's key commands, such as Space for one screenful forward and =
the b key for one screenful backward, also have to be intercepted, and if t=
he pager's input comes from stdin then it can't intercept these keys by rea=
ding stdin.</div><div><br></div><div>My reference is an old Unix implementa=
tion of a pager, and the idea used there to intercept these keys is to read=
 from the terminal device directly (and not stdin).</div><div><br></div><di=
v>As I understand, getch() is the standard way of getting character input i=
n ncurses. Is there any way to make getch() read from the terminal device a=
nd not stdin?</div><div><br></div><div>I would be grateful for any help!</d=
iv><div><br></div><div>Thanks,</div><div>Saniya</div><div><br></div><div><b=
r></div></div>
------=_Part_1882364_1969660443.1703421762407--