Article 6HDWP Making getch() in ncurses read from the terminal device

Making getch() in ncurses read from the terminal device

by
codeandfire
from LinuxQuestions.org on (#6HDWP)
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've read the TLDP How-to on ncurses and I've reasonably familiarized myself with the API. Currently, I'm facing only one specific problem.

A pager should be able to take input both from filename arguments, as in Code:$ pager foo.txt bar.txt ...and from standard input: Code:$ <command> | pagerBut, 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 read 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 from 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?

Thanks!
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments