Repository: saulpw/visidata

Issue:
Hiding column cancels replay
Hello,

I like the `Visidata` replay feature and hope to be able to use it with my data.

I've noticed that if I hide a column in a MS Excel spreadsheet, the replay is cancelled.

1. Open vd with a MS Excel file that has multiple columns
2. Hide a column with `-`
3. Save the playback as test.vd
4. Quit vd
5. `vd --play test.vd`
6. Notice `replay canceled` will appear

I would expect the replay to hide the column I selected.

This is what's in the playback:
```
myfile  0               hide-col                -       Hide current column
```

$ vd -v
saul.pw/VisiData v2.9dev


Discussion:
Ah, the issue is if the column has no name, then the replay is cancelled.


If I delete the 0 in the test.vd, everything works.

```
myfile                 hide-col                -       Hide current column
```
Excellent find!

Since 6e1334167f740a78832054e63020215acc6d5a88, column indexing via the replay requires an explicit int value. This is to support column names that are numeric. `.vdj` supports typed values, and so can distinguish between an int value for **column** (index via column number), and a string value for **column** (index via column name).

I am going to make sure that VisiData does the right thing if the **CmdLog** format was `.vdj`. And then maybe we should consider making `.vdj` the default format.

Resolving patch:
diff --git a/visidata/cmdlog.py b/visidata/cmdlog.py
--- a/visidata/cmdlog.py
+++ b/visidata/cmdlog.py
@@ -48,10 +48,10 @@ def checkVersion(vd, desired_version):
 @VisiData.api
 def fnSuffix(vd, prefix):
     i = 0
-    fn = prefix + '.vd'
+    fn = prefix + '.vdj'
     while Path(fn).exists():
         i += 1
-        fn = f'{prefix}-{i}.vd'
+        fn = f'{prefix}-{i}.vdj'
 
     return fn
 
@@ -190,7 +190,7 @@ def beforeExecHook(self, sheet, cmd, args, keystrokes):
 
         comment = vd.currentReplayRow.comment if vd.currentReplayRow else cmd.helpstr
         vd.activeCommand = self.newRow(sheet=sheetname,
-                                            col=str(colname),
+                                            col=colname,
                                             row=str(rowname),
                                             keystrokes=keystrokes,
                                             input=args,


Test patch:
diff --git a/tests/golden/numeric-cols.tsv b/tests/golden/numeric-cols.tsv
new file mode 100644
--- /dev/null
+++ b/tests/golden/numeric-cols.tsv
@@ -0,0 +1,44 @@
+Region	Rep	Item	Units	Unit_Cost	Total
+East	Jones	Pencil	95	1.99	189.05
+Central	Kivell	Binder	50	19.99	999.50
+Central	Jardine	Pencil	36	4.99	179.64
+Central	Gill	Pen	27	19.99	539.73
+West	Sorvino	Pencil	56	2.99	167.44
+East	Jones	Binder	60	4.99	299.40
+Central	Andrews	Pencil	75	1.99	149.25
+Central	Jardine	Pencil	90	4.99	449.10
+West	Thompson	Pencil	32	1.99	63.68
+East	Jones	Binder	60	8.99	539.40
+Central	Morgan	Pencil	90	4.99	449.10
+East	Howard	Binder	29	1.99	57.71
+East	Parent	Binder	81	19.99	1619.19
+East	Jones	Pencil	35	4.99	174.65
+Central	Smith	Desk	2	125.00	250.00
+East	Jones	Pen Set	16	15.99	255.84
+Central	Morgan	Binder	28	8.99	251.72
+East	Jones	Pen	64	8.99	575.36
+East	Parent	Pen	15	19.99	299.85
+Central	Kivell	Pen Set	96	4.99	479.04
+Central	Smith	Pencil	67	1.29	86.43
+East	Parent	Pen Set	74	15.99	1183.26
+Central	Gill	Binder	46	8.99	413.54
+Central	Smith	Binder	87	15.00	1305.00
+East	Jones	Binder	4	4.99	19.96
+West	Sorvino	Binder	7	19.99	139.93
+Central	Jardine	Pen Set	50	4.99	249.50
+Central	Andrews	Pencil	66	1.99	131.34
+East	Howard	Pen	96	4.99	479.04
+Central	Gill	Pencil	53	1.29	68.37
+Central	Gill	Binder	80	8.99	719.20
+Central	Kivell	Desk	5	125.00	625.00
+East	Jones	Pen Set	62	4.99	309.38
+Central	Morgan	Pen Set	55	12.49	686.95
+Central	Kivell	Pen Set	42	23.95	1005.90
+West	Sorvino	Desk	3	275.00	825.00
+Central	Gill	Pencil	7	1.29	9.03
+West	Sorvino	Pen	76	1.99	151.24
+West	Thompson	Binder	57	19.99	1139.43
+Central	Andrews	Pencil	14	1.29	18.06
+Central	Jardine	Binder	11	4.99	54.89
+Central	Jardine	Binder	94	19.99	1879.06
+Central	Andrews	Binder	28	4.99	139.72
diff --git a/tests/golden/numeric-names.tsv b/tests/golden/numeric-names.tsv
new file mode 100644
--- /dev/null
+++ b/tests/golden/numeric-names.tsv
@@ -0,0 +1,44 @@
+Region		Item	Units	Unit_Cost	Total
+East	Jones	Pencil	95	1.99	189.05
+Central	Kivell	Binder	50	19.99	999.50
+Central	Jardine	Pencil	36	4.99	179.64
+Central	Gill	Pen	27	19.99	539.73
+West	Sorvino	Pencil	56	2.99	167.44
+East	Jones	Binder	60	4.99	299.40
+Central	Andrews	Pencil	75	1.99	149.25
+Central	Jardine	Pencil	90	4.99	449.10
+West	Thompson	Pencil	32	1.99	63.68
+East	Jones	Binder	60	8.99	539.40
+Central	Morgan	Pencil	90	4.99	449.10
+East	Howard	Binder	29	1.99	57.71
+East	Parent	Binder	81	19.99	1619.19
+East	Jones	Pencil	35	4.99	174.65
+Central	Smith	Desk	2	125.00	250.00
+East	Jones	Pen Set	16	15.99	255.84
+Central	Morgan	Binder	28	8.99	251.72
+East	Jones	Pen	64	8.99	575.36
+East	Parent	Pen	15	19.99	299.85
+Central	Kivell	Pen Set	96	4.99	479.04
+Central	Smith	Pencil	67	1.29	86.43
+East	Parent	Pen Set	74	15.99	1183.26
+Central	Gill	Binder	46	8.99	413.54
+Central	Smith	Binder	87	15.00	1305.00
+East	Jones	Binder	4	4.99	19.96
+West	Sorvino	Binder	7	19.99	139.93
+Central	Jardine	Pen Set	50	4.99	249.50
+Central	Andrews	Pencil	66	1.99	131.34
+East	Howard	Pen	96	4.99	479.04
+Central	Gill	Pencil	53	1.29	68.37
+Central	Gill	Binder	80	8.99	719.20
+Central	Kivell	Desk	5	125.00	625.00
+East	Jones	Pen Set	62	4.99	309.38
+Central	Morgan	Pen Set	55	12.49	686.95
+Central	Kivell	Pen Set	42	23.95	1005.90
+West	Sorvino	Desk	3	275.00	825.00
+Central	Gill	Pencil	7	1.29	9.03
+West	Sorvino	Pen	76	1.99	151.24
+West	Thompson	Binder	57	19.99	1139.43
+Central	Andrews	Pencil	14	1.29	18.06
+Central	Jardine	Binder	11	4.99	54.89
+Central	Jardine	Binder	94	19.99	1879.06
+Central	Andrews	Binder	28	4.99	139.72
diff --git a/tests/numeric-cols.vdj b/tests/numeric-cols.vdj
new file mode 100644
--- /dev/null
+++ b/tests/numeric-cols.vdj
@@ -0,0 +1,4 @@
+#!vd -p
+{"longname": "open-file", "input": "sample_data/numeric-cols.tsv", "keystrokes": "o"}
+{"sheet": "numeric-cols", "col": "5", "row": "", "longname": "hide-col", "input": "", "keystrokes": "-", "comment": "Hide current column"}
+{"sheet": "numeric-cols", "col": 1, "row": "", "longname": "rename-col", "input": "Rep", "keystrokes": "^", "comment": "edit name of current column"}
diff --git a/tests/numeric-names.vd b/tests/numeric-names.vd
new file mode 100644
--- /dev/null
+++ b/tests/numeric-names.vd
@@ -0,0 +1,3 @@
+sheet	col	row	longname	input	keystrokes	comment
+			open-file	sample_data/numeric-cols.tsv	o	
+numeric-cols	5		hide-col		-	Hide current column