1
1
mirror of https://github.com/wader/fq.git synced 2024-12-23 13:22:58 +03:00

interp: Wrap Binary in decodeValue to fix prompt issue with bits/bytes format

This commit is contained in:
Mattias Wadman 2023-01-04 13:08:01 +01:00
parent 162cb40d9f
commit 8b49b42fa3
5 changed files with 14 additions and 6 deletions

View File

@ -2,13 +2,13 @@
hello hello
$ fq -d bits '., .size, .[8:-8]' hello $ fq -d bits '., .size, .[8:-8]' hello
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef| |00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
0x0|68 65 6c 6c 6f 0a| |hello.| |.: raw bits 0x0-0x5.7 (6) 0x0|68 65 6c 6c 6f 0a| |hello.| |.: raw bits (bits)
48 48
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef| |00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
0x0| 65 6c 6c 6f | ello |.: raw bits 0x1-0x4.7 (4) 0x0| 65 6c 6c 6f | ello |.: raw bits 0x1-0x4.7 (4)
$ fq -d bytes '., .size, .[1:-1]' hello $ fq -d bytes '., .size, .[1:-1]' hello
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef| |00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
0x0|68 65 6c 6c 6f 0a| |hello.| |.: raw bits 0x0-0x5.7 (6) 0x0|68 65 6c 6c 6f 0a| |hello.| |.: raw bits (bytes)
6 6
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef| |00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
0x0| 65 6c 6c 6f | ello |.: raw bits 0x1-0x4.7 (4) 0x0| 65 6c 6c 6f | ello |.: raw bits 0x1-0x4.7 (4)

View File

@ -433,8 +433,11 @@ func makeDecodeValueOut(dv *decode.Value, kind decodeValueKind, out any) any {
decodeValueBase: decodeValueBase{dv: dv}, decodeValueBase: decodeValueBase{dv: dv},
} }
case Binary: case Binary:
// used by bytes and bits format return decodeValue{
return vvv JQValue: vvv,
decodeValueBase: decodeValueBase{dv: dv},
}
default: default:
panic(fmt.Sprintf("unreachable vv %#+v", vvv)) panic(fmt.Sprintf("unreachable vv %#+v", vvv))
} }

View File

@ -49,7 +49,9 @@ func decoratorFromOptions(opts Options) Decorator {
return d.True return d.True
} }
return d.False return d.False
case string, bitio.Reader: case string,
bitio.Reader,
Binary:
return d.String return d.String
case int, float64, int64, uint64: case int, float64, int64, uint64:
// TODO: clean up number types // TODO: clean up number types

View File

@ -42,7 +42,8 @@ func previewValue(v any, df scalar.DisplayFormat) string {
return strings.ReplaceAll(s, `\u007f`, `\x7f`) return strings.ReplaceAll(s, `\u007f`, `\x7f`)
case nil: case nil:
return "null" return "null"
case bitio.Reader: case bitio.Reader,
Binary:
return "raw bits" return "raw bits"
case *big.Int: case *big.Int:
return mathex.PadFormatBigInt(vv, df.FormatBase(), true, 0) return mathex.PadFormatBigInt(vv, df.FormatBase(), true, 0)

View File

@ -107,6 +107,8 @@ $ fq -i -d json . test.mp3
json!> ^D json!> ^D
$ fq -i -n '"[]" | json' $ fq -i -n '"[]" | json'
json> ^D json> ^D
$ fq -i -d bytes . test.mp3
bytes> ^D
$ fq -n repl $ fq -n repl
exitcode: 3 exitcode: 3
stderr: stderr: