Skip to content

Commit

Permalink
[expr-] add command addcol-iter to make a col from iterator
Browse files Browse the repository at this point in the history
Analogous to setcol-iter, but creating a new column.
  • Loading branch information
midichef committed Jan 8, 2025
1 parent 6b0a78a commit 4d3ad36
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions visidata/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def inputExpr(self, prompt, *args, **kwargs):
Sheet.addCommand('g=', 'setcol-expr', 'cursorCol.setValuesFromExpr(someSelectedRows, inputExpr("set selected="), curcol=cursorCol)', 'set current column for selected rows to result of Python expression')
Sheet.addCommand('z=', 'setcell-expr', 'cursorCol.setValues([cursorRow], evalExpr(inputExpr("set expr="), row=cursorRow, curcol=cursorCol))', 'evaluate Python expression on current row and set current cell with result of Python expression')
Sheet.addCommand('gz=', 'setcol-iter', 'cursorCol.setValues(someSelectedRows, *list(itertools.islice(eval(input("set column= ", "expr", completer=CompleteExpr())), len(someSelectedRows))))', 'set current column for selected rows to the items in result of Python sequence expression')
Sheet.addCommand('', 'addcol-iter', 'iter_expr=inputExpr("new column iterator expr: "); it = eval(iter_expr, getGlobals()); c=SettableColumn(); addColumnAtCursor(c); c.setValues(rows, *it)', 'add column with values from a Python sequence expression, repeating it if needed to fill')

Sheet.addCommand(None, 'show-expr', 'status(evalExpr(inputExpr("show expr="), row=cursorRow, curcol=cursorCol))', 'evaluate Python expression on current row and show result on status line')

Expand Down

0 comments on commit 4d3ad36

Please # to comment.