Skip to content

Commit

Permalink
[layout] hidden columns accessible beyond right of sheet #2394
Browse files Browse the repository at this point in the history
  • Loading branch information
saulpw committed May 24, 2024
1 parent 447686c commit 521410e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
2 changes: 1 addition & 1 deletion visidata/cmdlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
nonLogged = '''forget exec-longname undo redo quit
show error errors statuses options threads jump
replay cancel save-cmdlog macro cmdlog-sheet menu repeat reload-every
go- search scroll prev next page start end zoom resize visibility sidebar
go- search scroll prev next page start end zoom visibility sidebar
mouse suspend redraw no-op help syscopy sysopen profile toggle'''.split()

vd.option('rowkey_prefix', 'キ', 'string prefix for rowkey in the cmdlog', sheettype=None)
Expand Down
4 changes: 2 additions & 2 deletions visidata/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
vd.theme_option('disp_ambig_width', 1, 'width to use for unicode chars marked ambiguous')

vd.theme_option('disp_pending', '', 'string to display in pending cells')
vd.theme_option('disp_note_pending', '', 'note to display for pending cells')
vd.theme_option('disp_note_pending', ':', 'note to display for pending cells')
vd.theme_option('disp_note_fmtexc', '?', 'cell note for an exception during formatting')
vd.theme_option('disp_note_getexc', '!', 'cell note for an exception during computation')
vd.theme_option('disp_note_typeexc', '!', 'cell note for an exception during type conversion')

vd.theme_option('color_note_pending', 'bold magenta', 'color of note in pending cells')
vd.theme_option('color_note_pending', 'bold green', 'color of note in pending cells')
vd.theme_option('color_note_type', '226 yellow', 'color of cell note for non-str types in anytype columns')
vd.theme_option('color_note_row', '220 yellow', 'color of row note on left edge')
vd.option('scroll_incr', -3, 'amount to scroll with scrollwheel')
Expand Down
35 changes: 20 additions & 15 deletions visidata/sheets.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ def help_columns(self):
ColumnColorizer(1, 'color_key_col', lambda s,c,r,v: c and c.keycol),
CellColorizer(0, 'color_default', lambda s,c,r,v: True),
RowColorizer(1, 'color_error', lambda s,c,r,v: isinstance(r, (Exception, TypedExceptionWrapper))),
CellColorizer(3, 'color_current_cell', lambda s,c,r,v: c is s.cursorCol and r is s.cursorRow)
CellColorizer(3, 'color_current_cell', lambda s,c,r,v: c is s.cursorCol and r is s.cursorRow),
ColumnColorizer(1, 'color_hidden_col', lambda s,c,r,v: c and c.hidden),
]
nKeys = 0 # columns[:nKeys] are key columns
_ordering = [] # list of (col:Column|str, reverse:bool)
Expand Down Expand Up @@ -398,7 +399,7 @@ def nFooterRows(self):
@property
def cursorCol(self):
'Current Column object.'
vcols = self.visibleCols
vcols = self._ordered_cols
return vcols[min(self.cursorVisibleColIndex, len(vcols)-1)] if vcols else None

@property
Expand Down Expand Up @@ -592,8 +593,8 @@ def checkCursor(self):

if self.cursorVisibleColIndex <= 0:
self.cursorVisibleColIndex = 0
elif self.cursorVisibleColIndex >= self.nVisibleCols:
self.cursorVisibleColIndex = self.nVisibleCols-1
elif self.cursorVisibleColIndex >= len(self._ordered_cols):
self.cursorVisibleColIndex = len(self._ordered_cols)-1

if self.topRowIndex < 0:
self.topRowIndex = 0
Expand Down Expand Up @@ -639,34 +640,38 @@ def calcColLayout(self):
self._visibleColLayout = {}
x = 0
vcolidx = 0
for vcolidx in range(0, self.nVisibleCols):
width = self.calcSingleColLayout(vcolidx, x, minColWidth)
for vcolidx, col in enumerate(self._ordered_cols):
width = self.calcSingleColLayout(col, vcolidx, x, minColWidth)
if width:
x += width+sepColWidth
if x > winWidth-1:
break

self.rightVisibleColIndex = vcolidx

def calcSingleColLayout(self, vcolidx:int, x:int=0, minColWidth:int=4):
col = self.visibleCols[vcolidx]
def calcSingleColLayout(self, col:Column, vcolidx:int, x:int=0, minColWidth:int=4):
if col.width is None and len(self.visibleRows) > 0:
vrows = self.visibleRows if self.nRows > 1000 else self.rows[:1000] #1964
# handle delayed column width-finding
col.width = max(col.getMaxWidth(vrows), minColWidth)
if vcolidx != self.nVisibleCols-1: # let last column fill up the max width
if vcolidx < self.nVisibleCols-1: # let last column fill up the max width
col.width = min(col.width, self.options.default_width)

width = col.width if col.width is not None else self.options.default_width
if col in self.keyCols:
width = max(width, 1) # keycols must all be visible

# when cursor showing a hidden column
if vcolidx >= self.nVisibleCols and vcolidx == self.cursorVisibleColIndex:
width = self.options.default_width

width = max(width, 1)
if col in self.keyCols or vcolidx >= self.leftVisibleColIndex: # visible columns
self._visibleColLayout[vcolidx] = [x, min(width, self.windowWidth-x)]
return width


def drawColHeader(self, scr, y, h, vcolidx):
'Compose and draw column header for given vcolidx.'
col = self.visibleCols[vcolidx]
col = self._ordered_cols[vcolidx]

# hdrattr highlights whole column header
# sepattr is for header separators and indicators
Expand All @@ -677,7 +682,7 @@ def drawColHeader(self, scr, y, h, vcolidx):
hdrcattr = update_attr(hdrcattr, colors.color_current_hdr, 2)

C = self.options.disp_column_sep
if (self.keyCols and col is self.keyCols[-1]) or vcolidx == self.rightVisibleColIndex:
if (self.keyCols and col is self.keyCols[-1]) or vcolidx == self.nVisibleCols-1:
C = self.options.disp_keycol_sep

x, colwidth = self._visibleColLayout[vcolidx]
Expand Down Expand Up @@ -788,8 +793,8 @@ def calc_height(self, row, displines=None, isNull=None, maxheight=1):

for vcolidx, (x, colwidth) in sorted(self._visibleColLayout.items()):
if x < self.windowWidth: # only draw inside window
vcols = self.visibleCols
if vcolidx >= len(vcols):
vcols = self._ordered_cols
if vcolidx >= self.nVisibleCols and vcolidx != self.cursorVisibleColIndex:
continue
col = vcols[vcolidx]
cellval = col.getCell(row)
Expand Down

0 comments on commit 521410e

Please sign in to comment.