-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAsciiDrawer.py
89 lines (77 loc) · 3.68 KB
/
AsciiDrawer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
"""
____________
/ \--------------------------
| when program starts |
|--- --------------------------------
| \__/ |
| forever |
| |--- --------------------------------
| | \__/ |
| | wait (13) seconds |
| |--- --------------------------------
| | \__/ |
| | set status light to [GREEN] |
| ---- ----------------------------
| \__/ |
| ^ |
|___ ________________________________
\__/
"""
class AsciiDrawer:
def __init__(self, codeImpl):
self.blockLength = 60
self.levelShiftSize = 8
self.notchSize = 5
self.concatenateBlocks = True
self.codeImpl = codeImpl
def addLine(self, line):
level_indicator_unit = "|" + (self.levelShiftSize - 1) * " "
level_indicator = level_indicator_unit * self.codeImpl.level
self.codeImpl.code += "{}{}\n".format(level_indicator, line)
def removeLastBlockTail(self):
if self.concatenateBlocks and self.codeImpl.code!= '':
self.codeImpl.code = "\n".join(self.codeImpl.code.split("\n")[:-3])
self.codeImpl.code += "\n"
def drawNotchLine(self, char, level, openRoof=False):
# level = 0 :
# |___ ________________________________
# level = 1 : openRoof defines if there is spaces between the start of the text line and
# the start of the notch line
# | ___ ____________________________
# /\ here
# @todo Improve. Way too complicated. For c_end, openRoof is way too dirty
block_begin = "|" + char * (self.levelShiftSize - 1)
if openRoof:
block_begin = "|" + (self.levelShiftSize - 1) * " " + (level - 1) * " " * (self.levelShiftSize - 2)
endNb = self.blockLength - len(block_begin) - (self.notchSize * level) - self.notchSize
self.addLine(block_begin
+ (char * self.notchSize) * level # Potential block spacing
+ (" " * self.notchSize) # Notch empty zone
+ endNb * char) # Block end
def drawUpperNotch(self, level, openRoof=False):
self.drawNotchLine("-", level, openRoof)
# | \___/ |
self.addLine("|" + " " * (self.levelShiftSize - 1) +
" " * self.levelShiftSize * level +
"\\" + '_' * (self.notchSize - 2) + "/" +
" " * (self.blockLength - self.notchSize - (self.levelShiftSize * level) - self.levelShiftSize - 1)
+ "|")
def drawLowerNotch(self, level):
self.drawNotchLine("_", level)
# \___/ |
self.addLine(" " * self.levelShiftSize +
(" " * self.notchSize) * level +
"\\" + '_' * (self.notchSize - 2) + "/")
def drawHatTop(self):
hat_size = 12
self.addLine(" " + hat_size * "_")
self.addLine("/" + hat_size * " " + "\\" + "-" * (self.blockLength - hat_size - 2))
def drawHatBlock(self, functionText):
self.drawHatTop()
self.addLine("| " + functionText + (self.blockLength - len(functionText) - 3) * " " + "|")
self.drawLowerNotch(0)
def drawStackBlock(self, functionText, upNotchLevel=0, lowNotchLevel=0, openRoof=False):
self.removeLastBlockTail()
self.drawUpperNotch(upNotchLevel, openRoof)
self.addLine("| " + functionText + (self.blockLength - len(functionText) - 3) * " " + "|")
self.drawLowerNotch(lowNotchLevel)