├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── minimap.png ├── minimap └── __init__.py ├── requirements.txt ├── setup.cfg └── setup.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 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | MANIFEST 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | 49 | # Translations 50 | *.mo 51 | *.pot 52 | 53 | # Django stuff: 54 | *.log 55 | .static_storage/ 56 | .media/ 57 | local_settings.py 58 | 59 | # Flask stuff: 60 | instance/ 61 | .webassets-cache 62 | 63 | # Scrapy stuff: 64 | .scrapy 65 | 66 | # Sphinx documentation 67 | docs/_build/ 68 | 69 | # PyBuilder 70 | target/ 71 | 72 | # Jupyter Notebook 73 | .ipynb_checkpoints 74 | 75 | # pyenv 76 | .python-version 77 | 78 | # celery beat schedule file 79 | celerybeat-schedule 80 | 81 | # SageMath parsed files 82 | *.sage.py 83 | 84 | # Environments 85 | .env 86 | .venv 87 | env/ 88 | venv/ 89 | ENV/ 90 | env.bak/ 91 | venv.bak/ 92 | 93 | # Spyder project settings 94 | .spyderproject 95 | .spyproject 96 | 97 | # Rope project settings 98 | .ropeproject 99 | 100 | # mkdocs documentation 101 | /site 102 | 103 | # mypy 104 | .mypy_cache/ 105 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | python: 3 | - "3.6" 4 | 5 | script: minimap.py --overwrite minimap.py 6 | 7 | python: 8 | - "3.6" 9 | - "3.6-dev" # 3.6 development branch 10 | - "3.7-dev" # 3.7 development branch 11 | - "nightly" 12 | 13 | install: 14 | - pip install -r requirements.txt 15 | 16 | script: 17 | - pip install -U pip setuptools wheel 18 | - python setup.py build 19 | - python setup.py install 20 | 21 | deploy: 22 | provider: pypi 23 | user: ivoah 24 | password: 25 | secure: Cztduk1IqNCIdM5hAGieAuWsUhznF3tKmtuMlG/LTGRaK0mKkPW7qpET+oNa2YTY+O4dIV5Q/ZuPtSzMcZEk32XmQODJXpLJLTk4UMwxQG6C/zV2a6MJAMQK/AuQHKFYcvB17612SGcrjeFlduNne7KUZ7dgiLOAyrafKEjvib9xBqa8vckA1CDBOakHB2N+qfgf/yCv+4pjIyyGW/ZkDfQWKoU0/+8P1+GOTHU7hw4czCuNygam7IET+oXWs8Na5avtMC3fEiZ4Mfot1K5eU7hXA+mf+kkzXPh9FEmXiB+yG1Cd3BnSSjHeFy2mjg0GBwKNliNqDVmVQLwIeEeaary2MlEst3GMhBX0LywnxudOBDqwDAqAtWV+PzCCf5jMR8VQYxG1pDV0Z0ZgDip5JdLGkbWI/k/76ywba2YHImM850phLcv+hAe9+6T7wQoRP7RL3KpsVlElXCAiaWSUIiQHo5RZx48JpUlA3Ef6sLbKNVakR1uzUjxfYcBW2t7vC7Ev2xN7mFT5EYH6MfZ8vLpSes8+rPOyBd7RJaSRtHhvXfLBWnskrWmMfqW7RmT9K/D0UXGTalPOOXPpEKELVXlsLH9wZqeZh+abJ8qPvKBEoy37D/cq5S6xVlue0dkgD85XMoljvlyCrCWkcJfTa9cW/h7fua04QDQN+zqt9WE= 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Noah Rosamilia 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # minimap 2 | 3 | [![Build Status](https://travis-ci.org/Ivoah/minimap.svg?branch=master)](https://travis-ci.org/Ivoah/minimap) 4 | [![PyPI version](https://badge.fury.io/py/minimap.svg)](https://badge.fury.io/py/minimap) 5 | 6 | Generate minimaps of your code 7 | 8 | ![example](https://raw.githubusercontent.com/Ivoah/minimap/master/minimap.png) 9 | 10 | ## Requirements 11 | 12 | `minimap.py` requires Python 3.6 or greater 13 | 14 | ## Installation 15 | You can install directly via pip 16 | ```shell 17 | $ pip install -U setuptools # upgrade setuptools to install minimap 18 | $ pip install minimap 19 | ``` 20 | 21 | Or from the [github](https://github.com/Ivoah/minimap) repository (master branch by default) 22 | ```shell 23 | $ git clone https://github.com/Ivoah/minimap 24 | $ cd minimap 25 | $ sudo python setup.py install 26 | ``` 27 | 28 | ## Usage 29 | 30 | ``` 31 | minimap [-o OUTPUT [OUTPUT ...]] [-l LANGUAGE] [-s STYLE] [-w WIDTH] 32 | [-h HEIGHT] [--spacing SPACING] [--overwrite] files [files ...] 33 | ``` 34 | 35 | ## Options 36 | 37 | ``` 38 | -o Output file (or files). Must come after input files if listing multiple 39 | -l Select language to highlight for (if it can't autodetect) 40 | -s Select highlighting style (use `-s list` to list all styles) 41 | -w Width of each character in pixels 42 | -h Height of each character in pixels 43 | --spacing Number of pixels to insert between rows 44 | --overwrite Overwrite output file if it already exists 45 | ``` 46 | -------------------------------------------------------------------------------- /minimap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ivoah/minimap/be13b3687d2113b55aa184aa866a0af60254ea73/minimap.png -------------------------------------------------------------------------------- /minimap/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | import sys 4 | import os.path 5 | import argparse 6 | 7 | import pygments 8 | import pygments.styles 9 | import pygments.lexers 10 | import pygments.formatter 11 | 12 | from PIL import Image 13 | from PIL import ImageDraw 14 | 15 | def main(): 16 | parser = argparse.ArgumentParser(add_help = False) 17 | parser.add_argument('files', nargs = '+') 18 | parser.add_argument('-o', '--output', nargs = '+') 19 | parser.add_argument('-l', '--language', '--lang') 20 | parser.add_argument('-s', '--style', default = 'monokai') 21 | parser.add_argument('-w', '--width', type = int, default = 3) 22 | parser.add_argument('-h', '--height', type = int, default = 5) 23 | parser.add_argument('--spacing', type = int, default = 1) 24 | parser.add_argument('--tab-width', type = int, default = 4) 25 | parser.add_argument('--overwrite', action="store_true") 26 | 27 | args = parser.parse_args() 28 | 29 | if args.style == 'list': 30 | print('Available styles:', ', '.join(pygments.styles.get_all_styles())) 31 | sys.exit(0) 32 | 33 | style = pygments.styles.get_style_by_name(args.style) 34 | colors = {t: '#' + (s['color'] or '777') for t, s in style} 35 | 36 | if args.output is None: 37 | args.output = [os.path.splitext(os.path.basename(filename))[0] + '.png' for filename in args.files] 38 | 39 | if len(args.output) > 0 and len(args.files) != len(args.output): 40 | print(f'{sys.argv[0]}: error: output must have the same number of arguments as input') 41 | sys.exit(1) 42 | 43 | for filename, output in zip(args.files, args.output): 44 | if not args.overwrite and os.path.exists(output): 45 | print(f'{sys.argv[0]}: error: "{output}" already exists') 46 | sys.exit(1) 47 | 48 | with open(filename, 'r') as f: 49 | code = f.read() 50 | if args.language: 51 | lexer = pygments.lexers.get_lexer_by_name(args.language) 52 | else: 53 | lexer = pygments.lexers.get_lexer_for_filename(filename) 54 | 55 | tokens = list(pygments.lex(code, lexer)) 56 | 57 | lines = ''.join(map(lambda t: t[1], tokens)).split('\n') 58 | width = max(map(len, lines))*args.width 59 | height = (len(lines) - 1)*(args.height + args.spacing) - args.spacing 60 | 61 | img = Image.new('RGB', (width, height), style.background_color) 62 | draw = ImageDraw.Draw(img) 63 | 64 | x = 0 65 | y = 0 66 | for ttype, token in tokens: 67 | for c in token: 68 | if c == '\n': 69 | x = 0 70 | y += args.height + args.spacing 71 | elif c == ' ': 72 | x += args.width 73 | elif c == '\t': 74 | x += args.width*args.tab_width 75 | else: 76 | draw.rectangle([(x, y), (x + args.width - 1, y + args.height - 1)], colors[ttype]) 77 | x += args.width 78 | 79 | img.save(output) 80 | 81 | if __name__ == '__main__': 82 | main() 83 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | Pillow>=4.2.1 2 | Pygments>=2.2.0 3 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | name = minimap 3 | description = "Generate minimaps of your code" 4 | version = 0.1.0 5 | author = Noah Rosamilia 6 | author_email = ivoahivoah@gmail.com 7 | url = https://github.com/Ivoah/minimap 8 | license = MIT 9 | keywords = source, code, image, generate 10 | classifiers = 11 | License :: OSI approved :: MIT License 12 | Natural Language :: English 13 | Programming Language :: Python :: 3.6 14 | 15 | [options] 16 | install_requires = 17 | Pillow==4.2.1 18 | Pygments==2.2.0 19 | packages = find: 20 | 21 | [options.entry_points] 22 | console_scripts = 23 | minimap = minimap:main 24 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | from setuptools import setup 4 | 5 | setup() 6 | --------------------------------------------------------------------------------