Finish the straight line box drawing characters
This commit is contained in:
parent
334541e8dc
commit
8424f55177
@ -18,13 +18,92 @@ def half_hline(buf, width, height, level=1, which='left'):
|
||||
sz = thickness(level=level, horizontal=True)
|
||||
start = height // 2 - sz // 2
|
||||
for y in range(start, start + sz):
|
||||
offset = y * width
|
||||
for x in (range(0, width // 2) if which == 'left' else range(width // 2, width)):
|
||||
buf[y * width + x] = 255
|
||||
buf[offset + x] = 255
|
||||
|
||||
|
||||
def half_vline(buf, width, height, level=1, which='top'):
|
||||
sz = thickness(level=level, horizontal=False)
|
||||
start = width // 2 - sz // 2
|
||||
for x in range(start, start + sz):
|
||||
for y in (range(0, height // 2) if which == 'top' else range(height // 2, height)):
|
||||
buf[x + y * width] = 255
|
||||
|
||||
|
||||
def get_holes(sz, hole_sz, num):
|
||||
if num == 1:
|
||||
pts = [sz // 2]
|
||||
elif num == 2:
|
||||
pts = (sz // 3, 2 * (sz // 3))
|
||||
elif num == 3:
|
||||
pts = (sz // 4, sz // 2, 3 * (sz // 4))
|
||||
holes = []
|
||||
for c in pts:
|
||||
holes.append(tuple(range(c - hole_sz // 2, c - hole_sz // 2 + hole_sz)))
|
||||
return holes
|
||||
|
||||
|
||||
def add_hholes(buf, width, height, level=1, num=1, hole_sz=3):
|
||||
line_sz = thickness(level=level, horizontal=True)
|
||||
hole_sz = thickness(level=hole_sz, horizontal=False)
|
||||
start = height // 2 - line_sz // 2
|
||||
holes = get_holes(width, hole_sz, num)
|
||||
for y in range(start, start + line_sz):
|
||||
offset = y * width
|
||||
for hole in holes:
|
||||
for x in hole:
|
||||
buf[offset + x] = 0
|
||||
|
||||
|
||||
def add_vholes(buf, width, height, level=1, num=1, hole_sz=3):
|
||||
line_sz = thickness(level=level, horizontal=False)
|
||||
hole_sz = thickness(level=hole_sz, horizontal=True)
|
||||
start = width // 2 - line_sz // 2
|
||||
holes = get_holes(height, hole_sz, num)
|
||||
for x in range(start, start + line_sz):
|
||||
for hole in holes:
|
||||
for y in hole:
|
||||
buf[x + width * y] = 0
|
||||
|
||||
|
||||
def hline(*a, level=1):
|
||||
half_hline(*a, level=level)
|
||||
half_hline(*a, level=level, which='right')
|
||||
|
||||
|
||||
def vline(*a, level=1):
|
||||
half_vline(*a, level=level)
|
||||
half_vline(*a, level=level, which='bottom')
|
||||
|
||||
|
||||
def hholes(*a, level=2, num=1):
|
||||
hline(*a, level=level)
|
||||
add_hholes(*a, level=level, num=num)
|
||||
|
||||
|
||||
def vholes(*a, level=1, num=1):
|
||||
vline(*a, level=level)
|
||||
add_vholes(*a, level=level, num=num)
|
||||
|
||||
|
||||
box_chars = {
|
||||
'─': [half_hline, p(half_hline, which='right')],
|
||||
'━': [p(half_hline, level=3), p(half_hline, level=3, which='right')],
|
||||
'─': [hline],
|
||||
'━': [p(hline, level=3)],
|
||||
'│': [vline],
|
||||
'┃': [p(vline, level=3)],
|
||||
'╌': [hholes],
|
||||
'╍': [p(hholes, level=3)],
|
||||
'┄': [p(hholes, num=2)],
|
||||
'┅': [p(hholes, num=2, level=3)],
|
||||
'┈': [p(hholes, num=3)],
|
||||
'┉': [p(hholes, num=3, level=3)],
|
||||
'╎': [vholes],
|
||||
'╏': [p(vholes, level=3)],
|
||||
'┆': [p(vholes, num=2)],
|
||||
'┇': [p(vholes, num=2, level=3)],
|
||||
'┊': [p(vholes, num=3)],
|
||||
'┋': [p(vholes, num=3, level=3)],
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user