├── .gitignore ├── .pre-commit-config.yaml ├── CHANGELOG.md ├── LICENSE ├── MANIFEST.in ├── README.md ├── assets ├── bar.png ├── bar_h.png └── pie.png ├── reqs ├── app.in ├── app.txt ├── dev.in └── dev.txt ├── sandbox ├── barchart.py ├── eng.py ├── pie.py └── rich_integ.py ├── setup.cfg ├── setup.py ├── src └── termcharts │ ├── __init__.py │ ├── bar_chart.py │ ├── colors.py │ ├── engine.py │ ├── formula.py │ ├── main.py │ └── pie.py └── tests ├── test_colors.py └── test_engine.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | ci: 2 | autoupdate_schedule: monthly 3 | repos: 4 | - repo: https://github.com/asottile/pyupgrade 5 | rev: v2.31.1 6 | hooks: 7 | - id: pyupgrade 8 | args: ["--py36-plus"] 9 | - repo: https://github.com/asottile/reorder_python_imports 10 | rev: v3.0.1 11 | hooks: 12 | - id: reorder-python-imports 13 | name: Reorder Python imports 14 | - repo: https://github.com/psf/black 15 | rev: 22.3.0 16 | hooks: 17 | - id: black 18 | args: [--experimental-string-processing] 19 | - repo: https://github.com/pre-commit/pre-commit-hooks 20 | rev: v4.1.0 21 | hooks: 22 | - id: fix-byte-order-marker 23 | - id: trailing-whitespace 24 | - id: end-of-file-fixer 25 | - id: check-yaml 26 | - id: debug-statements 27 | - id: check-added-large-files 28 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## v1.1.0 (2022-09-08) 2 | 3 | ### Feat 4 | 5 | - vertical barcharts 6 | 7 | ### Fix 8 | 9 | - add_text x coord anolmaly 10 | 11 | ## v1.0.4 (2022-09-07) 12 | 13 | ## v1.0.3 (2022-09-07) 14 | 15 | - Tests 16 | 17 | ### Refactor 18 | 19 | - Color class 20 | 21 | ## v1.0.1 (2022-09-06) 22 | 23 | ## v1.0.0 (2022-09-06) 24 | 25 | ### Feat 26 | 27 | - bar chart 28 | - engine screen utils 29 | - mode=h or v in add_text 30 | 31 | ### Fix 32 | 33 | - rich integration 34 | - engine render 35 | - screen mix between charts 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | recursive-include src/termcharts * 2 | recursive-include reqs * 3 | recursive-include assets * 4 | recursive-exclude __pycache__ * 5 | recursive-exclude sandbox * -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # termcharts 2 | 3 | Terminal charts with rich compatibility in mind 4 | 5 | 6 | ![](https://github.com/Abdur-RahmaanJ/termcharts/raw/stable/assets/pie.png) 7 | 8 | # bar 9 | 10 | ![](https://github.com/Abdur-RahmaanJ/termcharts/raw/stable/assets/bar.png) 11 | 12 | ![](https://github.com/Abdur-RahmaanJ/termcharts/raw/stable/assets/bar_h.png) 13 | 14 | 15 | ```python 16 | import termcharts 17 | 18 | 19 | chart1 = termcharts.bar({'roll': 24, 'bread':10, 'rice':30, 'pasta':50}, title='brunches') 20 | chart2 = termcharts.bar({'roll': 24, 'bread':10, 'rice':30, 'pasta':50}, title='brunches', mode='v') # vertical 21 | chart3 = termcharts.bar([10, 20, 30, 40], title='brunches') # from list 22 | print(chart1) 23 | print(chart2) 24 | print(chart3) 25 | ``` 26 | 27 | # Pie 28 | 29 | ```python 30 | import termcharts 31 | 32 | 33 | chart = termcharts.pie({'pencil':10, 'eraser': 20, 'ruler': 30}, title='stationary') 34 | print(chart) 35 | ``` 36 | 37 | # Doughnut 38 | 39 | ```python 40 | import termcharts 41 | 42 | 43 | chart = termcharts.doughnut({'a':10, 'b': 20, 'c': 30}, title='aphabet dist') 44 | print(chart) 45 | ``` 46 | 47 | 48 | # Rich compatibility 49 | 50 | 51 | ```python 52 | from termcharts import pie 53 | from termcharts import doughnut 54 | from termcharts import bar 55 | 56 | from rich.console import Console 57 | from rich.columns import Columns 58 | from rich.panel import Panel 59 | 60 | console = Console() 61 | 62 | charts = [ 63 | doughnut({'a':10, 'b': 20, 'c': 30, 'd': 20}, title='aphabet dist', rich=True), 64 | pie({'wefwefqwddwqdqwda':10, 'b': 20, 'c': 30, 'd': 20}, rich=True), 65 | bar({'roll': 24, 'bss':10, 'wes':30, 'ewfwef':50}, title='Brunches', rich=True) 66 | ] 67 | user_renderables = [Panel(x, expand=True) for x in charts] 68 | console.print(Columns(user_renderables)) 69 | ``` 70 | 71 | 72 | # Testing 73 | 74 | All testing is currently handled by the [pytest](https://docs.pytest.org/en/7.1.x/) module and are incomplete at the momment. 75 | 76 | Installation: 77 | ``` 78 | pip install -U pytest 79 | ``` 80 | 81 | Run all the testcases in a file: 82 | ``` 83 | pytest tests/.py 84 | ``` 85 | 86 | Run one testcase in a file: 87 | ``` 88 | pytest tests/.py:: 89 | ``` 90 | 91 | Exclude one testcase in a file: 92 | ``` 93 | pytest tests/.py -k 'not ' 94 | ``` 95 | -------------------------------------------------------------------------------- /assets/bar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdur-rahmaanJ/termcharts/f0dc7e01a61f5492c07d2840cf493606aeff9474/assets/bar.png -------------------------------------------------------------------------------- /assets/bar_h.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdur-rahmaanJ/termcharts/f0dc7e01a61f5492c07d2840cf493606aeff9474/assets/bar_h.png -------------------------------------------------------------------------------- /assets/pie.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdur-rahmaanJ/termcharts/f0dc7e01a61f5492c07d2840cf493606aeff9474/assets/pie.png -------------------------------------------------------------------------------- /reqs/app.in: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdur-rahmaanJ/termcharts/f0dc7e01a61f5492c07d2840cf493606aeff9474/reqs/app.in -------------------------------------------------------------------------------- /reqs/app.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdur-rahmaanJ/termcharts/f0dc7e01a61f5492c07d2840cf493606aeff9474/reqs/app.txt -------------------------------------------------------------------------------- /reqs/dev.in: -------------------------------------------------------------------------------- 1 | pip-tools 2 | pytest 3 | twine -------------------------------------------------------------------------------- /reqs/dev.txt: -------------------------------------------------------------------------------- 1 | # 2 | # This file is autogenerated by pip-compile with python 3.10 3 | # To update, run: 4 | # 5 | # pip-compile --output-file=reqs/dev.txt reqs/dev.in 6 | # 7 | attrs==22.1.0 8 | # via pytest 9 | bleach==5.0.1 10 | # via readme-renderer 11 | build==0.8.0 12 | # via pip-tools 13 | certifi==2022.6.15 14 | # via requests 15 | cffi==1.15.1 16 | # via cryptography 17 | charset-normalizer==2.1.1 18 | # via requests 19 | click==8.1.3 20 | # via pip-tools 21 | commonmark==0.9.1 22 | # via rich 23 | cryptography==37.0.4 24 | # via secretstorage 25 | docutils==0.19 26 | # via readme-renderer 27 | idna==3.3 28 | # via requests 29 | importlib-metadata==4.12.0 30 | # via twine 31 | iniconfig==1.1.1 32 | # via pytest 33 | jaraco-classes==3.2.2 34 | # via keyring 35 | jeepney==0.8.0 36 | # via 37 | # keyring 38 | # secretstorage 39 | keyring==23.9.0 40 | # via twine 41 | more-itertools==8.14.0 42 | # via jaraco-classes 43 | packaging==21.3 44 | # via 45 | # build 46 | # pytest 47 | pep517==0.13.0 48 | # via build 49 | pip-tools==6.8.0 50 | # via -r reqs/dev.in 51 | pkginfo==1.8.3 52 | # via twine 53 | pluggy==1.0.0 54 | # via pytest 55 | py==1.11.0 56 | # via pytest 57 | pycparser==2.21 58 | # via cffi 59 | pygments==2.13.0 60 | # via 61 | # readme-renderer 62 | # rich 63 | pyparsing==3.0.9 64 | # via packaging 65 | pytest==7.1.3 66 | # via -r reqs/dev.in 67 | readme-renderer==37.0 68 | # via twine 69 | requests==2.28.1 70 | # via 71 | # requests-toolbelt 72 | # twine 73 | requests-toolbelt==0.9.1 74 | # via twine 75 | rfc3986==2.0.0 76 | # via twine 77 | rich==12.5.1 78 | # via twine 79 | secretstorage==3.3.3 80 | # via keyring 81 | six==1.16.0 82 | # via bleach 83 | tomli==2.0.1 84 | # via 85 | # build 86 | # pep517 87 | # pytest 88 | twine==4.0.1 89 | # via -r reqs/dev.in 90 | urllib3==1.26.12 91 | # via 92 | # requests 93 | # twine 94 | webencodings==0.5.1 95 | # via bleach 96 | wheel==0.37.1 97 | # via pip-tools 98 | zipp==3.8.1 99 | # via importlib-metadata 100 | 101 | # The following packages are considered to be unsafe in a requirements file: 102 | # pip 103 | # setuptools 104 | -------------------------------------------------------------------------------- /sandbox/barchart.py: -------------------------------------------------------------------------------- 1 | import termcharts 2 | 3 | chart = termcharts.bar( 4 | {"roll": 24, "bss": 10, "wes": 30, "ewfwef": 50}, title="Brunches" 5 | ) 6 | print(chart) 7 | chart = termcharts.bar( 8 | { 9 | "roll": 100, 10 | "bss": 40, 11 | "wes": 30, 12 | "ewfwef": 50, 13 | "ewsax": 50, 14 | "ewasx": 50, 15 | "ewasxaOOOf": 50, 16 | }, 17 | title="Brunches", 18 | mode="v", 19 | ) 20 | print(chart) 21 | chart = termcharts.bar( 22 | [10, 20, 30, 40], 23 | title="Brunches", 24 | mode="v", 25 | ) 26 | print(chart) 27 | chart = termcharts.bar( 28 | [10, 20, 30, 40], 29 | title="Brunches", 30 | mode="h", 31 | ) 32 | print(chart) 33 | -------------------------------------------------------------------------------- /sandbox/eng.py: -------------------------------------------------------------------------------- 1 | from termcharts.engine import add_char 2 | from termcharts.engine import render 3 | 4 | screen = {"0-0": "x", "10-20": "@"} 5 | 6 | 7 | print(render(screen, 11, 21)) 8 | 9 | 10 | add_char(screen, [0, 3], "/") 11 | 12 | 13 | print(render(screen, 11, 21)) 14 | -------------------------------------------------------------------------------- /sandbox/pie.py: -------------------------------------------------------------------------------- 1 | from termcharts import doughnut 2 | from termcharts import pie 3 | 4 | print(doughnut({"1": 10, "2": 20, "3": 30}, title="aphabet dist"), flush=True) 5 | print(pie({"aaa": 10, "bbb": 20, "ccc": 30}), flush=True) 6 | -------------------------------------------------------------------------------- /sandbox/rich_integ.py: -------------------------------------------------------------------------------- 1 | from rich.columns import Columns 2 | from rich.console import Console 3 | from rich.panel import Panel 4 | from termcharts import bar 5 | from termcharts import doughnut 6 | from termcharts import pie 7 | 8 | console = Console() 9 | 10 | 11 | charts = [ 12 | doughnut({"a": 10, "b": 20, "c": 30, "d": 20}, title="aphabet dist", rich=True), 13 | pie({"wefwefqwddwqdqwda": 10, "b": 20, "c": 30, "d": 20}, rich=True), 14 | bar({"roll": 24, "bss": 10, "wes": 30, "ewfwef": 50}, title="Brunches", rich=True), 15 | bar( 16 | { 17 | "roll": 100, 18 | "bss": 40, 19 | "wes": 30, 20 | "ewfwef": 50, 21 | "ewsax": 50, 22 | "ewasx": 50, 23 | "ewasxaOOOf": 50, 24 | }, 25 | title="Brunches", 26 | rich=True, 27 | mode="v", 28 | ), 29 | bar([10, 20, 30, 40], title="Brunches", rich=True), 30 | bar( 31 | [10, 20, 30, 40], 32 | title="Brunches", 33 | rich=True, 34 | mode="v", 35 | ), 36 | ] 37 | user_renderables = [Panel(x, expand=True) for x in charts] 38 | # print(user_renderables) 39 | console.print(Columns(user_renderables)) 40 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | description-file = README.md 3 | 4 | [options] 5 | packages = find: 6 | package_dir = = src 7 | include_package_data = True 8 | python_requires = >= 3.7 9 | 10 | [options.packages.find] 11 | where = src -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | """A setuptools based setup module. 2 | See: 3 | https://packaging.python.org/guides/distributing-packages-using-setuptools/ 4 | https://github.com/pypa/sampleproject 5 | python setup.py publish to publish 6 | """ 7 | import glob 8 | import os 9 | import sys 10 | 11 | import setuptools 12 | from setuptools import find_packages 13 | from setuptools import setup 14 | 15 | # Always prefer setuptools over distutils 16 | 17 | # from setuptools import find_packages 18 | 19 | 20 | here = os.path.abspath(os.path.dirname(__file__)) 21 | 22 | 23 | if sys.argv[-1] == "publish": # requests 24 | os.system("python setup.py sdist") # bdist_wheel 25 | os.system("twine upload dist/* --skip-existing") 26 | sys.exit() 27 | 28 | 29 | # Get the long description from the README file 30 | with open(os.path.join(here, "README.md"), encoding="utf-8") as f: 31 | long_description = f.read() 32 | setup( 33 | name="termcharts", # Required 34 | version="1.1.2", # Required 35 | description="Download stats for Python packages", # Optional 36 | long_description=long_description, # Optional 37 | long_description_content_type="text/markdown", # Optional (see note above) 38 | # url="https://github.com/Abdur-RahmaanJ/greenBerry", # Optional 39 | # author="Abdur-Rahmaan Janhangeer & contributors", # Optional 40 | author_email="arj.python@gmail.com", # Optional 41 | # Classifiers help users find your project by categorizing it. 42 | # 43 | # For a list of valid classifiers, see https://pypi.org/classifiers/ 44 | classifiers=[ # Optional 45 | # How mature is this project? Common values are 46 | # 3 - Alpha 47 | # 4 - Beta 48 | # 5 - Production/Stable 49 | "Development Status :: 4 - Beta", 50 | # Indicate who your project is intended for 51 | "Intended Audience :: Developers", 52 | # 'Topic :: Weather', 53 | # Pick your license as you wish 54 | "License :: OSI Approved :: MIT License", 55 | # Specify the Python versions you support here. In particular, ensure 56 | # that you indicate whether you support Python 2, Python 3 or both. 57 | # These classifiers are *not* checked by 'pip install'. See instead 58 | # 'python_requires' below. 59 | "Programming Language :: Python :: 3.7", 60 | "Programming Language :: Python :: 3.8", 61 | "Programming Language :: Python :: 3.9", 62 | "Programming Language :: Python :: 3.10", 63 | "Programming Language :: Python :: 3.11", 64 | ], 65 | keywords="chart terminal plot cli command-line", # Optional 66 | # You can just specify package directories manually here if your project is 67 | # simple. Or you can use find_packages(). 68 | # 69 | # Alternatively, if you just want to distribute a single Python file, use 70 | # the `py_modules` argument instead as follows, which will expect a file 71 | # called `my_module.py` to exist: 72 | # 73 | # py_modules=["my_module"], 74 | # 75 | # packages=find_packages(exclude=['contrib', 'docs', 'tests']), # Required 76 | python_requires=">=3.7", 77 | include_package_data=True, 78 | # install_requires=open(os.path.join(here, "reqs", "app.txt"), encoding="utf-8") 79 | # .read() 80 | # .split("\n"), # Optional 81 | install_requires=open(os.path.join(here, "reqs", "app.txt"), encoding="utf-8") 82 | .read() 83 | .split("\n"), 84 | extras_require={ 85 | "dev": open(os.path.join(here, "reqs", "dev.txt"), encoding="utf-8") 86 | .read() 87 | .split("\n"), 88 | "rich": ["rich"], 89 | }, 90 | project_urls={ # Optional 91 | "Bug Reports": "https://github.com/Abdur-RahmaanJ/termcharts/issues", 92 | "Source": "https://github.com/Abdur-RahmaanJ/termcharts/", 93 | }, 94 | packages=find_packages(), 95 | # entry_points={"console_scripts": ["download-stats=download_stats.main:main"]}, 96 | ) 97 | # Footer 98 | -------------------------------------------------------------------------------- /src/termcharts/__init__.py: -------------------------------------------------------------------------------- 1 | from termcharts.bar_chart import bar 2 | from termcharts.pie import doughnut_chart as doughnut 3 | from termcharts.pie import pie_chart as pie 4 | -------------------------------------------------------------------------------- /src/termcharts/bar_chart.py: -------------------------------------------------------------------------------- 1 | import math 2 | from itertools import cycle 3 | from typing import Union 4 | 5 | from termcharts.colors import Color 6 | from termcharts.colors import default_colors 7 | from termcharts.engine import add_char 8 | from termcharts.engine import add_text 9 | from termcharts.engine import merge_screens 10 | from termcharts.engine import render 11 | from termcharts.engine import screen 12 | from termcharts.formula import constrain 13 | 14 | 15 | def bar_chart_raw_h(data: Union[dict, list], title, return_rich=False): 16 | top_pad = 3 17 | right_pad = 2 18 | values_x = 500 19 | values_y = 100 20 | 21 | term_size_x = 40 + 1 22 | term_size_y = top_pad + len(data) + (len(data) - 1) + 2 23 | 24 | screen_axis = screen() 25 | screen_chart = screen() 26 | 27 | # Add left bar 28 | for i in range(term_size_x): 29 | add_char(screen_axis, [0, i + top_pad], Color.white + "│" + Color.RESET) 30 | 31 | if isinstance(data, dict): 32 | max_item = max(data[e] for e in data) 33 | max_d_len = max(len(e) for e in data) 34 | elif isinstance(data, list): 35 | max_item = max(data) 36 | 37 | # Draw bars 38 | space_pad = 1 39 | for i, item in enumerate(data): 40 | col = next(default_colors) 41 | if isinstance(data, dict): 42 | width = term_size_x - (right_pad + max_d_len + 5) 43 | value = data[item] 44 | elif isinstance(data, list): 45 | width = term_size_x - (right_pad + len(str(max_item)) + 5) 46 | value = item 47 | 48 | number = int(constrain(value, 0, max_item, 0, width)) 49 | bar = f"{col}" + ("█" * number) 50 | 51 | if not return_rich: 52 | bar = bar + f" {value}" + Color.RESET 53 | else: 54 | bar = bar + f" {value}" 55 | add_text(screen_chart, bar, 1, top_pad + i + space_pad) 56 | space_pad += 1 57 | 58 | # Add title 59 | 60 | add_text(screen_chart, Color.white + title, 0, 1) 61 | 62 | main_screen = merge_screens([screen_chart, screen_axis]) 63 | 64 | source = render(main_screen, term_size_x, term_size_y) 65 | 66 | if return_rich: 67 | try: 68 | from rich.text import Text 69 | except ImportError: 70 | raise Exception("Text not found from rich.text") 71 | return Text.from_ansi(source) 72 | else: 73 | return source 74 | 75 | 76 | def bar_chart_raw_v(data, title, return_rich=False): 77 | top_pad = 4 78 | right_pad = 2 79 | values_x = 500 80 | values_y = 100 81 | bottom_pad = 1 82 | 83 | if isinstance(data, dict): 84 | max_item = max(data[e] for e in data) 85 | max_d_len = max(len(e) for e in data) 86 | elif isinstance(data, list): 87 | max_item = max(data) 88 | 89 | term_size_y = 15 90 | chart_size_x = len(data) + (len(data) - 1) + 2 91 | if title is None: 92 | term_size_x = chart_size_x 93 | elif title: 94 | if len(title) > chart_size_x: 95 | term_size_x = len(title) + 2 96 | else: 97 | term_size_x = chart_size_x + 5 98 | 99 | screen_axis = screen() 100 | screen_chart = screen() 101 | 102 | # Draw bars 103 | space_pad = 1 104 | 105 | for i, item in enumerate(data): 106 | 107 | col = next(default_colors) 108 | height = term_size_y - (top_pad + bottom_pad) 109 | if isinstance(data, dict): 110 | value = data[item] 111 | elif isinstance(data, list): 112 | value = item 113 | 114 | number = int(constrain(value, 0, max_item, 0, height)) 115 | 116 | if not return_rich: 117 | bar = [f"{col}█{Color.RESET}" for i in range(number + 1)] 118 | else: 119 | bar = [f"{col}█" for i in range(number + 1)] 120 | txt_start_y = term_size_y - len(bar) - bottom_pad 121 | add_text(screen_chart, bar, i + space_pad, txt_start_y, mode="v") 122 | space_pad += 1 123 | 124 | # Add title 125 | add_text(screen_chart, Color.white + title, 0, 1) 126 | 127 | # Add bottom bar 128 | add_text(screen_axis, [f"{Color.white}─" * chart_size_x], 0, term_size_y - 1) 129 | 130 | # --- 131 | main_screen = merge_screens([screen_chart, screen_axis]) 132 | 133 | source = render(main_screen, term_size_x, term_size_y) 134 | 135 | if return_rich: 136 | try: 137 | from rich.text import Text 138 | except ImportError: 139 | raise Exception("Text not found from rich.text") 140 | return Text.from_ansi(source) 141 | else: 142 | return source 143 | 144 | 145 | def bar(data, title, rich=False, mode="h"): 146 | if mode == "h": 147 | return bar_chart_raw_h(data, title, return_rich=rich) 148 | if mode == "v": 149 | return bar_chart_raw_v(data, title, return_rich=rich) 150 | -------------------------------------------------------------------------------- /src/termcharts/colors.py: -------------------------------------------------------------------------------- 1 | import itertools 2 | 3 | # if need instantiation use dataclass 4 | class Color: 5 | RESET = "\033[39m" 6 | 7 | red = "\033[31m" 8 | green = "\033[32m" 9 | orange = "\033[33m" 10 | purple = "\033[35m" 11 | white = "\033[37m" 12 | 13 | 14 | default_colors = itertools.cycle([Color.red, Color.green, Color.orange, Color.purple]) 15 | -------------------------------------------------------------------------------- /src/termcharts/engine.py: -------------------------------------------------------------------------------- 1 | from collections import ChainMap 2 | from typing import Union 3 | 4 | 5 | def coord_to_str(coord): 6 | r = "-".join([str(i) for i in coord]) 7 | return r 8 | 9 | 10 | def add_char(screen_: dict, coord: Union[list, tuple], value): 11 | # add coord to screen 12 | coord_str = coord_to_str(coord) 13 | 14 | screen_[coord_str] = value 15 | 16 | 17 | def get_coord(screen, coord: Union[list, tuple]): 18 | return screen[coord_to_str(coord)] 19 | 20 | 21 | def coord_in_scr(screen: dict, coord: Union[list, tuple]): 22 | return coord_to_str(coord) in screen 23 | 24 | 25 | def pie_render(screen, displayx, displayy, debug=False): 26 | displayx, displayy = displayy, displayx 27 | 28 | c = 0 29 | xxx = "" 30 | for x in range(displayx - 20): 31 | for y in range(displayy): 32 | c += 1 33 | if c % (displayy) == 0: 34 | if debug: 35 | end = "|\n" 36 | else: 37 | end = "\n" 38 | else: 39 | end = "" 40 | 41 | if x <= displayx and y <= displayy: 42 | # print(x, y, displayx, displayy) 43 | if not coord_in_scr(screen, [x, y]): 44 | xxx = xxx + " " + end 45 | else: 46 | xxx = xxx + get_coord(screen, [x, y]) + end 47 | 48 | return xxx 49 | 50 | 51 | def render(screen, size_x, size_y): 52 | RESET = "\033[39m" 53 | string = "" 54 | end = "" 55 | counter = 0 56 | for y in range(size_y): 57 | for x in range(size_x): 58 | counter += 1 59 | if counter % size_x == 0: 60 | end = "\n" 61 | else: 62 | end = "" 63 | 64 | coord = f"{x}-{y}" 65 | 66 | if x <= size_x and y <= size_y: 67 | if not coord_in_scr(screen, [x, y]): 68 | string = string + " " + end 69 | else: 70 | string = string + get_coord(screen, [x, y]) + end 71 | 72 | return string 73 | 74 | 75 | def pie_add_text(screen_, text, gx, gy, mode="h"): 76 | x = 0 77 | y = 0 78 | 79 | for c in text: 80 | if "h" in mode: 81 | add_char(screen_, [gy, gx + x], c) 82 | x += 1 83 | if "v" in mode: 84 | add_char(screen_, [gy + y, x], c) 85 | y += 1 86 | 87 | 88 | def add_text(screen_, text: Union[list, str], gx, gy, mode="h"): 89 | """List is the preferred text type, colors integrate without problem""" 90 | x = 0 91 | y = 0 92 | 93 | for c in text: 94 | if "h" in mode: 95 | add_char(screen_, [gx + x, gy], c) 96 | x += 1 97 | if "v" in mode: 98 | add_char(screen_, [gx, gy + y], c) 99 | y += 1 100 | 101 | 102 | def screen(): 103 | return {} 104 | 105 | 106 | def merge_screens(screens): 107 | screens = reversed(screens) 108 | return dict(ChainMap(*screens)) 109 | -------------------------------------------------------------------------------- /src/termcharts/formula.py: -------------------------------------------------------------------------------- 1 | def constrain( 2 | val, start, end, realstart, realend, lessthan_sym=None, morethan_sym=None 3 | ): 4 | # from hooman 5 | # mouseX 0 width 0 255 6 | # v = (mouseX / (end-start)) * (realend-realstart) 7 | # return realstart + v 8 | # if val < start, val = start 9 | # if val > end, val = end 10 | 11 | if val < start: 12 | if lessthan_sym is None: 13 | return start 14 | else: 15 | return lessthan_sym 16 | if val > end: 17 | if morethan_sym is None: 18 | return end 19 | else: 20 | return morethan_sym 21 | v = ((val - start) / (end - start)) * (realend - realstart) 22 | return realstart + v 23 | -------------------------------------------------------------------------------- /src/termcharts/main.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdur-rahmaanJ/termcharts/f0dc7e01a61f5492c07d2840cf493606aeff9474/src/termcharts/main.py -------------------------------------------------------------------------------- /src/termcharts/pie.py: -------------------------------------------------------------------------------- 1 | # at coord we put symbol 2 | # 0-0 3 | import itertools 4 | import math 5 | 6 | from termcharts.colors import Color 7 | from termcharts.colors import default_colors 8 | from termcharts.engine import add_char 9 | from termcharts.engine import coord_in_scr 10 | from termcharts.engine import coord_to_str 11 | from termcharts.engine import get_coord 12 | from termcharts.engine import pie_add_text as add_text 13 | from termcharts.engine import pie_render as render 14 | 15 | 16 | def corx(xc, r, theta): 17 | return xc + (r * math.cos(math.radians(theta))) 18 | 19 | 20 | def cory(yc, r, theta): 21 | return yc + (r * math.sin(math.radians(theta))) 22 | 23 | 24 | grid_s = 20 25 | centerx = 250 26 | centery = 250 27 | rx = 200 28 | ry = 200 29 | 30 | 31 | def sector_line(centerx, centery, rx, ry, degstart, degend, grid_s, screen, symbol): 32 | for i in range(degstart, degend): 33 | x = corx(centerx, rx, i) 34 | y = cory(centery, ry, i) 35 | 36 | gx = int(x // grid_s) 37 | gy = int(y // grid_s) 38 | 39 | add_char(screen, [gx, gy], symbol) 40 | 41 | 42 | def pie_chart_raw( 43 | data: dict, 44 | centerx, 45 | centery, 46 | rx, 47 | ry, 48 | grid_s, 49 | screen, 50 | return_rich=False, 51 | __debug=False, 52 | fill=False, 53 | title="pie chart", 54 | ): 55 | total = sum(data[d] for d in data) 56 | deg_current = 0 57 | # for i in range(10): 58 | 59 | if fill == True: 60 | fill_factor = 21 61 | else: 62 | fill_factor = 5 63 | 64 | max_d_len = sum(len(e) for e in data) 65 | for s, d in enumerate(data): 66 | 67 | deg_step = int((data[d] / total) * 360) 68 | col = next(default_colors) 69 | 70 | # legend 71 | # add_text(screen, col + d, 25, s + 2) 72 | # add_text(screen, 'x', 25, 3) 73 | # add_char(screen, [10, 3], '#') 74 | 75 | # print(col+d) 76 | # print(col+d) 77 | if not return_rich: 78 | txt = f"{col} {d} {Color.RESET}" 79 | else: 80 | txt = f"{col} {d}" 81 | 82 | # print(d, col+d, col+d+Color.RESET, file=open('z.log', 'w+')) 83 | 84 | # txt = d 85 | add_text(screen, txt, 25, s + 2) 86 | 87 | for i in range(10): 88 | 89 | if not return_rich: 90 | text = col + "█" + Color.RESET # reset col 91 | else: 92 | text = col + "█" 93 | sector_line( 94 | centerx, 95 | centery, 96 | rx - (i * fill_factor), 97 | ry - (i * fill_factor), 98 | deg_current, 99 | deg_current + deg_step, 100 | grid_s, 101 | screen, 102 | text, 103 | ) 104 | deg_current += deg_step 105 | 106 | add_text(screen, title, 0, 1) 107 | 108 | display = 50 + max_d_len + 3 109 | 110 | source = render(screen, display - (25), display - (9 + max_d_len), debug=__debug) 111 | 112 | if return_rich: 113 | try: 114 | from rich.text import Text 115 | except ImportError: 116 | raise Exception("Text not found from rich.text") 117 | return Text.from_ansi(source) 118 | else: 119 | return source 120 | 121 | 122 | def pie_chart(data, rich=False, title="pie chart", screen=None): 123 | global centerx, centery, rx, ry, grid_s 124 | fill = True 125 | if screen is None: 126 | screen = {} 127 | return pie_chart_raw( 128 | data, 129 | centerx, 130 | centery, 131 | rx, 132 | ry, 133 | grid_s, 134 | screen, 135 | fill=fill, 136 | return_rich=rich, 137 | title=title, 138 | ) 139 | 140 | 141 | def doughnut_chart(data, rich=False, title="doughnut chart", screen=None): 142 | global centerx, centery, rx, ry, grid_s 143 | fill = False 144 | if screen is None: 145 | screen = {} 146 | return pie_chart_raw( 147 | data, 148 | centerx, 149 | centery, 150 | rx, 151 | ry, 152 | grid_s, 153 | screen, 154 | fill=fill, 155 | return_rich=rich, 156 | title=title, 157 | ) 158 | -------------------------------------------------------------------------------- /tests/test_colors.py: -------------------------------------------------------------------------------- 1 | from termcharts.colors import Color 2 | 3 | 4 | def test_colors(): 5 | assert Color.red == "\033[31m" 6 | -------------------------------------------------------------------------------- /tests/test_engine.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import pytest 3 | sys.path.append('.') 4 | from src.termcharts.engine import merge_screens 5 | from src.termcharts.engine import coord_in_scr 6 | from src.termcharts.engine import pie_add_text 7 | from src.termcharts.engine import coord_to_str 8 | from src.termcharts.engine import pie_render 9 | from src.termcharts.engine import get_coord 10 | from src.termcharts.engine import add_text 11 | from src.termcharts.engine import add_char 12 | from src.termcharts.engine import render 13 | 14 | 15 | """ 16 | Pytest docs: 17 | - https://docs.pytest.org/en/7.1.x/ 18 | Testing module for termcharts/engine.py 19 | Each function has it's own `screen` localized and tested separately 20 | """ 21 | 22 | def test_coord_to_str(): 23 | output = coord_to_str('testing') 24 | expected = 't-e-s-t-i-n-g' 25 | assert output == expected, '`coord_to_str()` function may be changed but test not updated' 26 | 27 | 28 | def test_render(): 29 | screen = {"0-0": "x", "10-20": "@"} 30 | add_char(screen, [0, 3], "/") 31 | 32 | string = render(screen, 11, 21) 33 | assert ( 34 | string.replace(" ", "+").replace("\n", "
") 35 | == "x++++++++++++++++++++
++++++++++++++++++++++
++++++++++++++++++++++
/++++++++++++++++++++
++++++++++++++++++++++
++++++++++++++++++++++
++++++++++++++++++++++
++++++++++++++++++++++
++++++++++++++++++++++
++++++++++++++++++++++
++++++++++++++++++++++
++++++++++++++++++++++
++++++++++++++++++++++
++++++++++++++++++++++
++++++++++++++++++++++
++++++++++++++++++++++
++++++++++++++++++++++
++++++++++++++++++++++
++++++++++++++++++++++
++++++++++++++++++++++
++++++++++++++++++++@
" 36 | ) 37 | 38 | 39 | def test_coord_in_scr(): 40 | screen = {} 41 | screen['10-10'] = 'test' 42 | 43 | assert not coord_in_scr(screen, [12, 10]), "`coord_in_scr()` reports false positive" 44 | assert coord_in_scr(screen, [10, 10]), "`coord_in_scr()` reports false negative" 45 | 46 | 47 | def test_pie_add_text(): 48 | screen = {} 49 | pie_add_text(screen, 'test', 4, 4, mode='h') 50 | expexted = { 51 | '4-4': 't', 52 | '4-5': 'e', 53 | '4-6': 's', 54 | '4-7': 't', 55 | } 56 | assert screen == expexted, "`pie_add_text()` failes at `horizontal` mode" 57 | 58 | screen.clear() 59 | 60 | pie_add_text(screen, 'test', 4, 4, mode='v') 61 | expexted = { 62 | '4-0': 't', 63 | '5-0': 'e', 64 | '6-0': 's', 65 | '7-0': 't', 66 | } 67 | assert screen == expexted, "`pie_add_text()` failes at `vertical` mode" 68 | 69 | 70 | def test_add_text(): 71 | screen = {} 72 | add_text(screen, 'test', 4, 4, mode='h') 73 | expected = { 74 | '4-4': 't', 75 | '5-4': 'e', 76 | '6-4': 's', 77 | '7-4': 't', 78 | } 79 | assert screen == expected, "`add_text()` failes at `horizontal` mode" 80 | 81 | screen.clear() 82 | 83 | add_text(screen, 'test', 4, 4, mode='v') 84 | expected = { 85 | '0-4': 't', 86 | '0-5': 'e', 87 | '0-6': 's', 88 | '0-7': 't', 89 | } 90 | assert screen == expected, "`add_text()` failes at `vertical` mode" 91 | 92 | 93 | def test_get_coord(): 94 | screen = {'10-5': 'test'} 95 | assert get_coord(screen, [10, 5]) == screen['10-5'] 96 | 97 | 98 | def test_merge_screens(): 99 | screen1 = {"10-5": "1", "10-6": "2"} 100 | screen2 = {"8-3": "A", "9-3": "B"} 101 | screens = [screen1, screen2] 102 | 103 | merged = merge_screens(screens) 104 | expected = { 105 | "10-5": "1", 106 | "10-6": "2", 107 | "8-3": "A", 108 | "9-3": "B", 109 | } 110 | 111 | assert merged == expected 112 | --------------------------------------------------------------------------------