Drawing a colored, formatted box with Pastel and Cleo
lighth7015 opened this issue · comments
Robert Butler commented
Pastel is wonderful, however I'm trying to draw a UTF-8 box and not have the bounds become warped.
Sample command-
from cleo import Application, Command
from pastel import Pastel
class BoxDrawCommand(Command):
"""
Draws a box.
box:draw
"""
def box(self, text, **keyword):
contents, p = text.split("\n"), Pastel()
length = len(p.colorize(max(contents, key = len))) + 4
self.line( "\n┌{}┐".format( "─" * ( (length + 1) * 2 )))
for line in contents:
pos = 1 if len(line) is 0 else len(line) + 2
style = keyword.get( "style", "info" )
self.line("│<{}> {} </>│".format( style, line.ljust(pos)))
self.line( "└{}┘\n".format( "─" * length ))
def handle(self):
self.box( "Email client", style = "comment" )
app = Application()
app.add(BoxDrawCommand())
if __name__ == '__main__':
app.run()
Any suggestions for fixing the top and bottom box border drawing?