mirror of
https://github.com/wader/fq.git
synced 2024-11-25 23:13:19 +03:00
cli: Add -M -C support and default to color if tty
This commit is contained in:
parent
6fa5ae8ca3
commit
93fd097b53
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
@ -11,7 +11,6 @@
|
||||
"bzip",
|
||||
"CCIT",
|
||||
"chzyer",
|
||||
"CLICOLOR",
|
||||
"CLIUNICODE",
|
||||
"CLLID",
|
||||
"coef",
|
||||
|
@ -44,12 +44,13 @@ Use Ctrl-C to exits REPL, Ctrl-C to interrupt current evaluation.
|
||||
<pre sh>
|
||||
$ fq -h
|
||||
fq - jq for files
|
||||
Tool, language and decoders for exploring binary data.
|
||||
Tool, language and format decoders for exploring binary data.
|
||||
For more information see https://github.com/wader/fq
|
||||
|
||||
Usage: fq [OPTIONS] [--] [EXPR] [FILE...]
|
||||
--arg NAME VALUE Set variable $NAME to string VALUE
|
||||
--argjson NAME JSON Set variable $NAME to JSON
|
||||
--color-output,-C Force color output
|
||||
--compact-output,-c Compact output
|
||||
--decode,-d NAME Decode format (probe)
|
||||
--decode-file NAME PATH Set variable $NAME to decode of file
|
||||
@ -58,6 +59,7 @@ Usage: fq [OPTIONS] [--] [EXPR] [FILE...]
|
||||
--help,-h Show help
|
||||
--include-path,-L PATH Include search path
|
||||
--join-output,-j No newline between outputs
|
||||
--monochrome-output,-M Force monochrome output
|
||||
--null-input,-n Null input (use input/0 and inputs/0 to read input)
|
||||
--null-output,-0 Null byte between outputs
|
||||
--option,-o KEY=VALUE Set option, eg: color=true
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env expect
|
||||
# TODO: move this script somehwere else
|
||||
# TODO: run without NODECODEPROGRESS
|
||||
# TODO: run without NO_DECODE_PROGRESS
|
||||
# TODO: test interrupt?
|
||||
|
||||
log_user 1
|
||||
@ -10,7 +10,7 @@ expect_after {
|
||||
timeout {exit 1}
|
||||
}
|
||||
|
||||
spawn sh -c "NODECODEPROGRESS=1 fq -o color=false -i . pkg/interp/testdata/test.mp3 2>&1"
|
||||
spawn sh -c "NO_DECODE_PROGRESS=1 fq -o color=false -i . pkg/interp/testdata/test.mp3 2>&1"
|
||||
|
||||
expect "mp3> "
|
||||
|
||||
|
@ -80,7 +80,8 @@ func (tcr *testCaseRun) Interrupt() chan struct{} { return nil }
|
||||
|
||||
func (tcr *testCaseRun) Environ() []string {
|
||||
return []string{
|
||||
"NODECODEPROGRESS=1",
|
||||
"NO_COLOR=1",
|
||||
"NO_DECODE_PROGRESS=1",
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ def _build_default_options:
|
||||
arraytruncate: 50,
|
||||
bitsformat: "snippet",
|
||||
bytecolors: "0-0xff=brightwhite,0=brightblack,32-126:9-13=white",
|
||||
color: ($stdout.is_terminal and env.CLICOLOR != null),
|
||||
color: ($stdout.is_terminal and (env.NO_COLOR | . == null or . == "")),
|
||||
colors: (
|
||||
{
|
||||
null: "brightblack",
|
||||
@ -65,7 +65,7 @@ def _build_default_options:
|
||||
compact: false,
|
||||
decode_file: [],
|
||||
decode_format: "probe",
|
||||
decode_progress: (env.NODECODEPROGRESS == null),
|
||||
decode_progress: (env.NO_DECODE_PROGRESS == null),
|
||||
depth: 0,
|
||||
# TODO: intdiv 2 * 2 to get even number, nice or maybe not needed?
|
||||
displaybytes: (if $stdout.is_terminal then [intdiv(intdiv($stdout.width; 8); 2) * 2, 4] | max else 16 end),
|
||||
@ -554,6 +554,12 @@ def _main:
|
||||
description: "Compact output",
|
||||
bool: true
|
||||
},
|
||||
"color_output": {
|
||||
short: "-C",
|
||||
long: "--color-output",
|
||||
description: "Force color output",
|
||||
bool: true
|
||||
},
|
||||
"decode_format": {
|
||||
short: "-d",
|
||||
long: "--decode",
|
||||
@ -608,6 +614,12 @@ def _main:
|
||||
description: "Null input (use input/0 and inputs/0 to read input)",
|
||||
bool: true
|
||||
},
|
||||
"monochrome_output": {
|
||||
short: "-M",
|
||||
long: "--monochrome-output",
|
||||
description: "Force monochrome output",
|
||||
bool: true
|
||||
},
|
||||
"option": {
|
||||
short: "-o",
|
||||
long: "--option",
|
||||
@ -659,7 +671,7 @@ def _main:
|
||||
};
|
||||
def _banner:
|
||||
( "fq - jq for files"
|
||||
, "Tool, language and decoders for exploring binary data."
|
||||
, "Tool, language and format decoders for exploring binary data."
|
||||
, "For more information see https://github.com/wader/fq"
|
||||
);
|
||||
def _usage($arg0; $version):
|
||||
@ -675,8 +687,8 @@ def _main:
|
||||
| _default_options($default_opts) as $_
|
||||
# combine --args and -o key=value args
|
||||
| ( $default_opts
|
||||
+ ($parsed_args.option | _to_options)
|
||||
+ $parsed_args
|
||||
+ ($parsed_args.option | _to_options)
|
||||
) as $args_opts
|
||||
| _options_stack(
|
||||
[ $args_opts
|
||||
@ -697,6 +709,11 @@ def _main:
|
||||
end
|
||||
)
|
||||
),
|
||||
color: (
|
||||
if $args_opts.monochrome_output == true then false
|
||||
elif $args_opts.color_output == true then true
|
||||
end
|
||||
),
|
||||
decode_file: (
|
||||
( $args_opts.decode_file
|
||||
| if . then
|
||||
|
4
pkg/interp/testdata/args.fqtest
vendored
4
pkg/interp/testdata/args.fqtest
vendored
@ -5,12 +5,13 @@ stderr:
|
||||
Usage: fq [OPTIONS] [--] [EXPR] [FILE...]
|
||||
$ fq -h
|
||||
fq - jq for files
|
||||
Tool, language and decoders for exploring binary data.
|
||||
Tool, language and format decoders for exploring binary data.
|
||||
For more information see https://github.com/wader/fq
|
||||
|
||||
Usage: fq [OPTIONS] [--] [EXPR] [FILE...]
|
||||
--arg NAME VALUE Set variable $NAME to string VALUE
|
||||
--argjson NAME JSON Set variable $NAME to JSON
|
||||
--color-output,-C Force color output
|
||||
--compact-output,-c Compact output
|
||||
--decode,-d NAME Decode format (probe)
|
||||
--decode-file NAME PATH Set variable $NAME to decode of file
|
||||
@ -19,6 +20,7 @@ Usage: fq [OPTIONS] [--] [EXPR] [FILE...]
|
||||
--help,-h Show help
|
||||
--include-path,-L PATH Include search path
|
||||
--join-output,-j No newline between outputs
|
||||
--monochrome-output,-M Force monochrome output
|
||||
--null-input,-n Null input (use input/0 and inputs/0 to read input)
|
||||
--null-output,-0 Null byte between outputs
|
||||
--option,-o KEY=VALUE Set option, eg: color=true
|
||||
|
9
pkg/interp/testdata/color.fqtest
vendored
Normal file
9
pkg/interp/testdata/color.fqtest
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
# TODO: $ NO_COLOR= fq -n 123
|
||||
$ fq -Cn 123
|
||||
[36m123[m
|
||||
$ fq --color-output -n 123
|
||||
[36m123[m
|
||||
$ fq -Mn 123
|
||||
123
|
||||
$ fq --monochrome-output -n 123
|
||||
123
|
Loading…
Reference in New Issue
Block a user