diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 01935cf..885e844 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,7 @@ # See https://pre-commit.com/hooks.html for more hooks repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.0.1 + rev: v5.0.0 hooks: - id: trailing-whitespace - id: check-yaml diff --git a/completions/powershell/_csview.ps1 b/completions/powershell/_csview.ps1 index 9457229..9545799 100644 --- a/completions/powershell/_csview.ps1 +++ b/completions/powershell/_csview.ps1 @@ -21,29 +21,29 @@ Register-ArgumentCompleter -Native -CommandName 'csview' -ScriptBlock { $completions = @(switch ($command) { 'csview' { - [CompletionResult]::new('-d', 'd', [CompletionResultType]::ParameterName, 'Specify the field delimiter') - [CompletionResult]::new('--delimiter', 'delimiter', [CompletionResultType]::ParameterName, 'Specify the field delimiter') - [CompletionResult]::new('-s', 's', [CompletionResultType]::ParameterName, 'Specify the border style') - [CompletionResult]::new('--style', 'style', [CompletionResultType]::ParameterName, 'Specify the border style') - [CompletionResult]::new('-p', 'p', [CompletionResultType]::ParameterName, 'Specify padding for table cell') - [CompletionResult]::new('--padding', 'padding', [CompletionResultType]::ParameterName, 'Specify padding for table cell') - [CompletionResult]::new('-i', 'i', [CompletionResultType]::ParameterName, 'Specify global indent for table') - [CompletionResult]::new('--indent', 'indent', [CompletionResultType]::ParameterName, 'Specify global indent for table') - [CompletionResult]::new('--sniff', 'sniff', [CompletionResultType]::ParameterName, 'Limit column widths sniffing to the specified number of rows. Specify "0" to cancel limit') - [CompletionResult]::new('--header-align', 'header-align', [CompletionResultType]::ParameterName, 'Specify the alignment of the table header') - [CompletionResult]::new('--body-align', 'body-align', [CompletionResultType]::ParameterName, 'Specify the alignment of the table body') - [CompletionResult]::new('-H', 'H ', [CompletionResultType]::ParameterName, 'Specify that the input has no header row') - [CompletionResult]::new('--no-headers', 'no-headers', [CompletionResultType]::ParameterName, 'Specify that the input has no header row') - [CompletionResult]::new('-n', 'n', [CompletionResultType]::ParameterName, 'Prepend a column of line numbers to the table') - [CompletionResult]::new('--number', 'number', [CompletionResultType]::ParameterName, 'Prepend a column of line numbers to the table') - [CompletionResult]::new('-t', 't', [CompletionResultType]::ParameterName, 'Use ''\t'' as delimiter for tsv') - [CompletionResult]::new('--tsv', 'tsv', [CompletionResultType]::ParameterName, 'Use ''\t'' as delimiter for tsv') - [CompletionResult]::new('-P', 'P ', [CompletionResultType]::ParameterName, 'Disable pager') - [CompletionResult]::new('--disable-pager', 'disable-pager', [CompletionResultType]::ParameterName, 'Disable pager') - [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help') - [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help') - [CompletionResult]::new('-V', 'V ', [CompletionResultType]::ParameterName, 'Print version') - [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version') + [CompletionResult]::new('-d', '-d', [CompletionResultType]::ParameterName, 'Specify the field delimiter') + [CompletionResult]::new('--delimiter', '--delimiter', [CompletionResultType]::ParameterName, 'Specify the field delimiter') + [CompletionResult]::new('-s', '-s', [CompletionResultType]::ParameterName, 'Specify the border style') + [CompletionResult]::new('--style', '--style', [CompletionResultType]::ParameterName, 'Specify the border style') + [CompletionResult]::new('-p', '-p', [CompletionResultType]::ParameterName, 'Specify padding for table cell') + [CompletionResult]::new('--padding', '--padding', [CompletionResultType]::ParameterName, 'Specify padding for table cell') + [CompletionResult]::new('-i', '-i', [CompletionResultType]::ParameterName, 'Specify global indent for table') + [CompletionResult]::new('--indent', '--indent', [CompletionResultType]::ParameterName, 'Specify global indent for table') + [CompletionResult]::new('--sniff', '--sniff', [CompletionResultType]::ParameterName, 'Limit column widths sniffing to the specified number of rows. Specify "0" to cancel limit') + [CompletionResult]::new('--header-align', '--header-align', [CompletionResultType]::ParameterName, 'Specify the alignment of the table header') + [CompletionResult]::new('--body-align', '--body-align', [CompletionResultType]::ParameterName, 'Specify the alignment of the table body') + [CompletionResult]::new('-H', '-H ', [CompletionResultType]::ParameterName, 'Specify that the input has no header row') + [CompletionResult]::new('--no-headers', '--no-headers', [CompletionResultType]::ParameterName, 'Specify that the input has no header row') + [CompletionResult]::new('-n', '-n', [CompletionResultType]::ParameterName, 'Prepend a column of line numbers to the table') + [CompletionResult]::new('--number', '--number', [CompletionResultType]::ParameterName, 'Prepend a column of line numbers to the table') + [CompletionResult]::new('-t', '-t', [CompletionResultType]::ParameterName, 'Use ''\t'' as delimiter for tsv') + [CompletionResult]::new('--tsv', '--tsv', [CompletionResultType]::ParameterName, 'Use ''\t'' as delimiter for tsv') + [CompletionResult]::new('-P', '-P ', [CompletionResultType]::ParameterName, 'Disable pager') + [CompletionResult]::new('--disable-pager', '--disable-pager', [CompletionResultType]::ParameterName, 'Disable pager') + [CompletionResult]::new('-h', '-h', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('-V', '-V ', [CompletionResultType]::ParameterName, 'Print version') + [CompletionResult]::new('--version', '--version', [CompletionResultType]::ParameterName, 'Print version') break } }) diff --git a/completions/zsh/_csview b/completions/zsh/_csview index eade7e4..7288243 100644 --- a/completions/zsh/_csview +++ b/completions/zsh/_csview @@ -15,15 +15,15 @@ _csview() { local context curcontext="$curcontext" state line _arguments "${_arguments_options[@]}" : \ -'-d+[Specify the field delimiter]:DELIMITER: ' \ -'--delimiter=[Specify the field delimiter]:DELIMITER: ' \ +'-d+[Specify the field delimiter]:DELIMITER:_default' \ +'--delimiter=[Specify the field delimiter]:DELIMITER:_default' \ '-s+[Specify the border style]:STYLE:(none ascii ascii2 sharp rounded reinforced markdown grid)' \ '--style=[Specify the border style]:STYLE:(none ascii ascii2 sharp rounded reinforced markdown grid)' \ -'-p+[Specify padding for table cell]:PADDING: ' \ -'--padding=[Specify padding for table cell]:PADDING: ' \ -'-i+[Specify global indent for table]:INDENT: ' \ -'--indent=[Specify global indent for table]:INDENT: ' \ -'--sniff=[Limit column widths sniffing to the specified number of rows. Specify "0" to cancel limit]:LIMIT: ' \ +'-p+[Specify padding for table cell]:PADDING:_default' \ +'--padding=[Specify padding for table cell]:PADDING:_default' \ +'-i+[Specify global indent for table]:INDENT:_default' \ +'--indent=[Specify global indent for table]:INDENT:_default' \ +'--sniff=[Limit column widths sniffing to the specified number of rows. Specify "0" to cancel limit]:LIMIT:_default' \ '--header-align=[Specify the alignment of the table header]:HEADER_ALIGN:(left center right)' \ '--body-align=[Specify the alignment of the table body]:BODY_ALIGN:(left center right)' \ '-H[Specify that the input has no header row]' \ diff --git a/src/cli.rs b/src/cli.rs index 5344654..95113cc 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,11 +1,26 @@ use std::path::PathBuf; -use clap::{Parser, ValueEnum, ValueHint}; +use clap::ValueHint; +use clap::{ + builder::{ + styling::{AnsiColor, Effects}, + Styles, + }, + Parser, ValueEnum, +}; #[derive(Parser)] -#[command(about, version)] -#[command(disable_help_subcommand = true)] -#[command(next_line_help = true)] +#[clap(about, version)] +#[clap(disable_help_subcommand = true)] +#[clap(next_line_help = true)] +#[clap( + styles(Styles::styled() + .header(AnsiColor::Yellow.on_default() | Effects::BOLD) + .usage(AnsiColor::Yellow.on_default() | Effects::BOLD) + .literal(AnsiColor::Green.on_default() | Effects::BOLD) + .placeholder(AnsiColor::Cyan.on_default()) + ) +)] pub struct App { /// File to view. #[arg(name = "FILE", value_hint = ValueHint::FilePath)] diff --git a/src/table/row.rs b/src/table/row.rs index 4d60867..024f384 100644 --- a/src/table/row.rs +++ b/src/table/row.rs @@ -17,7 +17,7 @@ impl<'a> FromIterator<&'a str> for Row<'a> { } } -impl<'a> Row<'a> { +impl Row<'_> { pub fn write(&self, wtr: &mut T, fmt: &Style, widths: &[usize], align: Alignment) -> Result<()> { let sep = fmt.colseps.mid.map(|c| c.to_string()).unwrap_or_default(); write!(wtr, "{:indent$}", "", indent = fmt.indent)?;