From e9e22bdf4dfa11de9de70c1fae1f33e723ae854e Mon Sep 17 00:00:00 2001 From: moculus Date: Sat, 16 Jun 2007 14:41:27 +0000 Subject: [PATCH] wrapping was fixed for highlighted windows --HG-- branch : pmacs2 --- application.py | 131 +++++++++++++++++++++++++++++++------------------ foo.pl | 2 + 2 files changed, 85 insertions(+), 48 deletions(-) diff --git a/application.py b/application.py index 4c47715..75a048c 100755 --- a/application.py +++ b/application.py @@ -462,59 +462,16 @@ class Application(object): def draw_slot(self, i): assert self.active_slot < len(self.bufferlist.slots), "only two" assert i < len(self.bufferlist.slots), "only three" - slot = self.bufferlist.slots[i] if slot.window is None: return w = slot.window modename = w.mode.name() - redattr = color.build_attr(color.pairs('red', 'default')) - - lines = w.buffer.lines - count = 0 - (x, y) = w.first.xy() - while count < slot.height: - if y >= len(lines): - self.win.addstr(slot.offset + count, 0, '~', redattr) - else: - line = lines[y] - if modename in w.buffer.highlights: - highlighter = w.buffer.highlights[modename] - group = highlighter.tokens[y] - j = 0 - for token in group: - assert token.y == y, highlighter.dump() - if token.x < x: - continue - elif token.x >= x + slot.width: - break - - fqlist = token.fqlist() - c = w.mode.default_color - for j in range(0, len(fqlist)): - name = '.'.join(fqlist[j:]) - if name in w.mode.colors: - c = w.mode.colors[name] - break - - if DARK_BACKGROUND: - c |= curses.A_BOLD - if token.x + len(token.string) >= x + slot.width: - n = len(token.string) - x - slot.width + token.x - s = token.string[:n] - self.win.addstr(slot.offset + count, token.x - x, s, c) - else: - self.win.addstr(slot.offset + count, token.x - x, token.string, c) - else: - self.win.addstr(slot.offset + count, 0, line[x:x + slot.width]) - - if x + slot.width >= len(line): - x = 0 - y += 1 - else: - x += slot.width - count += 1 + if modename in w.buffer.highlights: + self._draw_slot_lit(i) + else: + self._draw_slot_raw(i) # highlighted regions for (high_w, p1, p2) in self.highlighted_ranges: @@ -563,13 +520,91 @@ class Application(object): if p.y == y and p.x >= x and p.x < x + slot.width: self.highlight_char(slot.offset + count, p.x - x) break - if x + slot.width >= len(line): + if x + slot.width > len(w.buffer.lines[y]): x = 0 y += 1 else: x += slot.width count += 1 + def _draw_slot_raw(self, i): + slot = self.bufferlist.slots[i] + w = slot.window + modename = w.mode.name() + redattr = color.build_attr(color.pairs('red', 'default')) + + (x, y) = w.first.xy() + lines = w.buffer.lines + count = 0 + while count < slot.height: + if y >= len(lines): + self.win.addstr(slot.offset + count, 0, '~', redattr) + else: + line = lines[y][x:x + slot.width] + self.win.addstr(slot.offset + count, 0, line) + + if x + slot.width >= len(line): + x = 0 + y += 1 + else: + x += slot.width + count += 1 + + def _get_token_color(self, w, token): + fqlist = token.fqlist() + c = w.mode.default_color + for j in range(0, len(fqlist)): + name = '.'.join(fqlist[j:]) + if name in w.mode.colors: + c = w.mode.colors[name] + break + if DARK_BACKGROUND: + c |= curses.A_BOLD + return c + + def _draw_slot_lit(self, i): + slot = self.bufferlist.slots[i] + w = slot.window + modename = w.mode.name() + redattr = color.build_attr(color.pairs('red', 'default')) + highlighter = w.buffer.highlights[modename] + + (x, y) = w.first.xy() + j = 0 + count = 0 + assert len(w.buffer.lines) == len(highlighter.tokens) + while count < slot.height: + if y < len(w.buffer.lines): + while j < len(highlighter.tokens[y]): + token = highlighter.tokens[y][j] + assert token.y == y, '%d == %d' % (token.y, y) + + s_offset = max(x - token.x, 0) + x_offset = max(token.x - x, 0) + assert x_offset < slot.width + + c = self._get_token_color(w, token) + s = token.string[s_offset:] + token_done = x_offset + len(s) <= slot.width + token_wrap = x_offset + len(s) >= slot.width + self.win.addstr(slot.offset + count, x_offset, s[:slot.width], c) + + if token_wrap: + self.win.addch(slot.offset + count, slot.width, '\\', redattr) + x += slot.width + count += 1 + if token_done: + j += 1 + + # we have finished this logical line of tokens + j = 0 + x = 0 + y += 1 + count += 1 + else: + self.win.addstr(slot.offset + count, 0, '~', redattr) + count += 1 + def draw_status_bar(self, slotname): slot = self.bufferlist.slots[slotname] if slot.window is None: diff --git a/foo.pl b/foo.pl index da8227b..747067f 100644 --- a/foo.pl +++ b/foo.pl @@ -3,6 +3,8 @@ package Foo; use warnings FATAL => 'all'; use strict; +my $blah = "foo foo bar" . "foo foo bar" . "foo foo bar" . "foo foo bar" . "foo foo bar" . "one"; + use Carp; ${$blarg->{foo}} = 33;