如何在Python CMD线应用程序上创建静态标题/边框



我正在使用Python CMD模块创建CLI应用程序。一切都很好!但是,我正在尝试将应用程序定制为某种类型的存在:文本颜色,标题,使用alpha-numeric字符作为边界等。

是否有一种标准的方式来创建一种屏幕覆盖的屏幕:我设置边框和颜色标题保持静态的屏幕顶部?从屏幕的中间,或者说,从屏幕的底部到屏幕的底部,在到达标题/边界时,在提示符处输入的任何文本或命令都将不再可见。基本上,我所追求的是用户始终查看标题/边框,除非他们退出CLI应用程序。当然,如果他们键入帮助,他们会看到标题/边界下方的命令。但是,当他们输入命令时,理想情况下,命令菜单将消失在屏幕标题/边框后面。

以最佳方式我能实现的任何方向。

检查诅咒

您应该能够用颜色和静态边界装饰CLI/终端。

我从这里取了扩展示例:

import curses
from multiprocessing import Process
p = None
def display(stdscr):
    stdscr.clear()
    stdscr.timeout(500)
    maxy, maxx = stdscr.getmaxyx()
    curses.newwin(2,maxx,3,1)
    # invisible cursor
    curses.curs_set(0)
    if (curses.has_colors()):
        # Start colors in curses
        curses.start_color()
        curses.use_default_colors()
        curses.init_pair(1, curses.COLOR_RED, -1)
    stdscr.refresh()
    curses.init_pair(1, 0, -1)
    curses.init_pair(2, 1, -1)
    curses.init_pair(3, 2, -1)
    curses.init_pair(4, 3, -1)
    bottomBox = curses.newwin(8,maxx-2,maxy-8,1)
    bottomBox.box()
    bottomBox.addstr("BottomBox")
    bottomBox.refresh()
    bottomwindow = curses.newwin(6,maxx-4,maxy-7,2)
    bottomwindow.addstr("This is my bottom view", curses.A_UNDERLINE)
    bottomwindow.refresh()
    stdscr.addstr("{:20s}".format("Hello world !"), curses.color_pair(4))
    stdscr.refresh()
    while True:
        event = stdscr.getch()
        if event == ord("q"):
            break
def hang():
    while True:
        temp = 1 + 1
if __name__ == '__main__':
    p = Process(target = hang)
    curses.wrapper(display)

相关内容

最新更新