wrapping was fixed for highlighted windows

--HG--
branch : pmacs2
This commit is contained in:
moculus 2007-06-16 14:41:27 +00:00
parent 2f4b124477
commit e9e22bdf4d
2 changed files with 85 additions and 48 deletions

View File

@ -462,59 +462,16 @@ class Application(object):
def draw_slot(self, i): def draw_slot(self, i):
assert self.active_slot < len(self.bufferlist.slots), "only two" assert self.active_slot < len(self.bufferlist.slots), "only two"
assert i < len(self.bufferlist.slots), "only three" assert i < len(self.bufferlist.slots), "only three"
slot = self.bufferlist.slots[i] slot = self.bufferlist.slots[i]
if slot.window is None: if slot.window is None:
return return
w = slot.window w = slot.window
modename = w.mode.name() 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: if modename in w.buffer.highlights:
highlighter = w.buffer.highlights[modename] self._draw_slot_lit(i)
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: else:
self.win.addstr(slot.offset + count, token.x - x, token.string, c) self._draw_slot_raw(i)
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
# highlighted regions # highlighted regions
for (high_w, p1, p2) in self.highlighted_ranges: for (high_w, p1, p2) in self.highlighted_ranges:
@ -563,6 +520,29 @@ class Application(object):
if p.y == y and p.x >= x and p.x < x + slot.width: if p.y == y and p.x >= x and p.x < x + slot.width:
self.highlight_char(slot.offset + count, p.x - x) self.highlight_char(slot.offset + count, p.x - x)
break break
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): if x + slot.width >= len(line):
x = 0 x = 0
y += 1 y += 1
@ -570,6 +550,61 @@ class Application(object):
x += slot.width x += slot.width
count += 1 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): def draw_status_bar(self, slotname):
slot = self.bufferlist.slots[slotname] slot = self.bufferlist.slots[slotname]
if slot.window is None: if slot.window is None:

2
foo.pl
View File

@ -3,6 +3,8 @@ package Foo;
use warnings FATAL => 'all'; use warnings FATAL => 'all';
use strict; use strict;
my $blah = "foo foo bar" . "foo foo bar" . "foo foo bar" . "foo foo bar" . "foo foo bar" . "one";
use Carp; use Carp;
${$blarg->{foo}} = 33; ${$blarg->{foo}} = 33;