[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [arm/master] Drop panel's unused addfstr()



commit 45177461ecd9a6d9a930939fa1525d379584bb09
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Thu Apr 9 10:15:10 2015 -0700

    Drop panel's unused addfstr()
    
    Psudo-html for curses, how could it go wrong? What can I say, sounded like a
    good idea at the time.
    
    In more seriousness this was an experiment to simplify curses' clunky
    interface, so rather than...
    
      addstr(0, 0, 'name: ')
      addstr(0, 6, person, Format.BOLD)
      addstr(0, 6 + len(person), ' <- neat guy')
    
    ... you could do...
    
      addfstr(0, 0, 'name: <b>%s</b> <- neat guy' % person)
    
    We no longer use it since... well, ick! But it was a fine experiment.
---
 nyx/util/panel.py |  102 -----------------------------------------------------
 1 file changed, 102 deletions(-)

diff --git a/nyx/util/panel.py b/nyx/util/panel.py
index bd20de7..2841fe3 100644
--- a/nyx/util/panel.py
+++ b/nyx/util/panel.py
@@ -40,15 +40,6 @@ def _no_op(arg):
   return arg
 
 
-FORMAT_TAGS = {
-  '<b>': (_no_op, curses.A_BOLD),
-  '<u>': (_no_op, curses.A_UNDERLINE),
-  '<h>': (_no_op, curses.A_STANDOUT),
-}
-
-for color_label in ui_tools.COLOR_LIST:
-  FORMAT_TAGS['<%s>' % color_label] = (ui_tools.get_color, color_label)
-
 # prevents curses redraws if set
 HALT_ACTIVITY = False
 
@@ -540,99 +531,6 @@ class Panel(object):
 
     return x
 
-  def addfstr(self, y, x, msg):
-    """
-    Writes string to subwindow. The message can contain xhtml-style tags for
-    formatting, including:
-    <b>text</b>               bold
-    <u>text</u>               underline
-    <h>text</h>               highlight
-    <[color]>text</[color]>   use color (see ui_tools.get_color() for constants)
-
-    Tag nesting is supported and tag closing is strictly enforced (raising an
-    exception for invalid formatting). Unrecognized tags are treated as normal
-    text. This should only be called from the context of a panel's draw method.
-
-    Text in multiple color tags (for instance '<blue><red>hello</red></blue>')
-    uses the bitwise OR of those flags (hint: that's probably not what you
-    want).
-
-    Arguments:
-      y    - vertical location
-      x    - horizontal location
-      msg  - formatted text to be added
-    """
-
-    if self.win and self.max_y > y:
-      formatting = [curses.A_NORMAL]
-      expected_close_tags = []
-      unused_msg = msg
-
-      while self.max_x > x and len(unused_msg) > 0:
-        # finds next consumeable tag (left as None if there aren't any left)
-
-        next_tag, tag_start, tag_end = None, -1, -1
-
-        tmp_checked = 0  # portion of the message cleared for having any valid tags
-        expected_tags = FORMAT_TAGS.keys() + expected_close_tags
-
-        while next_tag is None:
-          tag_start = unused_msg.find('<', tmp_checked)
-          tag_end = unused_msg.find('>', tag_start) + 1 if tag_start != -1 else -1
-
-          if tag_start == -1 or tag_end == -1:
-            break  # no more tags to consume
-          else:
-            # check if the tag we've found matches anything being expected
-            if unused_msg[tag_start:tag_end] in expected_tags:
-              next_tag = unused_msg[tag_start:tag_end]
-              break  # found a tag to use
-            else:
-              # not a valid tag - narrow search to everything after it
-              tmp_checked = tag_end
-
-        # splits into text before and after tag
-
-        if next_tag:
-          msg_segment = unused_msg[:tag_start]
-          unused_msg = unused_msg[tag_end:]
-        else:
-          msg_segment = unused_msg
-          unused_msg = ''
-
-        # adds text before tag with current formatting
-
-        attr = 0
-
-        for text_format in formatting:
-          attr |= text_format
-
-        self.win.addstr(y, x, msg_segment[:self.max_x - x - 1], attr)
-        x += len(msg_segment)
-
-        # applies tag attributes for future text
-
-        if next_tag:
-          format_tag = '<' + next_tag[2:] if next_tag.startswith('</') else next_tag
-          format_match = FORMAT_TAGS[format_tag][0](FORMAT_TAGS[format_tag][1])
-
-          if not next_tag.startswith('</'):
-            # open tag - add formatting
-            expected_close_tags.append('</' + next_tag[1:])
-            formatting.append(format_match)
-          else:
-            # close tag - remove formatting
-            expected_close_tags.remove(next_tag)
-            formatting.remove(format_match)
-
-      # only check for unclosed tags if we processed the whole message (if we
-      # stopped processing prematurely it might still be valid)
-
-      if expected_close_tags and not unused_msg:
-        # if we're done then raise an exception for any unclosed tags (tisk, tisk)
-        base_msg = 'Unclosed formatting tag%s:' % ('s' if len(expected_close_tags) > 1 else '')
-        raise ValueError("%s: '%s'\n  \"%s\"" % (base_msg, "', '".join(expected_close_tags), msg))
-
   def getstr(self, y, x, initial_text = '', text_format = None, max_width = None, validator = None):
     """
     Provides a text field where the user can input a string, blocking until

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits