Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
del new_row[-1]
# we need another segment
y_attr, y_cs, nlast_text = row[-2]
nlast_cols = util.calc_width(nlast_text, 0,
len(nlast_text))
z_col += nlast_cols
nlast_offs, y_col = util.calc_text_pos(nlast_text, 0,
len(nlast_text), nlast_cols-1)
y_text = nlast_text[nlast_offs:]
if nlast_offs:
new_row.append((y_attr, y_cs,
nlast_text[:nlast_offs]))
else:
z_text = last_text[last_offs:]
y_attr, y_cs = z_attr, z_cs
nlast_cols = util.calc_width(last_text, 0,
last_offs)
nlast_offs, y_col = util.calc_text_pos(last_text, 0,
last_offs, nlast_cols-1)
y_text = last_text[nlast_offs:last_offs]
if nlast_offs:
new_row.append((y_attr, y_cs,
last_text[:nlast_offs]))
new_row.append((z_attr, z_cs, z_text))
return new_row, z_col-y_col, (y_attr, y_cs, y_text)
# perfect space wrap
b.append([(sc,p,pos),
# removed character hint
(0,pos)])
p = pos+1
continue
if is_wide_char(text, pos):
# perfect next wide
b.append([(sc,p,pos)])
p = pos
continue
prev = pos
while prev > p:
prev = move_prev_char(text, p, prev)
if text[prev] == sp_o:
sc = calc_width(text,p,prev)
l = [(0,prev)]
if p!=prev:
l = [(sc,p,prev)] + l
b.append(l)
p = prev+1
break
if is_wide_char(text,prev):
# wrap after wide char
next = move_next_char(text, prev, pos)
sc = calc_width(text,p,next)
b.append([(sc,p,next)])
p = next
break
else:
# unwrap previous line space if possible to
# fit more text (we're breaking a word anyway)
if y in old_line_numbers:
old_line = y
else:
old_line = old_line_numbers[0]
send( "<%d\n"%old_line )
continue
col = 0
for (a, cs, run) in row:
run = run.translate(_trans_table)
if a is None:
fg,bg,mono = "black", "light gray", None
else:
fg,bg,mono = self.palette[a]
if y == cy and col <= cx:
run_width = util.calc_width(run, 0,
len(run))
if col+run_width > cx:
l.append(code_span(run, fg, bg,
cx-col))
else:
l.append(code_span(run, fg, bg))
col += run_width
else:
l.append(code_span(run, fg, bg))
send("".join(l)+"\n")
self.last_screen = new_screen
self.last_screen_width = cols
if self.update_method == "polling":
sys.stdout.write("".join(sendq))
pos -- integer position into text
clamp -- ignored right now
"""
closest = None
y = 0
for line_layout in layout:
x = 0
for seg in line_layout:
s = LayoutSegment(seg)
if s.offs is None:
x += s.sc
continue
if s.offs == pos:
return x,y
if s.end is not None and s.offs<=pos and s.end>pos:
x += calc_width( text, s.offs, pos )
return x,y
distance = abs(s.offs - pos)
if s.end is not None and s.end
continue
prev = pos
while prev > p:
prev = move_prev_char(text, p, prev)
if text[prev] == sp_o:
sc = calc_width(text,p,prev)
l = [(0,prev)]
if p!=prev:
l = [(sc,p,prev)] + l
b.append(l)
p = prev+1
break
if is_wide_char(text,prev):
# wrap after wide char
next = move_next_char(text, prev, pos)
sc = calc_width(text,p,next)
b.append([(sc,p,next)])
p = next
break
else:
# unwrap previous line space if possible to
# fit more text (we're breaking a word anyway)
if b and (len(b[-1]) == 2 or ( len(b[-1])==1
and len(b[-1][0])==2 )):
# look for removed space above
if len(b[-1]) == 1:
[(h_sc, h_off)] = b[-1]
p_sc = 0
p_off = p_end = h_off
else:
[(p_sc, p_off, p_end),
(h_sc, h_off)] = b[-1]
def _last_row(self, row):
"""On the last row we need to slide the bottom right character
into place. Calculate the new line, attr and an insert sequence
to do that.
eg. last row:
XXXXXXXXXXXXXXXXXXXXYZ
Y will be drawn after Z, shifting Z into position.
"""
new_row = row[:-1]
z_attr, z_cs, last_text = row[-1]
last_cols = util.calc_width(last_text, 0, len(last_text))
last_offs, z_col = util.calc_text_pos(last_text, 0,
len(last_text), last_cols-1)
if last_offs == 0:
z_text = last_text
del new_row[-1]
# we need another segment
y_attr, y_cs, nlast_text = row[-2]
nlast_cols = util.calc_width(nlast_text, 0,
len(nlast_text))
z_col += nlast_cols
nlast_offs, y_col = util.calc_text_pos(nlast_text, 0,
len(nlast_text), nlast_cols-1)
y_text = nlast_text[nlast_offs:]
if nlast_offs:
new_row.append((y_attr, y_cs,
nlast_text[:nlast_offs]))
for row in r.content():
y += 1
col = 0
for a, cs, run in row:
if not str is bytes:
run = run.decode()
run = run.translate(_trans_table)
if isinstance(a, AttrSpec):
aspec = a
else:
aspec = self._palette[a][
{1: 1, 16: 0, 88:2, 256:3}[self.colors]]
if y == cy and col <= cx:
run_width = util.calc_width(run, 0,
len(run))
if col+run_width > cx:
l.append(html_span(run,
aspec, cx-col))
else:
l.append(html_span(run, aspec))
col += run_width
else:
l.append(html_span(run, aspec))
l.append("\n")
# add the fragment to the list
self.fragments.append( "<pre>%s</pre>" % "".join(l) )
XXXXXXXXXXXXXXXXXXXXYZ
Y will be drawn after Z, shifting Z into position.
"""
new_row = row[:-1]
z_attr, z_cs, last_text = row[-1]
last_cols = util.calc_width(last_text, 0, len(last_text))
last_offs, z_col = util.calc_text_pos(last_text, 0,
len(last_text), last_cols-1)
if last_offs == 0:
z_text = last_text
del new_row[-1]
# we need another segment
y_attr, y_cs, nlast_text = row[-2]
nlast_cols = util.calc_width(nlast_text, 0,
len(nlast_text))
z_col += nlast_cols
nlast_offs, y_col = util.calc_text_pos(nlast_text, 0,
len(nlast_text), nlast_cols-1)
y_text = nlast_text[nlast_offs:]
if nlast_offs:
new_row.append((y_attr, y_cs,
nlast_text[:nlast_offs]))
else:
z_text = last_text[last_offs:]
y_attr, y_cs = z_attr, z_cs
nlast_cols = util.calc_width(last_text, 0,
last_offs)
nlast_offs, y_col = util.calc_text_pos(last_text, 0,
last_offs, nlast_cols-1)
y_text = last_text[nlast_offs:last_offs]