ncurses_def_shell_mode() 和 ncurses_def_prog_mode() 究竟做了什么?

What do ncurses_def_shell_mode() and ncurses_def_prog_mode() do exactly?

使用 php ncurses,我很想知道 ncurses_def_shell_mode()ncurses_def_prog_mode() 函数的具体作用。它们没有记录在 PHP 手册中,我在 man ncurses 中偶然发现的一点也没有帮助。

如果我调用 ncurses_def_shell_mode() 然后在调用 ncurses_end() 之前用 ncurses_reset_shell_mode() 重置,根据扩展的源代码应该在 ncurses 中调用 endwin,终端光标是还是有点迷路了。

<?php
ncurses_init(); // start ncurses window
ncurses_def_shell_mode();

sleep(2); // print some stuff here

ncurses_reset_shell_mode();

ncurses_end(); // clean up and get out
exit;
?>

我尝试了 ncurses_def_shell_mode()ncurses_def_prog_mode(),但不知何故,尽管正确调用了重置,但 window 在退出时没有正确重置。我是否误解了这些功能应该如何工作?我能够挖掘出很少的信息来更深入地了解它们的正确用法。

我知道 ncurses 可能已经过时了,但这只会让知道如何正确使用它变得更加困难。

这里的预期行为是在调用 ncurses_reset_shell_mode()ncurses_reset_prog_mode() 之后,shell 或 prog window 应该回到之前保存的状态。

实际行为似乎是 shell 在退出时处于中断状态。光标不会闪烁,键入不会在终端中显示任何内容。但是,终端正在正确接收输入,因为输入命令并按回车键仍然有效。

php ncurses is a wrapper around ncurses. The functions you are asking about are documented in more detail in the ncurses manual pages, e.g., curs_kernel(3x)。也就是说,这些函数 save/restore 终端模式 。这些对应于 termios 中的 curses 设置(终端 I/O 设置)。

终端 I/O 设置不包括闪烁的光标(这是使用特定于终端的转义序列完成的)。对于 echo,manual page 可以提供帮助:

The def_prog_mode and def_shell_mode routines save the current terminal modes as the "program" (in curses) or "shell" (not in curses) state for use by the reset_prog_mode and reset_shell_mode routines. This is done each screen context allocated by newterm().

当 ncurses 启动时,例如 initscr (ncurses_init()),它保存 shell-mode 并初始化 prog-mode,基本上将终端置于 raw 模式以更好地控制它。

你打给ncurses_def_shell_mode();

  • prog-mode 保存为 shell-mode,并且
  • "restoring" 使用 ncurses_reset_shell_mode();,
  • 它没有效果:终端保持原始模式,禁用回显。

延伸阅读: