Repository: saulpw/visidata

Issue:
Title: [input] Up arrow stack traces and exits input
**Small description**
Up arrow causes stack trace, and exits input


**Expected result**
No stack trace, and doesn't exit.

**Actual result with screenshot**
https://asciinema.org/a/DW4cydUhUFBBAFRC3QufhBxQb


```
Traceback (most recent call last):
  File "/home/felix/git/visidata/env/lib/python3.9/site-packages/visidata/basesheet.py", line 167, in execCommand
    escaped = super().execCommand2(cmd, vdglobals=vdglobals)
  File "/home/felix/git/visidata/env/lib/python3.9/site-packages/visidata/basesheet.py", line 69, in execCommand2
    exec(code, vdglobals, LazyChainMap(vd, self))
  File "aggregate-col", line 1, in <module>
  File "/home/felix/git/visidata/env/lib/python3.9/site-packages/visidata/choose.py", line 63, in chooseMany
    chosenstr = vd.input(prompt+': ', completer=CompleteKey(choice_keys), bindings={'^X': throw_fancy})
  File "/home/felix/git/visidata/env/lib/python3.9/site-packages/visidata/_input.py", line 325, in input
    ret = self.editText(sheet.windowHeight-1, promptlen, sheet.windowWidth-promptlen-rstatuslen-2,
  File "/home/felix/git/visidata/env/lib/python3.9/site-packages/visidata/_input.py", line 264, in editText
    v = vd.editline(vd.activeSheet._scr, y, x, w, display=display, **kwargs)
  File "/home/felix/git/visidata/env/lib/python3.9/site-packages/visidata/_input.py", line 233, in editline
    elif history and ch == 'KEY_UP':           v, i = history_state.up(v, i)
  File "/home/felix/git/visidata/env/lib/python3.9/site-packages/visidata/_input.py", line 120, in up
    i = len(v)
TypeError: object of type 'int' has no len()
```

**Steps to reproduce with sample data and a .vd**
1. Set column width Enter
2. Start to add aggregator, use up arrow.


**Additional context**
Please include the version of VisiData. Lasest develop branch.



Discussion:
This is a good find, but unfortunately I am struggling to reproduce. =( Might have something to do with input histfile.

Do you have anything in your `~/.visidatarc`? Does this bug still happen if you do `vd --config="/dev/null" benchmarks.csv` and re-do the steps?
Are you using `options.input_history`?

 If you are using it is it possible to give a reference to the contents of your `histfile` that are relevant to the bug? The record of the `z_` column width being set? Also, what format is your `histfile` in?
 
 If you are not, hm!
@saulpw shared with me a recent change 46686d3778e308b3c00d13262a5f203096d5f97c that types the result from history the same as the typed value in `input()`. I did not actually have the latest `develop`.

So, I am now able to reproduce this!
Sorry @anjakefala!  My original reproduction case, actually specified --input_history.
When I tried it without that, it worked, but I picked that up from .visidatarc file.  I missed that was important to this bug.  My history file is in json.


Resolving patch:
diff --git a/visidata/_input.py b/visidata/_input.py
--- a/visidata/_input.py
+++ b/visidata/_input.py
@@ -117,7 +117,7 @@ def up(self, v, i):
         if self.hist_idx > 0:
             self.hist_idx -= 1
             v = self.history[self.hist_idx]
-        i = len(v)
+        i = len(str(v))
         return v, i
 
     def down(self, v, i):
@@ -129,7 +129,7 @@ def down(self, v, i):
         else:
             v = self.prev_val
             self.hist_idx = None
-        i = len(v)
+        i = len(str(v))
         return v, i
 
 
@@ -245,6 +245,8 @@ def find_nonword(s, a, b, incr):
             i += 1
 
         if i < 0: i = 0
+        # v may have a non-str type with no len()
+        v = str(v)
         if i > len(v): i = len(v)
         first_action = False
         complete_state.reset()


Test patch: