Esempio n. 1
0
    def _generate_lines(self, starty, startx):
        i = starty
        if not self.source:
            return
        while True:
            try:
                line = self._get_line(i).expandtabs(4)
                text = ansi.ansi_re.sub('', line) if self.markup == 'ansi' else line
                text_len = len(text)
                size = 0
                pos = 0
                #  Get the start position
                while startx > size and pos < text_len:
                    size += utf_char_width(text[pos])
                    pos += 1
                old_pos = pos
                size = 0
                while True:
                    if text_len in (0, pos):
                        line_bit = (ansi.char_slice(line, old_pos,
                                                    text_len) + ansi.reset) \
                            if self.markup == 'ansi' else text[old_pos:]
                        yield line_bit.rstrip().replace('\r\n', '\n')
                        break

                    size += utf_char_width(text[pos])
                    #  Last char of this line is east_asian_char,
                    #  show it at next line so ignore it at this line.
                    if size > self.wid:
                        pos -= 1

                    if size >= self.wid:
                        line_bit = (ansi.char_slice(line, old_pos,
                                                    pos + 1 - old_pos) + ansi.reset) \
                            if self.markup == 'ansi' else text[old_pos:pos + 1]
                        yield line_bit.rstrip().replace('\r\n', '\n')

                        #  Don't wrap lines in pager.
                        if not self.fm.settings.wrap_plaintext_previews or self.focused:
                            break
                        old_pos = pos + 1
                        size = 0
                    pos += 1

            except IndexError:
                return
            i += 1
Esempio n. 2
0
 def _generate_lines(self, starty, startx):
     i = starty
     if not self.source:
         return
     while True:
         try:
             line = self._get_line(i).expandtabs(4)
             if self.markup == 'ansi':
                 line = ansi.char_slice(line, startx, self.wid) + ansi.reset
             else:
                 line = line[startx:self.wid + startx]
             yield line.rstrip().replace('\r\n', '\n')
         except IndexError:
             return
         i += 1
Esempio n. 3
0
 def _generate_lines(self, starty, startx):
     i = starty
     if not self.source:
         raise StopIteration
     while True:
         try:
             line = self._get_line(i).expandtabs(4)
             if self.markup is 'ansi':
                 line = ansi.char_slice(line, startx, self.wid) + ansi.reset
             else:
                 line = line[startx:self.wid + startx]
             yield line.rstrip()
         except IndexError:
             raise StopIteration
         i += 1
Esempio n. 4
0
 def _generate_lines(self, starty, startx):
     i = starty
     if not self.source:
         return
     while True:
         try:
             line = self._get_line(i).expandtabs(4)
             if self.markup == 'ansi':
                 line = ansi.char_slice(line, startx, self.wid) + ansi.reset
             else:
                 line = line[startx:self.wid + startx]
             yield line.rstrip().replace('\r\n', '\n')
         except IndexError:
             return
         i += 1
Esempio n. 5
0
 def _generate_lines(self, starty, startx):
     i = starty
     if not self.source:
         raise StopIteration
     while True:
         try:
             line = self._get_line(i).expandtabs(4)
             if self.markup is 'ansi':
                 line = ansi.char_slice(line, startx, self.wid) + ansi.reset
             else:
                 line = line[startx:self.wid + startx]
             yield line.rstrip()
         except IndexError:
             raise StopIteration
         i += 1
Esempio n. 6
0
 def _generate_lines(self, starty, startx):
     i = starty
     if not self.source:
         return
     while True:
         try:
             line = self._get_line(i).expandtabs(4)
             for part in ((0,) if not
                          self.fm.settings.wrap_plaintext_previews else
                          range(max(1, ((len(line) - 1) // self.wid) + 1))):
                 shift = part * self.wid
                 if self.markup == 'ansi':
                     line_bit = (ansi.char_slice(line, startx + shift,
                                                 self.wid + shift)
                                 + ansi.reset)
                 else:
                     line_bit = line[startx + shift:self.wid + startx
                                     + shift]
                 yield line_bit.rstrip().replace('\r\n', '\n')
         except IndexError:
             return
         i += 1
Esempio n. 7
0
	def test_char_slice(self):
		ansi_string = "XY"
		expected = "X"
		self.assertEqual(ansi.char_slice(ansi_string, 0, 1), expected)