获取输入并将其打印到 window 上的简单方法
easy way to get and print input onto window
我正在使用 ncurses 在 C 中开发一个应用程序,我想要一个可以获取用户输入的框,唯一的问题是,我找不到一种方法来按照我需要的方式工作。
例如,我最接近的是 mvwgetnstr()
例程,但是这并没有像我希望的那样将输入的字符打印回 window。我已经搜索了很长时间,但我找不到任何东西。
感谢您的帮助!
编辑:澄清一下,我需要一个像 mvwgetnstr()
这样的例程,只是将输入打印回 window。
getstr
手册页告诉您:
Characters input are echoed only if echo
is currently on. In that
case, backspace is echoed as deletion of the previous character (typically a left motion).
echo
手册页为您提供了更多信息:
The echo and noecho routines control whether characters typed by the
user are echoed by getch(3x) as they are typed. Echoing by the tty
driver is always disabled, but initially getch
is in echo mode, so
characters typed are echoed. Authors of most interactive programs prefer to do their own echoing in a controlled area of the screen, or not
to echo at all, so they disable echoing by calling noecho
. [See
curs_getch(3x) for a discussion of how these routines interact with
cbreak
and nocbreak
.]
ncurses 手册页建议 initializing 使用 noecho
;您的程序可以随时关闭(或打开)它。
我正在使用 ncurses 在 C 中开发一个应用程序,我想要一个可以获取用户输入的框,唯一的问题是,我找不到一种方法来按照我需要的方式工作。
例如,我最接近的是 mvwgetnstr()
例程,但是这并没有像我希望的那样将输入的字符打印回 window。我已经搜索了很长时间,但我找不到任何东西。
感谢您的帮助!
编辑:澄清一下,我需要一个像 mvwgetnstr()
这样的例程,只是将输入打印回 window。
getstr
手册页告诉您:
Characters input are echoed only if
echo
is currently on. In that case, backspace is echoed as deletion of the previous character (typically a left motion).
echo
手册页为您提供了更多信息:
The echo and noecho routines control whether characters typed by the user are echoed by getch(3x) as they are typed. Echoing by the tty driver is always disabled, but initially
getch
is in echo mode, so characters typed are echoed. Authors of most interactive programs prefer to do their own echoing in a controlled area of the screen, or not to echo at all, so they disable echoing by callingnoecho
. [See curs_getch(3x) for a discussion of how these routines interact withcbreak
andnocbreak
.]
ncurses 手册页建议 initializing 使用 noecho
;您的程序可以随时关闭(或打开)它。