headson 0.5.3__tar.gz → 0.6.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of headson might be problematic. Click here for more details.
- {headson-0.5.3 → headson-0.6.0}/Cargo.lock +1 -1
- {headson-0.5.3 → headson-0.6.0}/Cargo.toml +1 -1
- {headson-0.5.3 → headson-0.6.0}/PKG-INFO +16 -2
- {headson-0.5.3 → headson-0.6.0}/README.md +15 -1
- headson-0.6.0/docs/assets/logo.png +0 -0
- headson-0.6.0/docs/assets/logo.svg +70 -0
- headson-0.6.0/docs/assets/tapes/demo.gif +0 -0
- {headson-0.5.3 → headson-0.6.0}/pyproject.toml +1 -1
- {headson-0.5.3 → headson-0.6.0}/python/Cargo.lock +2 -2
- {headson-0.5.3 → headson-0.6.0}/python/Cargo.toml +1 -1
- {headson-0.5.3 → headson-0.6.0}/python/src/lib.rs +2 -2
- {headson-0.5.3 → headson-0.6.0}/src/json_ingest/samplers/default.rs +0 -2
- {headson-0.5.3 → headson-0.6.0}/src/lib.rs +18 -6
- {headson-0.5.3 → headson-0.6.0}/src/main.rs +41 -6
- headson-0.6.0/src/serialization/color.rs +113 -0
- {headson-0.5.3 → headson-0.6.0}/src/serialization/fileset.rs +2 -2
- {headson-0.5.3 → headson-0.6.0}/src/serialization/mod.rs +248 -41
- headson-0.6.0/src/serialization/output.rs +98 -0
- headson-0.6.0/src/serialization/snapshots/headson__serialization__tests__array_omitted_js_head.snap +9 -0
- headson-0.6.0/src/serialization/snapshots/headson__serialization__tests__array_omitted_js_tail.snap +9 -0
- headson-0.6.0/src/serialization/snapshots/headson__serialization__tests__array_omitted_pseudo_head.snap +9 -0
- headson-0.6.0/src/serialization/snapshots/headson__serialization__tests__array_omitted_pseudo_tail.snap +9 -0
- headson-0.6.0/src/serialization/snapshots/headson__serialization__tests__inline_open_array_in_object_json.snap +10 -0
- headson-0.6.0/src/serialization/templates/core.rs +124 -0
- headson-0.6.0/src/serialization/templates/js.rs +75 -0
- headson-0.6.0/src/serialization/templates/json.rs +29 -0
- headson-0.6.0/src/serialization/templates/mod.rs +53 -0
- headson-0.6.0/src/serialization/templates/pseudo.rs +69 -0
- headson-0.6.0/src/serialization/types.rs +41 -0
- headson-0.6.0/src/utils/json.rs +11 -0
- headson-0.5.3/src/serialization/templates/core.rs +0 -92
- headson-0.5.3/src/serialization/templates/js.rs +0 -83
- headson-0.5.3/src/serialization/templates/json.rs +0 -22
- headson-0.5.3/src/serialization/templates/mod.rs +0 -45
- headson-0.5.3/src/serialization/templates/pseudo.rs +0 -60
- headson-0.5.3/src/serialization/types.rs +0 -18
- headson-0.5.3/src/utils/json.rs +0 -6
- {headson-0.5.3 → headson-0.6.0}/JSONTestSuite/LICENSE +0 -0
- {headson-0.5.3 → headson-0.6.0}/JSONTestSuite/README.md +0 -0
- {headson-0.5.3 → headson-0.6.0}/LICENSE +0 -0
- {headson-0.5.3 → headson-0.6.0}/docs/assets/algorithm.svg +0 -0
- {headson-0.5.3 → headson-0.6.0}/python/README.md +0 -0
- {headson-0.5.3 → headson-0.6.0}/python/headson/__init__.py +0 -0
- {headson-0.5.3 → headson-0.6.0}/src/json_ingest/builder.rs +0 -0
- {headson-0.5.3 → headson-0.6.0}/src/json_ingest/mod.rs +0 -0
- {headson-0.5.3 → headson-0.6.0}/src/json_ingest/samplers/head.rs +0 -0
- {headson-0.5.3 → headson-0.6.0}/src/json_ingest/samplers/mod.rs +0 -0
- {headson-0.5.3 → headson-0.6.0}/src/json_ingest/samplers/tail.rs +0 -0
- {headson-0.5.3 → headson-0.6.0}/src/order/build.rs +0 -0
- {headson-0.5.3 → headson-0.6.0}/src/order/mod.rs +0 -0
- {headson-0.5.3 → headson-0.6.0}/src/order/scoring.rs +0 -0
- {headson-0.5.3 → headson-0.6.0}/src/order/snapshots/headson__order__build__tests__order_empty_array_order.snap +0 -0
- {headson-0.5.3 → headson-0.6.0}/src/order/snapshots/headson__order__build__tests__order_single_string_array_order.snap +0 -0
- {headson-0.5.3 → headson-0.6.0}/src/order/types.rs +0 -0
- {headson-0.5.3 → headson-0.6.0}/src/serialization/snapshots/headson__serialization__tests__arena_render_empty.snap +0 -0
- {headson-0.5.3 → headson-0.6.0}/src/serialization/snapshots/headson__serialization__tests__arena_render_single.snap +0 -0
- {headson-0.5.3 → headson-0.6.0}/src/snapshots/headson__order__tests__order_empty_array_order.snap +0 -0
- {headson-0.5.3 → headson-0.6.0}/src/snapshots/headson__order__tests__order_single_string_array_order.snap +0 -0
- {headson-0.5.3 → headson-0.6.0}/src/snapshots/headson__order__tests__pq_empty_array_queue.snap +0 -0
- {headson-0.5.3 → headson-0.6.0}/src/snapshots/headson__order__tests__pq_single_string_array_queue.snap +0 -0
- {headson-0.5.3 → headson-0.6.0}/src/snapshots/headson__queue__tests__pq_empty_array_queue.snap +0 -0
- {headson-0.5.3 → headson-0.6.0}/src/snapshots/headson__queue__tests__pq_single_string_array_queue.snap +0 -0
- {headson-0.5.3 → headson-0.6.0}/src/snapshots/headson__tree__tests__build_tree_empty.snap +0 -0
- {headson-0.5.3 → headson-0.6.0}/src/snapshots/headson__tree__tests__build_tree_single.snap +0 -0
- {headson-0.5.3 → headson-0.6.0}/src/utils/graph.rs +0 -0
- {headson-0.5.3 → headson-0.6.0}/src/utils/mod.rs +0 -0
- {headson-0.5.3 → headson-0.6.0}/src/utils/search.rs +0 -0
- {headson-0.5.3 → headson-0.6.0}/src/utils/text.rs +0 -0
- {headson-0.5.3 → headson-0.6.0}/src/utils/tree_arena.rs +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: headson
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.6.0
|
|
4
4
|
Classifier: Programming Language :: Python
|
|
5
5
|
Classifier: Programming Language :: Python :: 3
|
|
6
6
|
Classifier: Programming Language :: Rust
|
|
@@ -13,7 +13,13 @@ Keywords: json,preview,summarize,cli,bindings
|
|
|
13
13
|
Requires-Python: >=3.10
|
|
14
14
|
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
<h1 align="center">
|
|
17
|
+
<img src="https://raw.githubusercontent.com/kantord/headson/main/docs/assets/logo.svg" alt="headson" width="600" height="99" />
|
|
18
|
+
</h1>
|
|
19
|
+
<p align="center">
|
|
20
|
+
<img src="https://raw.githubusercontent.com/kantord/headson/main/docs/assets/tapes/demo.gif" alt="Terminal demo" width="1560" height="900" />
|
|
21
|
+
<br/>
|
|
22
|
+
</p>
|
|
17
23
|
|
|
18
24
|
Head/tail for JSON — but structure‑aware. Get a compact preview that shows both the shape and representative values of your data, all within a strict character budget.
|
|
19
25
|
|
|
@@ -134,6 +140,14 @@ headson -n 120 -f json users.json
|
|
|
134
140
|
# {"users":[{"id":1,"name":"Ana","roles":["admin"]}],"meta":{"count":2}}
|
|
135
141
|
```
|
|
136
142
|
|
|
143
|
+
## Terminal Demos
|
|
144
|
+
|
|
145
|
+
Regenerate locally:
|
|
146
|
+
|
|
147
|
+
- Place tapes under docs/tapes (e.g., docs/tapes/demo.tape)
|
|
148
|
+
- Run: cargo make tapes
|
|
149
|
+
- Outputs are written to docs/assets/tapes
|
|
150
|
+
|
|
137
151
|
## Python Bindings
|
|
138
152
|
|
|
139
153
|
A thin Python extension module is available on PyPI as `headson`.
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
<h1 align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/kantord/headson/main/docs/assets/logo.svg" alt="headson" width="600" height="99" />
|
|
3
|
+
</h1>
|
|
4
|
+
<p align="center">
|
|
5
|
+
<img src="https://raw.githubusercontent.com/kantord/headson/main/docs/assets/tapes/demo.gif" alt="Terminal demo" width="1560" height="900" />
|
|
6
|
+
<br/>
|
|
7
|
+
</p>
|
|
2
8
|
|
|
3
9
|
Head/tail for JSON — but structure‑aware. Get a compact preview that shows both the shape and representative values of your data, all within a strict character budget.
|
|
4
10
|
|
|
@@ -119,6 +125,14 @@ headson -n 120 -f json users.json
|
|
|
119
125
|
# {"users":[{"id":1,"name":"Ana","roles":["admin"]}],"meta":{"count":2}}
|
|
120
126
|
```
|
|
121
127
|
|
|
128
|
+
## Terminal Demos
|
|
129
|
+
|
|
130
|
+
Regenerate locally:
|
|
131
|
+
|
|
132
|
+
- Place tapes under docs/tapes (e.g., docs/tapes/demo.tape)
|
|
133
|
+
- Run: cargo make tapes
|
|
134
|
+
- Outputs are written to docs/assets/tapes
|
|
135
|
+
|
|
122
136
|
## Python Bindings
|
|
123
137
|
|
|
124
138
|
A thin Python extension module is available on PyPI as `headson`.
|
|
Binary file
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
2
|
+
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
|
3
|
+
|
|
4
|
+
<svg
|
|
5
|
+
width="18.529102mm"
|
|
6
|
+
height="3.043225mm"
|
|
7
|
+
viewBox="0 0 18.529102 3.043225"
|
|
8
|
+
version="1.1"
|
|
9
|
+
id="svg1"
|
|
10
|
+
inkscape:version="1.4.2 (ebf0e940d0, 2025-05-08)"
|
|
11
|
+
sodipodi:docname="logo.svg"
|
|
12
|
+
inkscape:export-filename="logo.png"
|
|
13
|
+
inkscape:export-xdpi="500"
|
|
14
|
+
inkscape:export-ydpi="500"
|
|
15
|
+
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
|
16
|
+
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
|
17
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
18
|
+
xmlns:svg="http://www.w3.org/2000/svg">
|
|
19
|
+
<sodipodi:namedview
|
|
20
|
+
id="namedview1"
|
|
21
|
+
pagecolor="#ffffff"
|
|
22
|
+
bordercolor="#000000"
|
|
23
|
+
borderopacity="0.25"
|
|
24
|
+
inkscape:showpageshadow="2"
|
|
25
|
+
inkscape:pageopacity="0.0"
|
|
26
|
+
inkscape:pagecheckerboard="0"
|
|
27
|
+
inkscape:deskcolor="#d1d1d1"
|
|
28
|
+
inkscape:document-units="mm"
|
|
29
|
+
inkscape:zoom="27.623569"
|
|
30
|
+
inkscape:cx="27.856647"
|
|
31
|
+
inkscape:cy="5.8645572"
|
|
32
|
+
inkscape:window-width="3840"
|
|
33
|
+
inkscape:window-height="2124"
|
|
34
|
+
inkscape:window-x="1080"
|
|
35
|
+
inkscape:window-y="748"
|
|
36
|
+
inkscape:window-maximized="1"
|
|
37
|
+
inkscape:current-layer="layer1" />
|
|
38
|
+
<defs id="defs1">
|
|
39
|
+
<style type="text/css"><![CDATA[
|
|
40
|
+
.wordmark { fill: #000000; }
|
|
41
|
+
@media (prefers-color-scheme: dark) {
|
|
42
|
+
.wordmark { fill: #ffffff; }
|
|
43
|
+
}
|
|
44
|
+
]]></style>
|
|
45
|
+
</defs>
|
|
46
|
+
<g
|
|
47
|
+
inkscape:label="Layer 1"
|
|
48
|
+
inkscape:groupmode="layer"
|
|
49
|
+
id="layer1"
|
|
50
|
+
transform="translate(-62.9858,-133.27801)">
|
|
51
|
+
<g
|
|
52
|
+
id="text1"
|
|
53
|
+
class="wordmark"
|
|
54
|
+
style="font-size:3.175px;stroke-width:0.244"
|
|
55
|
+
aria-label="head{…}son">
|
|
56
|
+
<path
|
|
57
|
+
style="font-family:'Roboto Mono';-inkscape-font-specification:'Roboto Mono'"
|
|
58
|
+
d="m 63.272604,134.32601 v -0.95343 H 62.9858 v 2.38125 h 0.286804 v -1.21853 q 0.03101,-0.0496 0.06976,-0.0899 0.04031,-0.0419 0.08682,-0.0729 0.05891,-0.0403 0.128674,-0.062 0.06976,-0.0217 0.147278,-0.0217 0.09457,-0.002 0.167432,0.0264 0.07286,0.0264 0.120923,0.0806 0.04496,0.0496 0.06821,0.12558 0.02326,0.0744 0.02326,0.17363 v 1.05885 h 0.286804 v -1.05575 q 0,-0.16898 -0.04186,-0.29145 -0.04031,-0.12403 -0.116272,-0.20464 -0.07596,-0.0806 -0.184485,-0.11783 -0.10697,-0.0387 -0.238745,-0.0387 -0.100769,0.002 -0.190686,0.0294 -0.08837,0.0279 -0.162781,0.0822 -0.04651,0.0326 -0.08837,0.076 -0.04186,0.0419 -0.07596,0.093 z m 2.359546,1.45883 q 0.244947,0 0.410828,-0.0977 0.167431,-0.0992 0.251147,-0.22635 l -0.175183,-0.13642 q -0.07906,0.10232 -0.198437,0.16433 -0.119373,0.062 -0.272852,0.062 -0.116272,0 -0.21239,-0.0434 -0.09612,-0.0434 -0.164331,-0.11937 -0.06666,-0.0713 -0.10542,-0.16433 -0.03721,-0.093 -0.04806,-0.21549 v -0.0109 h 1.198376 v -0.12868 q 0,-0.17518 -0.04496,-0.32556 -0.04341,-0.15038 -0.133325,-0.262 -0.08992,-0.11007 -0.226343,-0.17208 -0.134876,-0.0636 -0.31626,-0.0636 -0.144177,0 -0.282153,0.0589 -0.136426,0.0589 -0.243396,0.16898 -0.108521,0.11162 -0.173633,0.27285 -0.06511,0.15968 -0.06511,0.36277 v 0.0651 q 0,0.17519 0.05891,0.32401 0.05891,0.14883 0.164331,0.25735 0.10542,0.10852 0.252698,0.16898 0.148828,0.0605 0.325561,0.0605 z m -0.03721,-1.50379 q 0.110071,0 0.189136,0.0403 0.08061,0.0403 0.133325,0.10542 0.05271,0.0651 0.08217,0.15503 0.02945,0.0884 0.02945,0.16588 v 0.0139 h -0.90227 q 0.01705,-0.11627 0.05891,-0.20464 0.04341,-0.0899 0.10542,-0.15192 0.06201,-0.0605 0.139526,-0.0915 0.07752,-0.0326 0.164331,-0.0326 z m 2.303736,1.47278 h 0.299206 v -0.0248 q -0.02791,-0.0698 -0.04341,-0.16279 -0.0155,-0.0946 -0.0155,-0.17828 v -0.7798 q 0,-0.14107 -0.05116,-0.24649 -0.05116,-0.10542 -0.139526,-0.17674 -0.08992,-0.0698 -0.21239,-0.10387 -0.122473,-0.0357 -0.2651,-0.0357 -0.15658,0 -0.280603,0.0434 -0.122473,0.0434 -0.20774,0.11317 -0.08682,0.0713 -0.133325,0.15968 -0.04496,0.0884 -0.04651,0.17983 h 0.288355 q 0,-0.0527 0.02481,-0.10077 0.02635,-0.0496 0.07286,-0.0853 0.04651,-0.0357 0.113172,-0.0574 0.06821,-0.0217 0.153479,-0.0217 0.09147,0 0.164331,0.0233 0.07441,0.0233 0.125574,0.0651 0.05116,0.0434 0.07906,0.10387 0.02791,0.0605 0.02791,0.13642 v 0.13178 h -0.313159 q -0.175184,0 -0.31781,0.0341 -0.141077,0.0341 -0.241846,0.10232 -0.100769,0.0698 -0.15658,0.17364 -0.05426,0.10387 -0.05426,0.24184 0,0.10542 0.04031,0.19689 0.04186,0.0899 0.117822,0.15503 0.07441,0.0667 0.181384,0.10542 0.108521,0.0388 0.241846,0.0388 0.08217,0 0.155029,-0.0171 0.07286,-0.017 0.137976,-0.0465 0.06356,-0.0294 0.116272,-0.0682 0.05426,-0.0388 0.09767,-0.0822 0.0046,0.0527 0.01395,0.10231 0.01085,0.0481 0.02791,0.0806 z m -0.506946,-0.21859 q -0.08372,0 -0.147278,-0.0217 -0.06356,-0.0217 -0.10542,-0.0605 -0.04186,-0.0372 -0.06356,-0.0899 -0.02015,-0.0527 -0.02015,-0.11473 0,-0.0651 0.02326,-0.11627 0.0248,-0.0512 0.07131,-0.0884 0.06511,-0.0527 0.175183,-0.0775 0.111621,-0.0264 0.260449,-0.0264 h 0.266651 v 0.33951 q -0.02481,0.0496 -0.06821,0.0961 -0.04341,0.045 -0.102319,0.0806 -0.06046,0.0357 -0.133326,0.0574 -0.07286,0.0217 -0.156579,0.0217 z m 1.255737,-0.63407 v 0.0325 q 0,0.17984 0.04806,0.33642 0.04806,0.15503 0.134875,0.26975 0.08682,0.11472 0.20929,0.17983 0.124023,0.0651 0.275952,0.0651 0.155029,0 0.271301,-0.0527 0.116272,-0.0527 0.199988,-0.15503 l 0.0124,0.17673 h 0.263549 v -2.38125 h -0.286804 v 0.86971 q -0.08217,-0.0961 -0.195337,-0.14572 -0.111621,-0.0512 -0.261999,-0.0512 -0.153479,0 -0.277503,0.0636 -0.124023,0.0636 -0.21084,0.17673 -0.08837,0.11317 -0.136425,0.2713 -0.04651,0.15658 -0.04651,0.34417 z m 0.286804,0.0325 v -0.0325 q 0,-0.12247 0.02635,-0.23255 0.02636,-0.11162 0.08217,-0.19688 0.05426,-0.0837 0.139526,-0.13333 0.08682,-0.0496 0.207739,-0.0496 0.141077,0 0.235645,0.0667 0.09457,0.0651 0.150378,0.16743 v 0.77824 q -0.05581,0.11008 -0.150378,0.17519 -0.09457,0.0651 -0.238745,0.0651 -0.119373,0 -0.204639,-0.0481 -0.08527,-0.0496 -0.139526,-0.13332 -0.05581,-0.0837 -0.08217,-0.19379 -0.02635,-0.11007 -0.02635,-0.23255 z m 2.919202,1.38752 0.03256,-0.17829 q -0.09612,-0.003 -0.15968,-0.0527 -0.06201,-0.0496 -0.09922,-0.12712 -0.03876,-0.076 -0.05426,-0.17208 -0.0155,-0.0946 -0.0155,-0.19069 v -0.262 q -0.0016,-0.18448 -0.08682,-0.32401 -0.08527,-0.14108 -0.2651,-0.21239 0.179834,-0.0729 0.2651,-0.21239 0.08682,-0.14108 0.08682,-0.32711 v -0.26355 q 0,-0.0946 0.0093,-0.19069 0.0093,-0.0961 0.04341,-0.17363 0.03256,-0.076 0.09767,-0.12557 0.06666,-0.0496 0.178284,-0.0527 l -0.03256,-0.17829 q -0.15658,0.005 -0.266651,0.0682 -0.11007,0.062 -0.178283,0.16123 -0.07286,0.10387 -0.10697,0.23564 -0.03256,0.13022 -0.03256,0.2558 v 0.26355 q 0,0.22479 -0.10697,0.32556 -0.10542,0.0992 -0.324011,0.0992 v 0.22479 q 0.218591,0.002 0.324011,0.10232 0.10697,0.10077 0.10697,0.32401 v 0.262 q 0,0.12402 0.03566,0.2496 0.03566,0.12712 0.10542,0.22944 0.07286,0.10697 0.182935,0.17208 0.11007,0.0651 0.260449,0.0698 z"
|
|
59
|
+
id="path3" />
|
|
60
|
+
<path
|
|
61
|
+
style="font-family:'Roboto Mono';-inkscape-font-specification:'Roboto Mono';fill:#ff0000"
|
|
62
|
+
d="m 72.653427,135.56779 q 0,0.0899 0.05581,0.15348 0.05736,0.062 0.168982,0.062 0.11007,0 0.168982,-0.062 0.05891,-0.062 0.05891,-0.15348 0,-0.093 -0.05891,-0.15657 -0.05736,-0.0651 -0.168982,-0.0651 -0.113172,0 -0.168982,0.0651 -0.05581,0.0651 -0.05581,0.15657 z m 0.599963,0 q 0,0.0899 0.05581,0.15348 0.05736,0.062 0.168982,0.062 0.110071,0 0.168982,-0.062 0.05891,-0.062 0.05891,-0.15348 0,-0.093 -0.05891,-0.15657 -0.05736,-0.0651 -0.168982,-0.0651 -0.113171,0 -0.168982,0.0651 -0.05581,0.0651 -0.05581,0.15657 z m 0.57981,0 q 0,0.0899 0.05581,0.15348 0.05736,0.062 0.168982,0.062 0.11007,0 0.168981,-0.062 0.05891,-0.062 0.05891,-0.15348 0,-0.093 -0.05891,-0.15657 -0.05736,-0.0651 -0.168981,-0.0651 -0.113172,0 -0.168982,0.0651 -0.05581,0.0651 -0.05581,0.15657 z"
|
|
63
|
+
id="path4" />
|
|
64
|
+
<path
|
|
65
|
+
style="font-family:'Roboto Mono';-inkscape-font-specification:'Roboto Mono'"
|
|
66
|
+
d="m 74.648654,136.14295 0.03256,0.17829 q 0.151929,-0.003 0.261999,-0.0698 0.110071,-0.0667 0.182935,-0.17053 0.07131,-0.10387 0.10542,-0.23099 0.03411,-0.12558 0.03411,-0.2496 v -0.262 q 0,-0.10852 0.02481,-0.18758 0.02481,-0.0791 0.07596,-0.13178 0.05271,-0.0543 0.134876,-0.0791 0.08372,-0.0264 0.195337,-0.0279 v -0.22479 q -0.127124,0 -0.218591,-0.0326 -0.08992,-0.0341 -0.141077,-0.10697 -0.03566,-0.0512 -0.05426,-0.12092 -0.01705,-0.0713 -0.01705,-0.16433 v -0.26355 q 0,-0.13023 -0.03566,-0.26355 -0.03411,-0.13333 -0.113172,-0.2403 -0.06976,-0.0946 -0.178283,-0.15348 -0.106971,-0.0589 -0.257349,-0.0636 l -0.03101,0.17829 q 0.111621,0.003 0.176733,0.0527 0.06511,0.0496 0.09922,0.12557 0.03256,0.0775 0.04186,0.17363 0.01085,0.0961 0.01085,0.19069 v 0.26355 q 0,0.12092 0.03566,0.22479 0.03566,0.10232 0.110071,0.17983 0.03876,0.0419 0.08992,0.076 0.05271,0.0341 0.114721,0.0589 -0.06046,0.0248 -0.111621,0.0574 -0.04961,0.0326 -0.08992,0.0729 -0.07596,0.076 -0.113171,0.17984 -0.03566,0.10387 -0.03566,0.22634 v 0.262 q 0,0.0961 -0.01705,0.19069 -0.0155,0.0961 -0.05271,0.17208 -0.03876,0.0775 -0.102319,0.12712 -0.06356,0.0496 -0.15813,0.0527 z m 2.788977,-0.83405 q 0,0.0403 -0.0155,0.076 -0.0155,0.0357 -0.04496,0.0651 -0.04806,0.0481 -0.133325,0.076 -0.08527,0.0264 -0.199988,0.0264 -0.07286,0 -0.147278,-0.0155 -0.07441,-0.0155 -0.134875,-0.0527 -0.06201,-0.0372 -0.10387,-0.0977 -0.04031,-0.0605 -0.04651,-0.14883 h -0.286804 q 0,0.10697 0.04806,0.20619 0.04961,0.0992 0.142627,0.17363 0.09147,0.076 0.224793,0.12248 0.133325,0.045 0.303857,0.045 0.148828,0 0.274402,-0.0357 0.125574,-0.0357 0.215491,-0.10077 0.08992,-0.0651 0.139526,-0.15658 0.05116,-0.0915 0.05116,-0.20309 0,-0.10387 -0.04496,-0.18293 -0.04341,-0.0791 -0.127124,-0.13953 -0.08372,-0.0589 -0.206189,-0.10077 -0.122473,-0.0434 -0.277502,-0.076 -0.117823,-0.0233 -0.195337,-0.0481 -0.07596,-0.0248 -0.120923,-0.0558 -0.04651,-0.031 -0.06511,-0.0698 -0.0186,-0.0388 -0.0186,-0.0884 0,-0.0481 0.02325,-0.093 0.02325,-0.045 0.06976,-0.0791 0.04496,-0.0341 0.113171,-0.0543 0.06976,-0.0202 0.161231,-0.0202 0.08837,0 0.158129,0.0248 0.07131,0.0248 0.120923,0.0651 0.04961,0.0403 0.07752,0.093 0.02791,0.0512 0.02791,0.10542 h 0.286804 q 0,-0.11007 -0.04806,-0.20464 -0.04651,-0.0961 -0.133325,-0.16743 -0.08682,-0.0713 -0.21084,-0.11163 -0.124023,-0.0403 -0.279052,-0.0403 -0.144178,0 -0.265101,0.0387 -0.119372,0.0388 -0.206189,0.10542 -0.08682,0.0667 -0.134875,0.15658 -0.04806,0.0884 -0.04806,0.19069 0,0.10387 0.04651,0.18293 0.04651,0.0775 0.131775,0.13488 0.08371,0.0589 0.201538,0.10077 0.119372,0.0419 0.263549,0.0713 0.117823,0.0233 0.196888,0.0527 0.07906,0.0279 0.127124,0.062 0.04806,0.0341 0.06821,0.076 0.02015,0.0403 0.02015,0.0915 z m 0.710034,-0.40928 v 0.0341 q 0,0.18139 0.05271,0.33642 0.05271,0.15503 0.151929,0.26975 0.09767,0.11472 0.238745,0.17983 0.142627,0.0651 0.320911,0.0651 0.176733,0 0.31781,-0.0651 0.141076,-0.0651 0.240295,-0.17983 0.09767,-0.11472 0.150379,-0.26975 0.05271,-0.15503 0.05271,-0.33642 v -0.0341 q 0,-0.18139 -0.05271,-0.33642 -0.05271,-0.15657 -0.150379,-0.2713 -0.09922,-0.11472 -0.241846,-0.17983 -0.141076,-0.0667 -0.31936,-0.0667 -0.176733,0 -0.31781,0.0667 -0.141077,0.0651 -0.238745,0.17983 -0.09922,0.11473 -0.151929,0.2713 -0.05271,0.15503 -0.05271,0.33642 z m 0.286804,0.0341 v -0.0341 q 0,-0.12247 0.02946,-0.2341 0.02946,-0.11317 0.08992,-0.19843 0.05891,-0.0853 0.147278,-0.13488 0.08837,-0.0512 0.207739,-0.0512 0.119373,0 0.207739,0.0512 0.08992,0.0496 0.150379,0.13488 0.05891,0.0853 0.08837,0.19843 0.03101,0.11163 0.03101,0.2341 v 0.0341 q 0,0.12403 -0.02945,0.2372 -0.02946,0.11162 -0.08837,0.19689 -0.06046,0.0853 -0.150378,0.13487 -0.08837,0.0496 -0.206189,0.0496 -0.119373,0 -0.20929,-0.0496 -0.08992,-0.0496 -0.148828,-0.13487 -0.06046,-0.0853 -0.08992,-0.19689 -0.02946,-0.11317 -0.02946,-0.2372 z m 1.699122,0.82011 h 0.286804 v -1.20303 q 0.02946,-0.0543 0.06821,-0.0992 0.04031,-0.045 0.08682,-0.0791 0.05736,-0.0388 0.125573,-0.0605 0.06821,-0.0233 0.147278,-0.0233 0.09147,0 0.161231,0.0217 0.07131,0.0217 0.120922,0.0698 0.04806,0.0481 0.07286,0.12557 0.02481,0.0775 0.02481,0.18914 v 1.05885 h 0.286804 v -1.06505 q 0,-0.16743 -0.04186,-0.28836 -0.04031,-0.12247 -0.116272,-0.20153 -0.07596,-0.0791 -0.184485,-0.11628 -0.10697,-0.0372 -0.238745,-0.0372 -0.09767,0.002 -0.186035,0.0294 -0.08682,0.0264 -0.16123,0.076 -0.04961,0.0325 -0.09457,0.0775 -0.04341,0.0434 -0.08061,0.0961 l -0.02015,-0.24805 h -0.257349 z"
|
|
67
|
+
id="path5" />
|
|
68
|
+
</g>
|
|
69
|
+
</g>
|
|
70
|
+
</svg>
|
|
Binary file
|
|
@@ -169,7 +169,7 @@ dependencies = [
|
|
|
169
169
|
|
|
170
170
|
[[package]]
|
|
171
171
|
name = "headson"
|
|
172
|
-
version = "0.
|
|
172
|
+
version = "0.6.0"
|
|
173
173
|
dependencies = [
|
|
174
174
|
"anyhow",
|
|
175
175
|
"clap",
|
|
@@ -182,7 +182,7 @@ dependencies = [
|
|
|
182
182
|
|
|
183
183
|
[[package]]
|
|
184
184
|
name = "headson-python"
|
|
185
|
-
version = "0.
|
|
185
|
+
version = "0.6.0"
|
|
186
186
|
dependencies = [
|
|
187
187
|
"anyhow",
|
|
188
188
|
"headson",
|
|
@@ -2,7 +2,7 @@ use anyhow::{bail, Result};
|
|
|
2
2
|
use pyo3::exceptions::PyRuntimeError;
|
|
3
3
|
use pyo3::prelude::*;
|
|
4
4
|
use pyo3::types::PyModule;
|
|
5
|
-
use headson_core::{ArraySamplerStrategy, OutputTemplate, PriorityConfig, RenderConfig};
|
|
5
|
+
use headson_core::{ArraySamplerStrategy, ColorMode, OutputTemplate, PriorityConfig, RenderConfig};
|
|
6
6
|
|
|
7
7
|
fn to_template(s: &str) -> Result<OutputTemplate> {
|
|
8
8
|
match s.to_ascii_lowercase().as_str() {
|
|
@@ -22,7 +22,7 @@ fn render_config_with_sampler(
|
|
|
22
22
|
let newline = "\n".to_string();
|
|
23
23
|
let indent_unit = " ".to_string();
|
|
24
24
|
let prefer_tail_arrays = matches!(sampler, ArraySamplerStrategy::Tail);
|
|
25
|
-
Ok(RenderConfig { template: t, indent_unit, space, newline, prefer_tail_arrays })
|
|
25
|
+
Ok(RenderConfig { template: t, indent_unit, space, newline, prefer_tail_arrays, color_mode: ColorMode::Auto, color_enabled: false })
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
fn parse_skew(skew: &str) -> Result<ArraySamplerStrategy> {
|
|
@@ -21,7 +21,6 @@ struct SampleAccumulator<'a> {
|
|
|
21
21
|
indices: &'a mut Vec<usize>,
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
#[inline]
|
|
25
24
|
fn mix64(mut x: u64) -> u64 {
|
|
26
25
|
x ^= x >> 30;
|
|
27
26
|
x = x.wrapping_mul(0xbf58_476d_1ce4_e5b9);
|
|
@@ -30,7 +29,6 @@ fn mix64(mut x: u64) -> u64 {
|
|
|
30
29
|
x ^ (x >> 31)
|
|
31
30
|
}
|
|
32
31
|
|
|
33
|
-
#[inline]
|
|
34
32
|
fn accept_index(i: u64) -> bool {
|
|
35
33
|
let h = mix64(i ^ RANDOM_ACCEPT_SEED);
|
|
36
34
|
((h >> 32) as u32) < RANDOM_ACCEPT_THRESHOLD
|
|
@@ -25,7 +25,8 @@ pub use order::{
|
|
|
25
25
|
NodeId, NodeKind, PriorityConfig, PriorityOrder, RankedNode, build_order,
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
pub use serialization::
|
|
28
|
+
pub use serialization::color::resolve_color_enabled;
|
|
29
|
+
pub use serialization::types::{ColorMode, OutputTemplate, RenderConfig};
|
|
29
30
|
|
|
30
31
|
pub fn headson(
|
|
31
32
|
input: Vec<u8>,
|
|
@@ -76,7 +77,11 @@ fn find_largest_render_under_budget(
|
|
|
76
77
|
let mut inclusion_flags: Vec<u32> = vec![0; total];
|
|
77
78
|
// Each render attempt bumps this non-zero identifier to create a fresh inclusion set.
|
|
78
79
|
let mut render_set_id: u32 = 1;
|
|
79
|
-
|
|
80
|
+
// Measure length without color so ANSI escapes do not count toward the
|
|
81
|
+
// character budget. Then render once more with the requested color setting.
|
|
82
|
+
let mut best_k: Option<usize> = None;
|
|
83
|
+
let mut measure_cfg = config.clone();
|
|
84
|
+
measure_cfg.color_enabled = false;
|
|
80
85
|
|
|
81
86
|
let _ = crate::utils::search::binary_search_max(lo, hi, |mid| {
|
|
82
87
|
let s = crate::serialization::render_top_k(
|
|
@@ -84,19 +89,26 @@ fn find_largest_render_under_budget(
|
|
|
84
89
|
mid,
|
|
85
90
|
&mut inclusion_flags,
|
|
86
91
|
render_set_id,
|
|
87
|
-
|
|
92
|
+
&measure_cfg,
|
|
88
93
|
);
|
|
89
94
|
render_set_id = render_set_id.wrapping_add(1).max(1);
|
|
90
95
|
if s.len() <= char_budget {
|
|
91
|
-
|
|
96
|
+
best_k = Some(mid);
|
|
92
97
|
true
|
|
93
98
|
} else {
|
|
94
99
|
false
|
|
95
100
|
}
|
|
96
101
|
});
|
|
97
102
|
|
|
98
|
-
if let Some(
|
|
99
|
-
|
|
103
|
+
if let Some(k) = best_k {
|
|
104
|
+
// Final render with original color settings
|
|
105
|
+
crate::serialization::render_top_k(
|
|
106
|
+
order_build,
|
|
107
|
+
k,
|
|
108
|
+
&mut inclusion_flags,
|
|
109
|
+
render_set_id,
|
|
110
|
+
config,
|
|
111
|
+
)
|
|
100
112
|
} else {
|
|
101
113
|
// Fallback: always render a single node (k=1) to produce the
|
|
102
114
|
// shortest possible preview, even if it exceeds the byte budget.
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
use std::fs::File;
|
|
2
|
+
use std::io::IsTerminal as _;
|
|
2
3
|
use std::io::{self, Read};
|
|
3
4
|
use std::path::{Path, PathBuf};
|
|
4
5
|
|
|
5
6
|
use anyhow::{Context, Result};
|
|
6
|
-
use clap::{Parser, ValueEnum};
|
|
7
|
+
use clap::{ArgAction, Parser, ValueEnum};
|
|
7
8
|
use content_inspector::{ContentType, inspect};
|
|
8
9
|
|
|
9
10
|
type InputEntry = (String, Vec<u8>);
|
|
@@ -65,6 +66,20 @@ struct Cli {
|
|
|
65
66
|
help = "Prefer the beginning of arrays when truncating (keep first N)."
|
|
66
67
|
)]
|
|
67
68
|
head: bool,
|
|
69
|
+
#[arg(
|
|
70
|
+
long = "color",
|
|
71
|
+
action = ArgAction::SetTrue,
|
|
72
|
+
conflicts_with = "no_color",
|
|
73
|
+
help = "Force enable ANSI colors in output"
|
|
74
|
+
)]
|
|
75
|
+
color: bool,
|
|
76
|
+
#[arg(
|
|
77
|
+
long = "no-color",
|
|
78
|
+
action = ArgAction::SetTrue,
|
|
79
|
+
conflicts_with = "color",
|
|
80
|
+
help = "Disable ANSI colors in output"
|
|
81
|
+
)]
|
|
82
|
+
no_color: bool,
|
|
68
83
|
#[arg(
|
|
69
84
|
value_name = "INPUT",
|
|
70
85
|
value_hint = clap::ValueHint::FilePath,
|
|
@@ -85,6 +100,9 @@ fn main() -> Result<()> {
|
|
|
85
100
|
let cli = Cli::parse();
|
|
86
101
|
|
|
87
102
|
let render_cfg = get_render_config_from(&cli);
|
|
103
|
+
// Resolve color auto-detection now (stdout is the surface for user output).
|
|
104
|
+
let _color_enabled =
|
|
105
|
+
render_cfg.color_mode.effective(io::stdout().is_terminal());
|
|
88
106
|
let (output, ignore_notices) = if cli.inputs.is_empty() {
|
|
89
107
|
(run_from_stdin(&cli, &render_cfg)?, Vec::new())
|
|
90
108
|
} else {
|
|
@@ -222,11 +240,24 @@ fn ingest_paths(paths: &[PathBuf]) -> Result<(InputEntries, IgnoreNotices)> {
|
|
|
222
240
|
}
|
|
223
241
|
|
|
224
242
|
fn get_render_config_from(cli: &Cli) -> headson::RenderConfig {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
243
|
+
fn to_output_template(t: Template) -> headson::OutputTemplate {
|
|
244
|
+
match t {
|
|
245
|
+
Template::Json => headson::OutputTemplate::Json,
|
|
246
|
+
Template::Pseudo => headson::OutputTemplate::Pseudo,
|
|
247
|
+
Template::Js => headson::OutputTemplate::Js,
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
fn color_mode_from_flags(cli: &Cli) -> headson::ColorMode {
|
|
251
|
+
if cli.color {
|
|
252
|
+
headson::ColorMode::On
|
|
253
|
+
} else if cli.no_color {
|
|
254
|
+
headson::ColorMode::Off
|
|
255
|
+
} else {
|
|
256
|
+
headson::ColorMode::Auto
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
let template = to_output_template(cli.template);
|
|
230
261
|
let space = if cli.compact || cli.no_space { "" } else { " " }.to_string();
|
|
231
262
|
let newline = if cli.compact || cli.no_newline {
|
|
232
263
|
""
|
|
@@ -239,6 +270,8 @@ fn get_render_config_from(cli: &Cli) -> headson::RenderConfig {
|
|
|
239
270
|
} else {
|
|
240
271
|
cli.indent.clone()
|
|
241
272
|
};
|
|
273
|
+
let color_mode = color_mode_from_flags(cli);
|
|
274
|
+
let color_enabled = headson::resolve_color_enabled(color_mode);
|
|
242
275
|
|
|
243
276
|
headson::RenderConfig {
|
|
244
277
|
template,
|
|
@@ -246,6 +279,8 @@ fn get_render_config_from(cli: &Cli) -> headson::RenderConfig {
|
|
|
246
279
|
space,
|
|
247
280
|
newline,
|
|
248
281
|
prefer_tail_arrays: cli.tail,
|
|
282
|
+
color_mode,
|
|
283
|
+
color_enabled,
|
|
249
284
|
}
|
|
250
285
|
}
|
|
251
286
|
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
use std::io::IsTerminal as _;
|
|
2
|
+
|
|
3
|
+
use crate::serialization::types::ColorMode;
|
|
4
|
+
|
|
5
|
+
// ANSI SGR fragments
|
|
6
|
+
const RESET: &str = "\u{001b}[0m";
|
|
7
|
+
const BOLD_BLUE: &str = "\u{001b}[1;34m";
|
|
8
|
+
const GREEN: &str = "\u{001b}[32m";
|
|
9
|
+
const CYAN: &str = "\u{001b}[36m";
|
|
10
|
+
const BRIGHT_GRAY: &str = "\u{001b}[37m";
|
|
11
|
+
const DARK_GRAY: &str = "\u{001b}[90m";
|
|
12
|
+
|
|
13
|
+
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
|
14
|
+
pub enum ColorRole {
|
|
15
|
+
Key,
|
|
16
|
+
String,
|
|
17
|
+
Number,
|
|
18
|
+
Bool,
|
|
19
|
+
Null,
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
pub fn wrap_role<S: Into<String>>(
|
|
23
|
+
s: S,
|
|
24
|
+
role: ColorRole,
|
|
25
|
+
enabled: bool,
|
|
26
|
+
) -> String {
|
|
27
|
+
let s: String = s.into();
|
|
28
|
+
if !enabled {
|
|
29
|
+
return s;
|
|
30
|
+
}
|
|
31
|
+
let prefix = match role {
|
|
32
|
+
ColorRole::Key => BOLD_BLUE,
|
|
33
|
+
ColorRole::String => GREEN,
|
|
34
|
+
ColorRole::Number => CYAN,
|
|
35
|
+
ColorRole::Bool | ColorRole::Null => BRIGHT_GRAY,
|
|
36
|
+
};
|
|
37
|
+
let mut out = String::with_capacity(8 + 8 + s.len());
|
|
38
|
+
out.push_str(prefix);
|
|
39
|
+
out.push_str(&s);
|
|
40
|
+
out.push_str(RESET);
|
|
41
|
+
out
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
pub fn omission_marker(enabled: bool) -> &'static str {
|
|
45
|
+
if enabled {
|
|
46
|
+
"\u{001b}[90m…\u{001b}[0m"
|
|
47
|
+
} else {
|
|
48
|
+
"…"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
pub fn color_comment<S: Into<String>>(body: S, enabled: bool) -> String {
|
|
53
|
+
if !enabled {
|
|
54
|
+
return body.into();
|
|
55
|
+
}
|
|
56
|
+
let b = body.into();
|
|
57
|
+
let mut out = String::with_capacity(b.len() + 8 + 4);
|
|
58
|
+
out.push_str(DARK_GRAY);
|
|
59
|
+
out.push_str(&b);
|
|
60
|
+
out.push_str(RESET);
|
|
61
|
+
out
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
fn env_bool(var: &str) -> Option<bool> {
|
|
65
|
+
std::env::var_os(var).map(|v| {
|
|
66
|
+
let s = v.to_string_lossy();
|
|
67
|
+
!(s == "0" || s.is_empty())
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
struct ColorEnv {
|
|
72
|
+
force: bool, // CLICOLOR_FORCE=1
|
|
73
|
+
force_color: bool, // FORCE_COLOR=1
|
|
74
|
+
no_color: bool, // NO_COLOR present
|
|
75
|
+
dumb: bool, // TERM=dumb
|
|
76
|
+
clicolor: Option<bool>, // CLICOLOR=0/1
|
|
77
|
+
is_tty: bool,
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
fn read_color_env() -> ColorEnv {
|
|
81
|
+
let term_dumb = std::env::var_os("TERM")
|
|
82
|
+
.map(|t| t.to_string_lossy() == "dumb")
|
|
83
|
+
.unwrap_or(false);
|
|
84
|
+
ColorEnv {
|
|
85
|
+
force: matches!(env_bool("CLICOLOR_FORCE"), Some(true)),
|
|
86
|
+
force_color: matches!(env_bool("FORCE_COLOR"), Some(true)),
|
|
87
|
+
no_color: std::env::var_os("NO_COLOR").is_some(),
|
|
88
|
+
dumb: term_dumb,
|
|
89
|
+
clicolor: env_bool("CLICOLOR"),
|
|
90
|
+
is_tty: std::io::stdout().is_terminal(),
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
fn auto_color_enabled(env: &ColorEnv) -> bool {
|
|
95
|
+
if env.force || env.force_color {
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
if env.no_color || env.dumb {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
if let Some(b) = env.clicolor {
|
|
102
|
+
return b && env.is_tty;
|
|
103
|
+
}
|
|
104
|
+
env.is_tty
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
pub fn resolve_color_enabled(mode: ColorMode) -> bool {
|
|
108
|
+
match mode {
|
|
109
|
+
ColorMode::On => true,
|
|
110
|
+
ColorMode::Off => false,
|
|
111
|
+
ColorMode::Auto => auto_color_enabled(&read_color_env()),
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -17,7 +17,7 @@ impl<'a> RenderScope<'a> {
|
|
|
17
17
|
out.push_str("// ");
|
|
18
18
|
out.push_str(raw_key);
|
|
19
19
|
out.push_str(nl);
|
|
20
|
-
let rendered = self.
|
|
20
|
+
let rendered = self.render_node_to_string(child_pq_id, depth, false);
|
|
21
21
|
out.push_str(&rendered);
|
|
22
22
|
out.push(';');
|
|
23
23
|
out.push_str(nl);
|
|
@@ -58,7 +58,7 @@ impl<'a> RenderScope<'a> {
|
|
|
58
58
|
out.push_str(raw_key);
|
|
59
59
|
out.push_str(" <==");
|
|
60
60
|
out.push_str(nl);
|
|
61
|
-
let rendered = self.
|
|
61
|
+
let rendered = self.render_node_to_string(child_pq_id, depth, false);
|
|
62
62
|
out.push_str(&rendered);
|
|
63
63
|
}
|
|
64
64
|
|