Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[save-] handle empty delimiter when safety_first #2421

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions visidata/save.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ def safe_trdict(vs):
'returns string.translate dictionary for replacing tabs and newlines'
if vs.options.safety_first:
delim = vs.options.delimiter
return {
trdict = {
0: '', # strip NUL completely
ord(delim): vs.options.tsv_safe_tab, # \t
10: vs.options.tsv_safe_newline, # \n
13: vs.options.tsv_safe_newline, # \r
}
if not delim or ord(delim) in trdict:
vd.fail(f'cannot use delimiter {repr(delim)} with safety_first')
trdict[ord(delim)] = vs.options.tsv_safe_tab # \t
return trdict
return {}


Expand All @@ -29,12 +32,12 @@ def iterdispvals(sheet, *cols, format=False):
cols = sheet.visibleCols

transformers = collections.OrderedDict() # list of transformers for each column in order
trdict = sheet.safe_trdict()
for col in cols:
transformers[col] = [ col.type ]
if format:
formatMaker = getattr(col, 'formatter_'+(col.formatter or sheet.options.disp_formatter))
transformers[col].append(formatMaker(col._formatdict))
trdict = sheet.safe_trdict()
if trdict:
transformers[col].append(lambda v,trdict=trdict: v.translate(trdict))

Expand Down
Loading