Skip to content

Commit

Permalink
[freqtbl] add open-preview for split pane of source rows at cursor #1086
Browse files Browse the repository at this point in the history
  • Loading branch information
saulpw committed Sep 4, 2023
1 parent 6358c94 commit dd5abba
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
12 changes: 10 additions & 2 deletions visidata/basesheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ def _class_options(cls):

class_options = options = _dualproperty(_obj_options, _class_options)

def __init__(self, *names, **kwargs):
def __init__(self, *names, rows=UNLOADED, **kwargs):
self._name = None # initial cache value necessary for self.options
self.names = list(names)
self.name = self.options.name_joiner.join(str(x) for x in self.names if x)
self.source = None
self.rows = UNLOADED # list of opaque objects
self.rows = rows # list of opaque objects
self._scr = None
self.hasBeenModified = False

Expand Down Expand Up @@ -151,6 +151,14 @@ def __len__(self):
def __str__(self):
return self.name

@property
def rows(self):
return self._rows

@rows.setter
def rows(self, rows):
self._rows = rows

@property
def nRows(self):
'Number of rows on this sheet. Override in subclass.'
Expand Down
9 changes: 9 additions & 0 deletions visidata/freqtbl.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ def makeFreqTableSheetSummary(sheet, *groupByCols):
source=sheet)


@VisiData.api
class FreqTablePreviewSheet(Sheet):
@property
def rows(self):
return self.source.cursorRow.sourcerows


FreqTableSheet.addCommand('', 'open-preview', 'vd.push(FreqTablePreviewSheet(sheet.name, "preview", source=sheet, columns=source.columns), pane=2); vd.options.disp_splitwin_pct=50', 'open split preview of source rows at cursor')

Sheet.addCommand('F', 'freq-col', 'vd.push(makeFreqTable(sheet, cursorCol))', 'open Frequency Table grouped on current column, with aggregations of other columns')
Sheet.addCommand('gF', 'freq-keys', 'vd.push(makeFreqTable(sheet, *keyCols))', 'open Frequency Table grouped by all key columns on source sheet, with aggregations of other columns')
Sheet.addCommand('zF', 'freq-summary', 'vd.push(makeFreqTableSheetSummary(sheet, Column("Total", sheet=sheet, getter=lambda col, row: "Total")))', 'open one-line summary for all rows and selected rows')
Expand Down
5 changes: 2 additions & 3 deletions visidata/sheets.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,8 @@ class TableSheet(BaseSheet):
]
nKeys = 0 # columns[:nKeys] are key columns

def __init__(self, *names, **kwargs):
super().__init__(*names, **kwargs)
self.rows = UNLOADED # list of opaque row objects (UNLOADED before first reload)
def __init__(self, *names, rows=UNLOADED, **kwargs):
super().__init__(*names, rows=rows, **kwargs)
self.cursorRowIndex = 0 # absolute index of cursor into self.rows
self.cursorVisibleColIndex = 0 # index of cursor into self.visibleCols

Expand Down

0 comments on commit dd5abba

Please sign in to comment.