Skip to content

Commit

Permalink
interp: Improve colors when using light background
Browse files Browse the repository at this point in the history
Related to #729
  • Loading branch information
wader committed Oct 10, 2023
1 parent a9051e8 commit c28163f
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 34 deletions.
22 changes: 11 additions & 11 deletions format/json/testdata/json_color.fqtest
Original file line number Diff line number Diff line change
@@ -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
6 changes: 4 additions & 2 deletions pkg/interp/ansi.jq
Original file line number Diff line number Diff line change
@@ -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"}
Expand All @@ -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"}
Expand Down
18 changes: 9 additions & 9 deletions pkg/interp/options.jq
Original file line number Diff line number Diff line change
Expand Up @@ -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 . == ""))
Expand All @@ -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)
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions pkg/interp/testdata/args.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions pkg/interp/testdata/options.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ $ fq -n options
255
]
],
"value": "brightwhite"
"value": "default+bold"
},
{
"ranges": [
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions pkg/interp/testdata/repl.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion pkg/interp/testdata/unicode.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit c28163f

Please sign in to comment.