我正在使用
Python cmd模块来创建CLI应用程序.一切都很棒!但是,我正在尝试将应用程序定制为某种类型的存在:文本颜色,标题,使用字母数字字符作为边框等.
有没有一种标准的方法来创建屏幕溢出的类型:我设置边框和颜色标题的屏幕顶部保持静态?从屏幕中间或其左侧,一直到屏幕底部,在提示符处输入的任何文本或命令将在到达标题/边框时停止显示.基本上,我所追求的是用户总是看到标题/边框,除非他们退出CLI应用程序.如果他们输入帮助,他们当然会看到标题/边框下方的命令.但是,当他们输入命令时,理想情况下,命令菜单将在屏幕标题/边框后面消失.
我能够实现这一目标的最佳方向是值得赞赏的.
检查
curses
您应该能够使用颜色和静态边框来装饰CLI /终端.
我从HERE获得了扩展的例子:
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,-1) curses.init_pair(2,1,-1) curses.init_pair(3,2,-1) curses.init_pair(4,-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)