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

[main-] handle position args as +sheet:subsheet:col:row #2425

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

midichef
Copy link
Contributor

Two bug fixes:
3ea655b - fixes setting column position in sheet
Currently the starting column cannot be set, only the row.
repro command: vd sample_data/sample.tsv sample_data/StatusPR.csv +2:2
This occurs because the column position changes too early, before the sheet is loaded.

1aa2d98 - fixes setting column position in subsheet
A similar problem, changing position before the subsheet is loaded.
repro: vd ~vdsrc/sample_data/employees.sqlite +:emp:5:2

And then some functionality changes:
d16743d - change arg parsing, from row:col to col:row
Strings of the form a:b are parsed as row:column. This commit changes it to column:row.
Previously, I discussed some pros and cons of this change.
This is technically a breaking change, but as I noted in that comment, the form +a:b has not worked since 2.9 so it's not likely that anyone is currently using that syntax. However, if they are using +:a:b with the extra colon, this will indeed be a breaking change for them.
repro: vd ~vdsrc/sample_data/sample.tsv +:1:4
(note the : before the 1. It's needed (on develop) to demonstrate the column-positioning bug, until the 2 commits above are applied.)

0a8f6ee - handling args of form +a:b vs +:a:b.
Comments in the code suggest that '+col:row' should apply to only the last sheet on the list, vs. adding a colon, '+:col:row', which should apply to all sheets:

'Return (startsheets:list, startrow:str, startcol:str) from *arg* like "+sheet:subsheet:col:row". Empty sheetstr in startsheets means the starting pos applies to all sheets.'

(The suggestion comes from the phrase Empty sheetstr in startsheets. An empty sheetstr happens only when arg.split(':') has more than 2 items and pos[:-2] is '', which happens when arg follows the pattern +:a:b:
startsheets = pos[:-2]

Currently the behavior is the reverse: +col:row applies to all sheets.
repro: vd sample_data/sample.tsv sample_data/StatusPR.csv +:2:2
and look at the cursor position on each sheet.
This commit changes +:a:b to apply to all sheets, and +a:b to apply only to the last sheet.

da52ac3 - improve error for invalid sheets
Attempting to index a sheet that does not exist, as with:
repro: vd sample_data/sample.tsv +10:0:0
gives a traceback with IndexError: list index out of range.
This commit handles the error and shows a status message of no sheet "10".

a0d4913 - handling subsheet names that are integers
For consistency with sheets/rows/cols, this commit allows indexing subsheets with integers, like:
numeric-subsheet-names.vds.txt
repro: vd -f vds numeric-subsheet-names.vds.txt +0:3:0:0
This is also a change that breaks current behavior, for a subsheet that happens to have a name that is an integer. Such a subsheet would become unable to opened by using its name, as with sheets 5, 6, 7, and 8 in numeric-subsheet-names.vds.txt; +0:5:0:0 currently works, but after this commit only +0:0:0:0 would work.

Thoughts? I'm not so worried about breaking changes, because I don't think the vd + feature is heavily used.

Just to write out all the cases, here's what the args would mean after all these commits:

    +2         = row 2
    +1:        = last sheet; col 1
    +:1:       = all sheets; col 1
    +:2        = last sheet; row 2
    +1:2       = last sheet; col 1, row 2
    +:1:2      = all sheets; col 1, row 2
    +0:1:2     = sheet 0; col 1, row 2
    +:a:1:2    = last sheet, subsheet a; col 1, row 2
    +0:a:1:2   = sheet 0, subsheet a; col 1, row 2
    +0:a:b:1:2 = sheet 0, subsheet a from sheet 0, subsheet b from sheet a; col 1, row 2
    +0:0:1:2   = sheet 0, first subsheet of sheet 0, col 1, row 2
    +1::       = 2nd sheet, col 0, row 0
    +-2::      = 2nd sheet from last, col 0, row 0

@midichef
Copy link
Contributor Author

I fixed the type hint that was breaking in Python 3.8, by adding ' quotes to make it a string:
https://github.com/midichef/visidata/blob/bcf812f0052d54f25a6c1c5d7734f9cec2e86a06/visidata/main.py#L89
I don't understand type hints enough to know what the string does, I'm just doing it because it worked in sort.py.

def sortkey(sheet, r, ordering:'list[tuple[Column, bool]]'=[]):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant