@@ -568,6 +568,10 @@ def __init__(self):
568568 self .width = 0
569569 self .height = 0
570570
571+ # [x, y, char, color, bg_color], ...
572+ # colors are in #000000 format or None
573+ self .data = []
574+
571575 self ._colors = {
572576 'A' : '#00cc00' ,
573577 'B' : '#00cc00' ,
@@ -613,17 +617,30 @@ def read(self, filename):
613617 self .width = max ([len (line ) for line in self .page ])
614618 self .height = len (self .page )
615619
620+ def parse (self ):
621+ lines = self .page
622+ self .data = []
623+
624+ for y , line in enumerate (lines ):
625+ for x , char in enumerate (line ):
626+ color = None
627+ bg_color = None
628+ if y < len (self .mask ):
629+ if x < len (self .mask [y ]):
630+ m = self .mask [y ][x ]
631+ color = self ._colors .get (m )
632+ bg_color = self ._bg_colors .get (m )
633+
634+ self .data .append ([x , y , char , color , bg_color ])
635+
616636 def apply_mask (self ):
617637
618638 self .panela = Panela (x = self .width , y = self .height )
619639 self .panela .read_ansi ("" .join ("%s\n " % x for x in self .page ))
620640
621- for i , line in enumerate (self .mask ):
622- for j , char in enumerate (line ):
623- if char in self ._colors or char in self ._bg_colors :
624- color = self ._colors .get (char )
625- bg_color = self ._bg_colors .get (char )
626- self .panela .put_point (j , i , color = color , background = bg_color )
641+ for x , y , _ , color , bg_color in self .data :
642+ if color or bg_color :
643+ self .panela .put_point (x , y , color = color , background = bg_color )
627644
628645 def show (self ):
629646
@@ -640,6 +657,7 @@ def main():
640657 pagepath = os .path .join (MYDIR , "share/firstpage-v2.pnl" )
641658 template = Template ()
642659 template .read (pagepath )
660+ template .parse ()
643661 template .apply_mask ()
644662 sys .stdout .write (template .show ())
645663
0 commit comments