Ver código fonte

Zoo! My turn at git fun... :(
Merge branch 'master' of ssh://bbs.red-green.com:8022/RedGreen/twgs-proxy

david 5 anos atrás
pai
commit
5188a56615
2 arquivos alterados com 41 adições e 3 exclusões
  1. 39 2
      boxes.py
  2. 2 1
      flexible.py

+ 39 - 2
boxes.py

@@ -61,7 +61,7 @@ class Boxes(object):
         },
     )
 
-    def __init__(self, size: int, color="", style=0):
+    def __init__(self, size: int, color="", style=0, start_nl=True):
         """ Construct box
 
         size is width of text inside the box.
@@ -71,11 +71,14 @@ class Boxes(object):
         If color is blank, we don't use the RESET_ALL.
 
         style=0  Is double lines.  
+        start_nl Should we start the top with a newline?
+
         FUTURE:  Support all line types.
         """
         self.size = size
         self.style = 0  # style
         self.color = color
+        self.start_nl = start_nl
 
         # default colors
         # self.c = merge(Style.BRIGHT + Fore.WHITE + Back.BLUE)
@@ -95,7 +98,11 @@ class Boxes(object):
             c = self.color
             r = self.r
         s = self.box_styles[self.style]
-        return self.nl + c + s["tl"] + s["top"] * self.size + s["tr"] + r + self.nl
+        if self.start_nl:
+            n = self.nl
+        else:
+            n = ""
+        return n + c + s["tl"] + s["top"] * self.size + s["tr"] + r + self.nl
 
     def middle(self):
         """ Output MIDDLE line.
@@ -138,3 +145,33 @@ class Boxes(object):
         s = self.box_styles[self.style]
         return c + s["bl"] + s["top"] * self.size + s["br"] + r + self.nl
 
+    @staticmethod
+    def alert(message, length=0, pad=2, width=78, base="red"):
+        if base == "red":
+            color = merge(Style.BRIGHT + Fore.YELLOW + Back.RED)
+        elif base == "blue":
+            color = merge(Style.BRIGHT + Fore.YELLOW + Back.BLUE)
+        elif base == "green":
+            color = merge(Style.BRIGHT + Fore.YELLOW + Back.GREEN)
+        elif base == "cyan":
+            color = merge(Style.BRIGHT + Fore.YELLOW + Back.CYAN)
+        elif base == "magenta":
+            color = merge(Style.BRIGHT + Fore.YELLOW + Back.MAGENTA)
+        else:
+            # I don't know.
+            color = Style.RESET_ALL
+
+        if length == 0:
+            length = len(message)
+        box_size = length + pad * 2
+        boxpad = " " * pad
+        box = Boxes(box_size, color=color, start_nl=False)
+        msg = "{0}{1}{2}{3}".format(color, boxpad, message, boxpad)
+
+        # How much pad to add to the left side?
+        left_pad = (width - box_size + 2) // 2
+        pad = " " * left_pad
+        return "{0}{1}{2}{3}{4}{5}".format(
+            pad, box.top(), pad, box.row(msg), pad, box.bottom()
+        )
+

+ 2 - 1
flexible.py

@@ -1753,7 +1753,8 @@ class ProxyMenu(object):
 
         elif key == "X":
             self.queue_game.put(self.c + key + self.r + self.nl)
-            self.queue_game.put("Proxy done." + self.nl)
+            self.queue_game.put(Boxes.alert("Proxy done.", base="green"))
+            # self.queue_game.put("Proxy done." + self.nl)
             self.observer.load(self.save)
             self.save = None
             # It isn't running (NOW), so don't try to stop it.