Project

Profile

Help

Revision 6e91011c

Added by Francisco Del Roio about 2 years ago

Changes:

  • `OnMessage`: Now the '\r' characters are discarded.
  • `PostMessage`: All style data are class-level variables.

This fixes incorrect position of styles at all.

View differences:

src/accesspanel/extensions/ansi.py
122 122
            47: wx.WHITE,
123 123
        }
124 124

  
125
        # Position mark and style
126
        self.last_mark = None
127
        self.start_mark = None
128

  
125 129
    def OnClearOutput(self):
126 130
        """The output has been cleared."""
131

  
132
        # We must clear all data for styles
127 133
        self.modifiers = []
134
        self.start_mark = None
135
        self.last_mark = None
128 136

  
129 137
    def OnMessage(self, message):
130 138
        """Interpret the ANSI codes."""
......
215 223
                if message[char_index] == "\x1B":
216 224
                    ansi_stage = 2
217 225
                else:
218
                    clean_buffer += message[char_index]
226

  
227
                    # We must discard \r characters because it causes problems at formatting time
228
                    if message[char_index] != "\r":
229
                        clean_buffer += message[char_index]
219 230

  
220 231
            # Second stage: look for a validation character (an '[')
221 232
            elif ansi_stage == 2:
......
248 259
    def PostMessage(self, message):
249 260
        """Applies ANSI style to text"""
250 261

  
251
        start = None
252
        last_mark = None
253

  
254 262
        for point, style in self.modifiers:
255
            if not last_mark:
256
                last_mark = style
257
                start = point
263
            if not self.last_mark:
264
                self.last_mark = style
265
                self.start_mark = point
258 266
                continue
259 267

  
260 268
            # Unpack foreground and background from style tuple
261
            foreground, background = style
269
            foreground, background = self.last_mark
262 270

  
263
            self.panel.output.SetStyle(start, point, wx.TextAttr(
271
            self.panel.output.SetStyle(self.start_mark, point, wx.TextAttr(
264 272
                    foreground, background))
265 273

  
266
            start = point
267
            last_mark = style
274
            self.start_mark = point
275
            self.last_mark = style
268 276

  
269 277
        self.modifiers = []

Also available in: Unified diff