Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if T is None: # still allow icon to be explicitly non-displayed ''
T = '?'
hdrs = col.name.split('\n')
for i in range(h):
name = ' ' # save room at front for LeftMore
if h-i-1 < len(hdrs):
name += hdrs[::-1][h-i-1]
if len(name) > colwidth-1:
name = name[:colwidth-len(options.disp_truncator)] + options.disp_truncator
if i == h-1:
hdrattr = hdrattr.update_attr(colors.color_bottom_hdr, 5)
clipdraw(scr, y+i, x, name, hdrattr.attr, colwidth)
vd.onMouse(scr, y+i, x, 1, colwidth, BUTTON3_RELEASED='rename-col')
if C and x+colwidth+len(C) < self.windowWidth:
scr.addstr(y+i, x+colwidth, C, sepattr)
clipdraw(scr, y+h-1, x+colwidth-len(T), T, hdrattr.attr, len(T))
try:
if vcolidx == self.leftVisibleColIndex and col not in self.keyCols and self.nonKeyVisibleCols.index(col) > 0:
A = options.disp_more_left
scr.addstr(y, x, A, sepattr)
except ValueError: # from .index
pass
height = min(max(heights), maxheight) or 1 # display even empty rows
self.rowLayout[rowidx] = (ybase, height)
for vcolidx, (col, cellval, lines) in displines.items():
if vcolidx not in self.visibleColLayout:
continue
x, colwidth = self.visibleColLayout[vcolidx]
cattr = self._colorize(col, row, cellval)
cattr = update_attr(cattr, basecellcattr)
note = getattr(cellval, 'note', None)
if note:
notecattr = update_attr(cattr, colors.get_color(cellval.notecolor), 10)
clipdraw(scr, ybase, x+colwidth-len(note), note, notecattr.attr)
if len(lines) > height:
firstn = sum(len(i)+1 for i in lines[:height-1])
lines[height-1] = cellval.display[firstn:]
del lines[height:]
elif len(lines) < height:
lines.extend(['']*(height-len(lines)))
for i, line in enumerate(lines):
y = ybase+i
if vcolidx == self.rightVisibleColIndex: # right edge of sheet
if len(lines) == 1:
sepchars = endsep
else:
if i == 0:
elif i == len(lines)-1:
sepchars = keybotsep
else:
sepchars = keymidsep
else:
if len(lines) == 1:
sepchars = colsep
else:
if i == 0:
sepchars = topsep
elif i == len(lines)-1:
sepchars = botsep
else:
sepchars = midsep
clipdraw(scr, y, x, disp_column_fill+line, attr.attr, colwidth-(1 if note else 0))
vd.onMouse(scr, y, x, 1, colwidth, BUTTON3_RELEASED='edit-cell')
if x+colwidth+len(sepchars) <= self.windowWidth:
scr.addstr(y, x+colwidth, sepchars, sepattr.attr)
return height
if vs.progresses:
gerund = vs.progresses[0].gerund
else:
gerund = 'processing'
statcolors.insert(1, (' %s %s…' % (vs.progressPct, gerund), 'color_status'))
if vd.cmdlog and vd.cmdlog.currentReplay:
statcolors.insert(0, (vd.cmdlog.currentReplay.replayStatus, 'color_status_replay'))
for rstatcolor in statcolors:
if rstatcolor:
try:
rstatus, coloropt = rstatcolor
rstatus = ' '+rstatus
attr = colors.get_color(coloropt).attr
statuslen = clipdraw(scr, vd.windowHeight-1, rightx, rstatus, attr, w=vs.windowWidth-1, rtl=True)
rightx -= statuslen
ret += statuslen
except Exception as e:
vd.exceptionCaught(e)
if scr:
curses.doupdate()
return ret
def input(self, prompt, type=None, defaultLast=False, history=[], **kwargs):
'''Display prompt and return line of user input.
type: list of previous items, or a string indicating the type of input.
defaultLast: on empty input, if True, return last history item
'''
if type:
if isinstance(type, str):
history = self.lastInputs[type]
else:
history = type
rstatuslen = self.drawRightStatus(self._scr, self.sheets[0])
attr = 0
promptlen = clipdraw(self._scr, self.windowHeight-1, 0, prompt, attr, w=self.windowWidth-rstatuslen-1)
ret = self.editText(self.windowHeight-1, promptlen, self.windowWidth-promptlen-rstatuslen-2,
attr=colors.color_edit_cell,
unprintablechar=options.disp_unprintable,
truncchar=options.disp_truncator,
history=history,
**kwargs)
if ret:
if isinstance(type, str):
self.lastInputs[type].append(ret)
elif defaultLast:
history or fail("no previous input")
ret = history[-1]
return ret
else:
if i == 0:
sepchars = topsep
elif i == len(lines)-1:
sepchars = botsep
else:
sepchars = midsep
clipdraw(scr, y, x, disp_column_fill+line, cattr.attr, w=colwidth-(1 if note else 0))
vd.onMouse(scr, y, x, 1, colwidth, BUTTON3_RELEASED='edit-cell')
if x+colwidth+len(sepchars) <= self.windowWidth:
scr.addstr(y, x+colwidth, sepchars, basecellcattr.attr)
if self.isSelected(row):
clipdraw(scr, ybase, 0, selectednote, basecellcattr.attr)
return height
elif i == len(lines)-1:
sepchars = keybotsep
else:
sepchars = keymidsep
else:
if len(lines) == 1:
sepchars = colsep
else:
if i == 0:
sepchars = topsep
elif i == len(lines)-1:
sepchars = botsep
else:
sepchars = midsep
clipdraw(scr, y, x, disp_column_fill+line, cattr.attr, w=colwidth-(1 if note else 0))
vd.onMouse(scr, y, x, 1, colwidth, BUTTON3_RELEASED='edit-cell')
if x+colwidth+len(sepchars) <= self.windowWidth:
scr.addstr(y, x+colwidth, sepchars, basecellcattr.attr)
if self.isSelected(row):
clipdraw(scr, ybase, 0, selectednote, basecellcattr.attr)
return height
if len(dispval) < w: # entire value fits
dispval += fillchar*(w-len(dispval)-1)
elif i == len(dispval): # cursor after value (will append)
dispi = w-1
dispval = left_truncchar + dispval[len(dispval)-w+2:] + fillchar
elif i >= len(dispval)-w//2: # cursor within halfwidth of end
dispi = w-(len(dispval)-i)
dispval = left_truncchar + dispval[len(dispval)-w+1:]
elif i <= w//2: # cursor within halfwidth of beginning
dispval = dispval[:w-1] + right_truncchar
else:
dispi = w//2 # visual cursor stays right in the middle
k = 1 if w%2==0 else 0 # odd widths have one character more
dispval = left_truncchar + dispval[i-w//2+1:i+w//2-k] + right_truncchar
prew = clipdraw(scr, y, x, dispval[:dispi], attr, w)
clipdraw(scr, y, x+prew, dispval[dispi:], attr, w-prew+1)
scr.move(y, x+prew)
ch = vd.getkeystroke(scr)
if ch == '': continue
elif ch == 'KEY_IC': insert_mode = not insert_mode
elif ch == '^A' or ch == 'KEY_HOME': i = 0
elif ch == '^B' or ch == 'KEY_LEFT': i -= 1
elif ch in ('^C', '^Q', ESC): raise EscapeException(ch)
elif ch == '^D' or ch == 'KEY_DC': v = delchar(v, i)
elif ch == '^E' or ch == 'KEY_END': i = len(v)
elif ch == '^F' or ch == 'KEY_RIGHT': i += 1
elif ch in ('^H', 'KEY_BACKSPACE', '^?'): i -= 1; v = delchar(v, i)
elif ch == TAB: v, i = complete_state.complete(v, i, +1)
elif ch == 'KEY_BTAB': v, i = complete_state.complete(v, i, -1)
elif ch == ENTER: break
elif ch == '^K': v = v[:i] # ^Kill to end-of-line