Fixed header and footer with ncurses?
I'm trying out ncurses for the first time (via UniCurses for Python). I'm trying to design a console application with a fixed header and footer but the documentation isn't clear on how I would go about doing this. Would I use a window? A panel? Something else? I've figured out how to give a string of text it's own foreground and background colors, but don't know how to extend that for the entire length of the console window. For an idea of what I'm trying to do, look at these cmus screensho开发者_如何学JAVAts:
http://cmus.sourceforge.net/#home
The blue header at the top and blue and white footer at the bottom is what i'm trying to get at. Thanks!
Alright, figured it out. Sub-windows to the rescue:
init_pair(1, COLOR_BLACK, COLOR_WHITE)
header = subwin(stdscr, 1, 80, 0, 0)
wattron(header, COLOR_PAIR(1))
waddstr(header, "Title")
wbkgd(header, COLOR_PAIR(1))
wattroff(header, COLOR_PAIR(1))
There might be a better way to do this, but it's a solution.
With Python Curses Module
initialize curses and give it a color to use
from curses import *
stdscr = initscr()
start_color()
init_pair(1,COLOR_RED,COLOR_WHITE)
get screen width and screen height
max_y, max_x = stdscr.getmaxyx()
create the subwindow header with the maximum width of terminal
header = stdscr.subwin(1, max_x, 0, 0)
color the header background and text within it
header.bkgd(color_pair(1))
wtv you want it to say
header.addstr('Header Text')
show everything
header.refresh()
精彩评论