subwin windows 应该比内容大一号吗

Should subwin windows be one size larger than content

我有下面的一段代码,除非 n_rows > 3n_cols > 3 否则无法运行。否则我会收到此错误:

    Traceback (most recent call last):
      File "script.py", line 16, in <module>
        curses.wrapper(main)
      File "/usr/lib/python3.8/curses/__init__.py", line 105, in wrapper
        return func(stdscr, *args, **kwds)
      File "script.py", line 10, in main
        window.addstr(2, 2, '2')
    _curses.error: addwstr() returned ERR

这种类型的错误通常发生在 window 外部打印时(这里不是这种情况)。

    def main(stdscr):
        n_rows = 3
        n_cols = 3
        window = stdscr.subwin(n_rows, n_cols, 0, 0)
        window.addstr(0, 0, '0')
        window.addstr(1, 1, '1')
        window.addstr(2, 2, '2')
    
        stdscr.getch()
    
    
    if __name__ == '__main__':
        curses.wrapper(main)

我的问题是,如何解释 window 必须大一号才能正常工作?

程序正在 window 和 returns 的右下角打印错误,因为它无法换行(或向上滚动)。

addch 联机帮助页说

  • If scrollok is not enabled, writing a character at the lower right margin succeeds. However, an error is returned because it is not possible to wrap to a new line

scrollok(除非明确设置,否则为 false):

The scrollok option controls what happens when the cursor of a window is moved off the edge of the window or scrolling region, either as a result of a newline action on the bottom line, or typing the last character of the last line. If disabled, (bf is FALSE), the cursor is left on the bottom line. If enabled, (bf is TRUE), the window is scrolled up one line (Note that to get the physical scrolling effect on the terminal, it is also necessary to call idlok).