Skip to content

Commit

Permalink
[cmdlog] set default cmdlog to CommandLogJsonl
Browse files Browse the repository at this point in the history
Also adds a **fields argument to jsonl:newRow.

Closes #1443
  • Loading branch information
anjakefala committed Jul 30, 2022
1 parent 5e476e1 commit 184d9e9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
12 changes: 7 additions & 5 deletions visidata/cmdlog.py
Expand Up @@ -238,8 +238,10 @@ class CommandLog(_CommandLog, VisiDataMetaSheet):

class CommandLogJsonl(_CommandLog, JsonLinesSheet):

def newRow(self):
return JsonLinesSheet.newRow(self)
filetype = 'vdj'

def newRow(self, **fields):
return AttrDict(JsonLinesSheet.newRow(self, **fields))

def iterload(self):
for r in JsonLinesSheet.iterload(self):
Expand Down Expand Up @@ -420,12 +422,12 @@ def cmdlog(sheet):
rows = sheet.cmdlog_sheet.rows
if isinstance(sheet.source, BaseSheet):
rows = sheet.source.cmdlog.rows + rows
return CommandLog(sheet.name+'_cmdlog', source=sheet, rows=rows)
return CommandLogJsonl(sheet.name+'_cmdlog', source=sheet, rows=rows)


@BaseSheet.lazy_property
def cmdlog_sheet(sheet):
return CommandLog(sheet.name+'_cmdlog', source=sheet, rows=[])
return CommandLogJsonl(sheet.name+'_cmdlog', source=sheet, rows=[])


@BaseSheet.property
Expand All @@ -448,7 +450,7 @@ def shortcut(self):
@VisiData.property
def cmdlog(vd):
if not vd._cmdlog:
vd._cmdlog = CommandLog('cmdlog', rows=[])
vd._cmdlog = CommandLogJsonl('cmdlog', rows=[])
vd.beforeExecHooks.append(vd._cmdlog.beforeExecHook)
return vd._cmdlog

Expand Down
4 changes: 2 additions & 2 deletions visidata/loaders/json.py
Expand Up @@ -55,8 +55,8 @@ def addRow(self, row, index=None):

return super().addRow(row, index=index)

def newRow(self):
return {}
def newRow(self, **fields):
return fields


## saving json and jsonl
Expand Down

0 comments on commit 184d9e9

Please sign in to comment.