I am making a python program that makes heavy use of the curses.textpad.rectangle function. It draws a rectangle using ─┐│
characters. I would like to know if I could use any other characters as a border. I don't think the function itself supports it, so are there any other functions I could use?
For example, this code uses single lines for the border:
from curses.textpad import rectangle
from curses import wrapper
@wrapper
def main(stdscr):
rectangle(stdscr, 2, 2, 10, 10)
I want to use double lines (using =#║
symbols). How can I achieve this?
The rectangle code shouldn't be too difficult to rewrite to do what you want:
def rectangle(win, uly, ulx, lry, lrx):
"""Draw a rectangle with corners at the provided upper-left
and lower-right coordinates.
"""
win.vline(uly+1, ulx, curses.ACS_VLINE, lry - uly - 1)
win.hline(uly, ulx+1, curses.ACS_HLINE, lrx - ulx - 1)
win.hline(lry, ulx+1, curses.ACS_HLINE, lrx - ulx - 1)
win.vline(uly+1, lrx, curses.ACS_VLINE, lry - uly - 1)
win.addch(uly, ulx, curses.ACS_ULCORNER)
win.addch(uly, lrx, curses.ACS_URCORNER)
win.addch(lry, lrx, curses.ACS_LRCORNER)
win.addch(lry, ulx, curses.ACS_LLCORNER)
change (monkey patch) the curses.ACS_* or rewrite this function to, say, double_line_rectangle(...) and put the character you want in the curses.X spot. like this:
def rectangle(win, uly, ulx, lry, lrx):
"""Draw a double-line rectangle with corners at the provided upper-left
and lower-right coordinates.
"""
win.vline(uly+1, ulx, u'\u2551', lry - uly - 1)
win.hline(uly, ulx+1, u'\u2551', lrx - ulx - 1)
win.hline(lry, ulx+1, u'\u2551', lrx - ulx - 1)
win.vline(uly+1, lrx, u'\u2551', lry - uly - 1)
win.addch(uly, ulx, u'\u2554')
win.addch(uly, lrx, u'\u2557')
win.addch(lry, lrx, u'\u255D')
win.addch(lry, ulx, u'\u255A')
Here's a lookup for all the cool unicode characters for drawing boxes