Get span of each item
I need this to detect which item the cursor is in it. Would you accept a PR for this functionality?
Sorry for my inattention to this repo. I happened to notice this when visiting the issue tracker due to another issue that was just opened. If you’re still interested, I’m willing to review PRs. Maybe this can be combined with the other two parsing feature requests (#9 and #13) into a more featureful lower-level API?
(@fenhl, I’ll make sure not to do anything without your input, unless you’re not available. Of course, this can wait until after the holidays. I’m just responding today because that’s when I noticed this.)
That sounds like a good idea.
I honestly don't remember exactly why I needed this. It was probably for my crate clap-repl to detect the cursor position for auto complete, but it seems now auto complete is working even when cursor is in the middle of the line, so maybe this was a XY problem and I didn't really need this.
I looked at my code and found that I worked around the problem by trimming the input to the cursor position. That is, to detect the word position of the cursor in this example:
some command --foo x --bar --baz
^
We can parse the trimmed version using shlex:
some command --f
^
and the number of tokens (in this case, 3) is the answer.
Although my original problem is solved, I still think there is some utility in returning the spans in a more featureful parsing api, and most of the other parsing libraries have such a api.