8000 improve text color handling · RPellowski/spatialmath-python@b3df7a4 · GitHub
[go: up one dir, main page]

Skip to content

Commit b3df7a4

Browse files
committed
improve text color handling
1 parent 66f5d02 commit b3df7a4

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

spatialmath/super_pose.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -596,10 +596,21 @@ def _string(self, color=False, tol=500):
596596
597597
"""
598598
#print('in __str__', _color)
599-
600-
def FG(c): return fg(c) if _color else ''
601-
def BG(c): return bg(c) if _color else ''
602-
def ATTR(c): return attr(c) if _color else ''
599+
600+
if _color:
601+
# bgcol = bg('grey_93')
602+
bgcol = ''
603+
trcol = fg('blue')
604+
rotcol = fg('red')
605+
constcol = fg('grey_50')
606+
reset = attr(0)
607+
indexcol = bg('yellow_2')
608+
else:
609+
bgcol = ''
610+
trcol = ''
611+
rotcol = ''
612+
constcol = ''
613+
reset = ''
603614

604615
def mformat(self, X):
605616
# X is an ndarray value to be display
@@ -620,15 +631,15 @@ def mformat(self, X):
620631
if rownum < n:
621632
if colnum < n:
622633
# rotation part
623-
s = FG('red') + BG('grey_93') + s + ATTR(0)
634+
s = rotcol + bgcol + s + reset
624635
else:
625636
# translation part
626-
s = FG('blue') + BG('grey_93') + s + ATTR(0)
637+
s = trcol + bgcol + s + reset
627638
else:
628639
# bottom row
629-
s = FG('grey_50') + BG('grey_93') + s + ATTR(0)
640+
s = constcol + bgcol + s + reset
630641
rowstr += s
631-
out += rowstr + BG('grey_93') + ' ' + ATTR(0) + '\n'
642+
out += rowstr + bgcol + ' ' + reset + '\n'
632643
return out
633644

634645
output_str = ''
@@ -642,7 +653,8 @@ def mformat(self, X):
642653
# sequence case
643654
for count, X in enumerate(self.data):
644655
# add separator lines and the index
645-
output_str += FG('green') + '[{:d}] =\n'.format(count) + ATTR(0) + mformat(self, X)
656+
output_str += indexcol + '[{:d}] ='.format(count) + reset \
657+
+ '\n' + mformat(self, X)
646658

647659
return output_str
648660

0 commit comments

Comments
 (0)
0