Browse Source

CoinAmt: amt formatting cleanups

The MMGen Project 1 week ago
parent
commit
acc71466ad
2 changed files with 25 additions and 8 deletions
  1. 24 7
      mmgen/amt.py
  2. 1 1
      mmgen/tw/prune.py

+ 24 - 7
mmgen/amt.py

@@ -88,19 +88,36 @@ class CoinAmt(Decimal, Hilite, InitErrors): # abstract class
 					a.rjust(iwidth) + ' ' + ''.ljust(prec or self.max_prec),
 					a.rjust(iwidth) + ' ' + ''.ljust(prec or self.max_prec),
 					color = color)
 					color = color)
 
 
+	# same as fmt(), only with color override:
+	def fmt2(self, iwidth=1, /, *, color=False, prec=None, color_override=''):
+		match str(self).split('.', 1):
+			case [a, b]:
+				return self.colorize2(
+					a.rjust(iwidth) + '.' + b.ljust(prec or self.max_prec)[:prec or self.max_prec],
+					color = color,
+					color_override = color_override)
+			case [a]:
+				return self.colorize2(
+					a.rjust(iwidth) + ' ' + ''.ljust(prec or self.max_prec),
+					color = color,
+					color_override = color_override)
+
 	def hl(self, *, color=True):
 	def hl(self, *, color=True):
 		return self.colorize(str(self), color=color)
 		return self.colorize(str(self), color=color)
 
 
+	def hl2(self, *, color=True, color_override=''):
+		return self.colorize2(str(self), color=color, color_override=color_override)
+
 	# fancy highlighting with coin unit, enclosure, formatting
 	# fancy highlighting with coin unit, enclosure, formatting
-	def hl2(self, *, color=True, unit=False, fs='{}', encl=''):
+	def hl3(self, *, color=True, unit=False, fs='{}', encl='', color_override=''):
 		res = fs.format(self)
 		res = fs.format(self)
-		return (
+		return self.colorize2(
 			encl[:-1]
 			encl[:-1]
-			+ self.colorize(
-				(res.rstrip('0').rstrip('.') if '.' in res else res) +
-				(' ' + self.coin if unit else ''),
-				color = color)
-			+ encl[1:])
+			+ (res.rstrip('0').rstrip('.') if '.' in res else res)
+			+ (' ' + self.coin if unit else '')
+			+ encl[1:],
+			color = color,
+			color_override = color_override)
 
 
 	def __str__(self): # format simply, with no exponential notation
 	def __str__(self): # format simply, with no exponential notation
 		return str(int(self)) if int(self) == self else self.normalize().__format__('f')
 		return str(int(self)) if int(self) == self else self.normalize().__format__('f')

+ 1 - 1
mmgen/tw/prune.py

@@ -91,7 +91,7 @@ class TwAddressesPrune(TwAddresses):
 					red('Address #{a} ({b}) has a balance of {c}!'.format(
 					red('Address #{a} ({b}) has a balance of {c}!'.format(
 						a = addrnum,
 						a = addrnum,
 						b = e.twmmid.addr,
 						b = e.twmmid.addr,
-						c = e.amt.hl2(color=False, unit=True))),
+						c = e.amt.hl3(color=False, unit=True))),
 					'[p]rune anyway, [P]rune all with balance, [s]kip, [S]kip all with balance: '),
 					'[p]rune anyway, [P]rune all with balance, [s]kip, [S]kip all with balance: '),
 				'used': md(
 				'used': md(
 					yellow('Address #{a} ({b}) is used!'.format(
 					yellow('Address #{a} ({b}) is used!'.format(