How to create a static header / border in a Python application for cmd

I am using the cmd module for Python to create a CLI application. Everything works great! However, I am trying to adapt the application to a certain type of presence: text colors, names, using alphanumeric characters as borders, etc.

Is there a standard way to create a screen overflow: does the top of the screen where I set the border and color caption remain static? And from the middle of the screen, or near it, up to the bottom of the screen, any text or commands entered in the tooltip will cease to be visible as the title / border is reached. Basically, for me, I should always see the header / border if they do not exit the CLI application. If they get help, of course, they will see teams below the header / border. But when you enter commands, ideally, the command menu disappears behind the title / screen border.

Any direction in which I can achieve this is appreciated.

+5
source share
1 answer

Check curses

You should be able to decorate the CLI / Terminal with colors and static borders.

I added an example from 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, 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) 
+3
source

Source: https://habr.com/ru/post/1275490/


All Articles