Skip to content

Commit

Permalink
[features] minor code changes to jsvine plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
saulpw committed Oct 26, 2023
1 parent c32e92d commit e3fc79e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
4 changes: 2 additions & 2 deletions visidata/features/dedupe.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ def _reload(self=vs):
self.addRow(row)

vs.reload = _reload
vd.push(vs)
return vs


# Add longname-commands to VisiData to execute these methods
BaseSheet.addCommand(None, "select-duplicate-rows", "sheet.select_duplicate_rows()", "select each row that is a duplicate of a prior row")
BaseSheet.addCommand(None, "dedupe-rows", "sheet.dedupe_rows()", "open new sheet in which only non-duplicate rows in the active sheet are included")
BaseSheet.addCommand(None, "dedupe-rows", "vd.push(sheet.dedupe_rows())", "open new sheet in which only non-duplicate rows in the active sheet are included")

vd.addMenuItems('''
Row > Select > duplicate rows > select-duplicate-rows
Expand Down
16 changes: 6 additions & 10 deletions visidata/features/normcol.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
from visidata import vd, Sheet, asyncthread, Progress
from collections import Counter
import re
import string

nonalphanum_pat = re.compile(r"[^a-z0-9]+")
DIGITS = "0123456789"


def normalize_name(name):
Expand All @@ -61,7 +61,7 @@ def normalize_name(name):
stripped = subbed.strip("_")

# To ensure it's a valid Python identifier
if (stripped or "_")[0] in DIGITS:
if (stripped or "_")[0] in string.digits:
stripped = "_" + stripped

return stripped
Expand All @@ -86,30 +86,26 @@ def gen_normalize_names(names):
yield norm_name


def normalize_names(names):
return list()


@Sheet.api
@asyncthread
def normalize_column_names(sheet):
"""
Normalize the names of all non-hidden columns on the active sheet.
"""

init_names = []
init_names = {}
gen = gen_normalize_names(c.name for c in sheet.visibleCols)
prog = Progress(gen, gerund="normalizing", total=sheet.nVisibleCols)

for i, norm_name in enumerate(prog):
col = sheet.visibleCols[i]
init_names.append(col.name) # Store for undo
init_names[col] = col.name # Store for undo
col.name = norm_name

@asyncthread
def undo():
for i, c in enumerate(init_names):
sheet.visibleCols[i].name = c
for c, oldname in init_names.items():
c.name = oldname

vd.addUndo(undo)

Expand Down

0 comments on commit e3fc79e

Please sign in to comment.