feat: Build help text based on terminal width, adjust column widths dynamically
This PR adds maxTableWidth and colRigidity options to TableSettings, allowing the table renderer to target a particular maximum width. colRigidity is a parameter where 1 indicates that the column width should not be reduced, and 0 that it can be adjusted arbitrarily. I made it a number instead of a bool, since it seems plausible to allow for a 0.5 to be reduced by half the amount of a 0, but I only implemented 0 and 1.
I then use this to update the help text generation, which is constrained to use the terminal width as the maximum width. I make the first columns rigid, as the descriptions and types are more likely to take up space and more tolerant to line breaks.
I hope this is reasonable. It dramatically improves the help text for my tool.
Before (regardless of terminal width):
❯ deno run -A jsr:@bids/validator --help
Usage: bids-validator <dataset_directory>
Version: 1.14.13
Description:
This tool checks if a dataset in a given directory is compatible with the Brain Imaging Data Structure specification. To learn more about
Brain Imaging Data Structure visit http://bids.neuroimaging.io
Options:
-h, --help - Show this help.
-V, --version - Show the version number for this program.
--json - Output machine readable JSON
-s, --schema <URL-or-tag> - Specify a schema version to use for validation
-c, --config <file> - Path to a JSON configuration file
-v, --verbose - Log more extensive information about issues
--ignoreWarnings - Disregard non-critical issues
--ignoreNiftiHeaders - Disregard NIfTI header content during validation
--debug <level> - Enable debug output (Default: "ERROR", Values: "NOTSET", "DEBUG", "INFO",
"WARN", "ERROR", "CRITICAL")
--filenameMode - Enable filename checks for newline separated filenames read from stdin
--blacklistModalities <modalities...> - Array of modalities to error on if detected. (Default: [], Values: "MRI", "PET", "MEG", "EEG", "iEEG",
"Microscopy", "NIRS", "MRS")
-r, --recursive - Validate datasets found in derivatives directories in addition to root dataset
-o, --outfile <file> - File to write validation results to.
--color, --no-color [color] - Enable/disable color output (defaults to detected support) (Default: true)
After (88 columns)
❯ deno run -A ~/Projects/bids/bids-validator/bids-validator/src/bids-validator.ts --help
Usage: bids-validator <dataset_directory>
Version: v1.14.15-dev.0-11-g8f3519b3
Description:
This tool checks if a dataset in a given directory is compatible with the Brain
Imaging Data Structure specification. To learn more about Brain Imaging Data
Structure visit http://bids.neuroimaging.io
Options:
-h, --help - Show this help.
-V, --version - Show the version number
for this program.
--json - Output machine readable
JSON
-s, --schema <URL-or-tag> - Specify a schema version
to use for validation
-c, --config <file> - Path to a JSON
configuration file
-v, --verbose - Log more extensive
information about issues
--ignoreWarnings - Disregard non-critical
issues
--ignoreNiftiHeaders - Disregard NIfTI header
content during
validation
--debug <level> - Enable debug output (Default:
"ERROR", Values:
"NOTSET",
"DEBUG", "INFO",
"WARN", "ERROR",
"CRITICAL")
--filenameMode - Enable filename checks
for newline separated
filenames read from
stdin
--blacklistModalities <modalities...> - Array of modalities to (Default: [],
error on if detected. Values: "MRI",
"PET", "MEG",
"EEG", "iEEG",
"Microscopy",
"NIRS", "MRS")
-r, --recursive - Validate datasets found
in derivatives
directories in addition
to root dataset
-o, --outfile <file> - File to write validation
results to.
--color, --no-color [color] - Enable/disable color (Default: true)
output (defaults to
detected support)
142 columns
❯ deno run -A ~/Projects/bids/bids-validator/bids-validator/src/bids-validator.ts --help
Usage: bids-validator <dataset_directory>
Version: v1.14.15-dev.0-11-g8f3519b3
Description:
This tool checks if a dataset in a given directory is compatible with the Brain Imaging Data Structure specification. To learn more about
Brain Imaging Data Structure visit http://bids.neuroimaging.io
Options:
-h, --help - Show this help.
-V, --version - Show the version number for this program.
--json - Output machine readable JSON
-s, --schema <URL-or-tag> - Specify a schema version to use for validation
-c, --config <file> - Path to a JSON configuration file
-v, --verbose - Log more extensive information about issues
--ignoreWarnings - Disregard non-critical issues
--ignoreNiftiHeaders - Disregard NIfTI header content during validation
--debug <level> - Enable debug output (Default: "ERROR", Values: "NOTSET",
"DEBUG", "INFO", "WARN", "ERROR",
"CRITICAL")
--filenameMode - Enable filename checks for newline separated filenames
read from stdin
--blacklistModalities <modalities...> - Array of modalities to error on if detected. (Default: [], Values: "MRI", "PET",
"MEG", "EEG", "iEEG", "Microscopy",
"NIRS", "MRS")
-r, --recursive - Validate datasets found in derivatives directories in
addition to root dataset
-o, --outfile <file> - File to write validation results to.
--color, --no-color [color] - Enable/disable color output (defaults to detected (Default: true)
support)
I think this closes #723. It doesn't enable configuration, but it does do what I think they want. It's certainly what I want.
If someone wants to try this out, you can replace @cliffy/command with @effigies/[email protected] and @cliffy/table with @effigies/[email protected].
@c4spar Just checking in to see if there's any interest in this patch. Happy to adjust to suit the needs/conventions of the project.
I tried out your packages @effigies it certainly helps when the terminal is narrow but when it is wide it would be nice if it made use of the space.
Unless I'm missing something this still caps the max width at 150?
this.width = Math.min(Deno.consoleSize().columns, 150);
Here is an example:
-s, --stage <stage> - The Xero stage or environment name to connect to. (required, Values: "test", "test-dev", "uat", "uat-dev",
"prod")
-r, --region <region> - The AWS Region the cluster resides in. (Default: "based on stage:
test=ap-southeast-2,uat=us-west-2,prod=us-east-1")
I'd prefer something like
-s, --stage <stage> - The Xero stage or environment name to connect to. (required, Values: "test", "test-dev", "uat", "uat-dev", "prod")
-r, --region <region> - The AWS Region the cluster resides in. (Default: "based on stage: test=ap-southeast-2,uat=us-west-2,prod=us-east-1")
If the terminal supports it.
Another option might be to put the hints below the option.
-s, --stage <stage> - The Xero stage or environment name to connect to.
(required, Values: "test", "test-dev", "uat", "uat-dev", "prod")
-r, --region <region> - The AWS Region the cluster resides in.
(Default: "based on stage: test=ap-southeast-2,uat=us-west-2,prod=us-east-1")