最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Python curses refresh issues when resizing terminal - Stack Overflow

programmeradmin1浏览0评论

With this example

#!/usr/bin/env python3

import curses

def repaint(stdscr,flog,wlog):
    flog.clear()
    wlog.clear()

# It seems flog and wlog autoresizing magicaly
#   flog.resize(curses.LINES, curses.COLS)
#   wlog.resize(curses.LINES-2, curses.COLS -2)
    flog.box()
    flog.refresh()
    wlog.refresh()

def main(stdscr):

    curses.curs_set(0)

    stdscr.nodelay(True)
    stdscr.keypad(True)
    stdscr.refresh()

    flog = curses.newwin(curses.LINES, curses.COLS, 0, 0)
    wlog= flog.derwin(curses.LINES-2, curses.COLS - 2, 1, 1)
    wlog.scrollok(True)
    repaint(stdscr,flog,wlog)

    wlog.addstr("Init application\n")
    wlog.refresh()

    finish = False

    while not finish:
        try:
            key = stdscr.getch()
            if key != -1:
                if key == 113 or key == 81:
                    finish = True
                elif key == curses.KEY_RESIZE:
                    curses.update_lines_cols()
                    repaint(stdscr,flog,wlog)
                    wlog.addstr("Resize\n")
                    wlog.refresh()

        except curses.error:
            pass

        except Exception :
            pass

if __name__ == "__main__":
    curses.wrapper(main)

  • When terminal window shrinks horizontally, the box and message are not showed.
  • When terminal window is enlarged horizontally, the box and message are showed but right vertical line is missing
  • When terminal window shrinks vertically, the box and message are showed but horizontal bottom line is missing
  • When terminal window is enlarged vertically, all run as expected.

Is there another way to refresh the screen?

发布评论

评论列表(0)

  1. 暂无评论