1
1
mirror of https://github.com/wader/fq.git synced 2024-12-27 15:42:07 +03:00

interp: Improve colors when using light background

Related to #729
This commit is contained in:
Mattias Wadman 2023-10-10 10:55:12 +02:00
parent a9051e8c5a
commit c28163f8f4
7 changed files with 36 additions and 34 deletions

View File

@ -1,21 +1,21 @@
# TODO: tests descorator with different types, move this test
$ fq -C d json.gz
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|.{}: json.gz (gzip)
0x000|1f 8b |.. | identification: raw bits (valid)
0x000| 08 | . | compression_method: "deflate" (8)
| | | flags{}:
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|.{}: json.gz (gzip)
0x000|1f 8b |.. | identification: raw bits (valid)
0x000| 08 | . | compression_method: "deflate" (8)
| | | flags{}:
0x000| 00 | . | text: false
0x000| 00 | . | header_crc: false
0x000| 00 | . | extra: false
0x000| 00 | . | name: false
0x000| 00 | . | comment: false
0x000| 00 | . | reserved: 0
0x000| 65 0a 08 61 | e..a | mtime: 1627916901 (2021-08-02T15:08:21Z)
0x000| 65 0a 08 61 | e..a | mtime: 1627916901 (2021-08-02T15:08:21Z)
0x000| 00 | . | extra_flags: 0
0x000| 03 | . | os: "unix" (3)
0x000| 03 | . | os: "unix" (3)
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
0x0|7b 22 61 22 3a 20 31 32 33 7d 0a| |{"a": 123}.| | uncompressed: {} (json)
0x000| ab 56 4a 54 b2 52| .VJT.R| compressed: raw bits
0x010|30 34 32 ae e5 02 00 |042.... |
0x010| 20 ac d2 9c |  ... | crc32: 0x9cd2ac20 (valid)
0x010| 0b 00 00 00| | ....|| isize: 11
0x0|7b 22 61 22 3a 20 31 32 33 7d 0a| |{"a": 123}.| | uncompressed: {} (json)
0x000| ab 56 4a 54 b2 52| .VJT.R| compressed: raw bits
0x010|30 34 32 ae e5 02 00 |042.... |
0x010| 20 ac d2 9c | ... | crc32: 0x9cd2ac20 (valid)
0x010| 0b 00 00 00| | ....|| isize: 11

View File

@ -1,6 +1,8 @@
def _esc: "\u001b";
def _ansi_codes:
{ black: {set: "30", reset: "39"}
{ bold: {set: "1", reset: "0"}
, faint: {set: "2", reset: "0"}
, black: {set: "30", reset: "39"}
, red: {set: "31", reset: "39"}
, green: {set: "32", reset: "39"}
, yellow: {set: "33", reset: "39"}
@ -16,7 +18,7 @@ def _ansi_codes:
, brightmagenta: {set: "95", reset: "39"}
, brightcyan: {set: "96", reset: "39"}
, brightwhite: {set: "97", reset: "39"}
, reset: {set: "39", reset: "39"}
, default: {set: "39", reset: "39"}
, bgblack: {set: "40", reset: "49"}
, bgred: {set: "41", reset: "49"}
, bggreen: {set: "42", reset: "49"}

View File

@ -10,16 +10,16 @@ def _opt_build_default_fixed:
, argjson: []
, array_truncate: 50
, bits_format: "string"
# 0-0xff=brightwhite,0=brightblack,32-126:9-13=white
# 0-0xff=brightwhite,0=brightblack,32-126:9-13=default
, byte_colors:
[ { ranges: [[0,255]]
, value: "brightwhite"
, value: "default+bold"
}
, { ranges: [[0]]
, value: "brightblack"
}
, { ranges: [[32,126],[9,13]]
, value: "white"
, value: "default"
}
]
, color: ($stdout.is_terminal and (env.NO_COLOR | . == null or . == ""))
@ -30,15 +30,15 @@ def _opt_build_default_fixed:
, number: "cyan"
, string: "green"
, objectkey: "brightblue"
, array: "white"
, object: "white"
, index: "white"
, value: "white"
, array: "default"
, object: "default"
, index: "default"
, value: "default"
, error: "brightred"
, dumpheader: "yellow+underline"
, dumpaddr: "yellow"
, prompt_repl_level: "brightblack"
, prompt_value: "white"
, prompt_value: "default"
}
, compact: false
, completion_timeout: (env.COMPLETION_TIMEOUT | if . != null then tonumber else 1 end)
@ -278,7 +278,7 @@ def _opt_from_array: tojson;
# TODO: cleanup
def _trim: capture("^\\s*(?<str>.*?)\\s*$"; "").str;
# "0-255=brightwhite,0=brightblack,32-126:9-13=white" -> [{"ranges": [[0-255]], value: "brightwhite"}, ...]
# "0-255=brightwhite,0=brightblack,32-126:9-13=default" -> [{"ranges": [[0-255]], value: "brightwhite"}, ...]
def _csv_ranges_to_array:
( split(",")
| map(

View File

@ -73,9 +73,9 @@ argdecode []
argjson []
array_truncate 50
bits_format string
byte_colors 0-255=brightwhite,0=brightblack,32-126:9-13=white
byte_colors 0-255=default+bold,0=brightblack,32-126:9-13=default
color false
colors array=white,dumpaddr=yellow,dumpheader=yellow+underline,error=brightred,false=yellow,index=white,null=brightblack,number=cyan,object=white,objectkey=brightblue,prompt_repl_level=brightblack,prompt_value=white,string=green,true=yellow,value=white
colors array=default,dumpaddr=yellow,dumpheader=yellow+underline,error=brightred,false=yellow,index=default,null=brightblack,number=cyan,object=default,objectkey=brightblue,prompt_repl_level=brightblack,prompt_value=default,string=green,true=yellow,value=default
compact false
completion_timeout 10
decode_group probe

View File

@ -16,7 +16,7 @@ $ fq -n options
255
]
],
"value": "brightwhite"
"value": "default+bold"
},
{
"ranges": [
@ -37,26 +37,26 @@ $ fq -n options
13
]
],
"value": "white"
"value": "default"
}
],
"color": false,
"colors": {
"array": "white",
"array": "default",
"dumpaddr": "yellow",
"dumpheader": "yellow+underline",
"error": "brightred",
"false": "yellow",
"index": "white",
"index": "default",
"null": "brightblack",
"number": "cyan",
"object": "white",
"object": "default",
"objectkey": "brightblue",
"prompt_repl_level": "brightblack",
"prompt_value": "white",
"prompt_value": "default",
"string": "green",
"true": "yellow",
"value": "white"
"value": "default"
},
"compact": false,
"completion_timeout": 10,

View File

@ -6,9 +6,9 @@ null
null> 1+1
2
null> repl({color: true})
> null> )
> null> )
^ unexpected token ")"
> null> ^D
> null> ^D
null> )
^ unexpected token ")"
null>

View File

@ -3,7 +3,7 @@ $ _STDOUT_IS_TERMINAL=0 NO_COLOR= CLIUNICODE=1 fq -n '[123] | hexdump'
0x0|7b| |{| |.: raw bits 0x0-0x0.7 (1)
$ _STDOUT_IS_TERMINAL=1 NO_COLOR= CLIUNICODE=1 fq -n '[123] | hexdump'
00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f│0123456789abcdef│
0x0│7b│ │{│ │.: raw bits 0x0-0x0.7 (1)
0x0│7b│ │{│ │.: raw bits 0x0-0x0.7 (1)
$ NO_COLOR=1 fq -Un '[123] | hexdump'
│00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f│0123456789abcdef│
0x0│7b│ │{│ │.: raw bits 0x0-0x0.7 (1)