├── .github ├── dependabot.yml └── workflows │ └── lint.yml ├── .gitignore ├── LICENSE ├── README.md ├── assets ├── icons │ ├── KoalaKeys.png │ ├── favicon-32.ico │ └── favicon.ico └── images │ └── KoalaKeys_Example.png ├── cheatsheets └── example-cheatsheet.yaml ├── requirements.txt ├── src ├── __init__.py ├── generate_cheatsheet.py ├── layouts │ ├── keyboard_layouts.yaml │ └── system_mappings.yaml ├── logger.py ├── template_renderer.py ├── templates │ ├── base.html │ ├── cheatsheets │ │ ├── assets │ │ │ └── cheatsheets.css │ │ ├── cheatsheet-template.html │ │ ├── components │ │ │ ├── body.html │ │ │ └── header.html │ │ └── scripts │ │ │ └── main.js │ └── index_template.html └── validate_yaml.py └── yaml_cheatsheet_spec.md /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | # Update Python packages 4 | - package-ecosystem: "pip" 5 | directory: "/" 6 | schedule: 7 | interval: "weekly" 8 | open-pull-requests-limit: 10 9 | 10 | # Update GitHub Actions 11 | - package-ecosystem: "github-actions" 12 | directory: "/" 13 | schedule: 14 | interval: "weekly" 15 | open-pull-requests-limit: 10 16 | -------------------------------------------------------------------------------- /.github/workflows/lint.yml: -------------------------------------------------------------------------------- 1 | name: Lint 2 | on: 3 | push: 4 | branches-ignore: ["main"] 5 | pull_request: 6 | branches: ["main"] 7 | workflow_dispatch: 8 | 9 | permissions: {} 10 | 11 | jobs: 12 | lint: 13 | runs-on: ubuntu-latest 14 | 15 | permissions: 16 | contents: read 17 | packages: read 18 | statuses: write 19 | 20 | steps: 21 | - name: Checkout Code 22 | uses: actions/checkout@v4 23 | with: 24 | fetch-depth: 0 25 | 26 | - name: Lint Code Base 27 | uses: github/super-linter@v7 28 | env: 29 | VALIDATE_ALL_CODEBASE: true 30 | FIX_PYTHON_RUFF: true 31 | VALIDATE_PYTHON_RUFF: true 32 | FIX_MARKDOWN_PRETTIER: true 33 | VALIDATE_MARKDOWN_PRETTIER: true 34 | VALIDATE_GITLEAKS: true 35 | VALIDATE_GITHUB_ACTIONS: true 36 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 37 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .aider* 2 | output/* 3 | 4 | 5 | *.log 6 | 7 | env 8 | venv 9 | .venv 10 | .env 11 | 12 | cheatsheets/* 13 | !cheatsheets/example-cheatsheet.yaml 14 | 15 | ### macOS ### 16 | # General 17 | .DS_Store 18 | .AppleDouble 19 | .LSOverride 20 | 21 | # Files that might appear in the root of a volume 22 | .DocumentRevisions-V100 23 | .fseventsd 24 | .Spotlight-V100 25 | .TemporaryItems 26 | .Trashes 27 | .VolumeIcon.icns 28 | .com.apple.timemachine.donotpresent 29 | 30 | 31 | # Distribution / packaging 32 | .Python 33 | build/ 34 | develop-eggs/ 35 | dist/ 36 | downloads/ 37 | eggs/ 38 | .eggs/ 39 | lib/ 40 | lib64/ 41 | parts/ 42 | sdist/ 43 | var/ 44 | wheels/ 45 | share/python-wheels/ 46 | *.egg-info/ 47 | .installed.cfg 48 | *.egg 49 | MANIFEST 50 | 51 | 52 | *pycache* 53 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 |

4 | 5 | # KoalaKeys 6 | 7 | A simple tool to create and manage portable keyboard shortcut cheat sheets. 8 | 9 | > **Demo**: Check out the [live demo](https://rtuszik.github.io/KoalaKeys-Collection/) to see a small collection of cheat sheets created with this project. 10 | 11 | ## Overview 12 | 13 | KoalaKeys generates and organizes portable, interactive HTML cheat sheets for keyboard shortcuts. It's designed for developers, designers, and power users who want to keep their essential shortcuts easily accessible. 14 | 15 | > **Quick Start**: To create a cheat sheet, add a YAML file to the `cheatsheets` directory and run `python src/generate_cheatsheet.py`. For detailed YAML formatting instructions, see the [YAML Cheat Sheet Specification Guide](yaml_cheatsheet_spec.md). 16 | 17 | ## Screenshots 18 | 19 |

20 | 21 | 22 |

23 | 24 | ## Features 25 | 26 | - Generate HTML cheat sheets from YAML files 27 | - Interactive keyboard layout with real-time highlighting 28 | - Categorized shortcuts with descriptions 29 | - Index page for quick access to all cheat sheets 30 | - Search functionality 31 | - Support for different keyboard layouts and system mappings 32 | 33 | ## Demo and Examples 34 | 35 | A live demo instance is available, showcasing a selection of cheat sheets: 36 | 37 | - **Demo Site**: [https://rtuszik.github.io/KoalaKeys-Collection/](https://rtuszik.github.io/KoalaKeys-Collection/) 38 | - **Demo Repository**: [https://github.com/rtuszik/KoalaKeys-Collection](https://github.com/rtuszik/KoalaKeys-Collection) 39 | 40 | Explore the demo to see how KoalaKeys works and to get ideas for creating custom cheat sheets. The demo repository also contains example YAML files that can be used as templates for new cheat sheets. 41 | 42 | ## Available Systems and Keyboards 43 | 44 | ### Systems 45 | 46 | - Darwin (macOS) 47 | - Linux 48 | - Windows 49 | 50 | ### Keyboard Layouts 51 | 52 | - US 53 | - UK 54 | - DE (German) 55 | - FR (French) 56 | - ES (Spanish) 57 | - DVORAK 58 | 59 | ## Requirements 60 | 61 | - Python 3.8+ 62 | 63 | ## Installation 64 | 65 | 1. Clone the repository: 66 | 67 | ``` 68 | git clone https://github.com/rtuszik/KoalaKeys 69 | cd KoalaKeys 70 | ``` 71 | 72 | 2. Create and activate a virtual environment (optional): 73 | 74 | ``` 75 | python -m venv .venv 76 | source .venv/bin/activate # On Windows, use `venv\Scripts\activate` 77 | ``` 78 | 79 | 3. Install dependencies: 80 | 81 | ``` 82 | pip install -r requirements.txt 83 | ``` 84 | 85 | 4. Set up the output directory: 86 | Create a `.env` file in the project root with: 87 | ``` 88 | CHEATSHEET_OUTPUT_DIR=path/to/your/output/directory 89 | ``` 90 | 91 | ## Usage 92 | 93 | 1. Create YAML files for your cheat sheets in the `cheatsheets` directory. For detailed instructions on how to format YAML files, please refer to the [YAML Cheat Sheet Specification Guide](yaml_cheatsheet_spec.md). 94 | 95 | 2. Generate cheat sheets: 96 | 97 | ``` 98 | python src/generate_cheatsheet.py 99 | ``` 100 | 101 | 3. Find the HTML cheat sheets in the specified output directory. 102 | 103 | 4. Open `index.html` to view the cheat sheet collection. 104 | 105 | ## Contributing 106 | 107 | Contributions are welcome! Feel free to submit issues, feature requests, or pull requests. 108 | 109 | ## License 110 | 111 | This project is licensed under the terms of the [GPLv3](LICENSE). 112 | -------------------------------------------------------------------------------- /assets/icons/KoalaKeys.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rtuszik/KoalaKeys/073a4a9603f9c4d6fc6c5a92fedae9c1f4516934/assets/icons/KoalaKeys.png -------------------------------------------------------------------------------- /assets/icons/favicon-32.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rtuszik/KoalaKeys/073a4a9603f9c4d6fc6c5a92fedae9c1f4516934/assets/icons/favicon-32.ico -------------------------------------------------------------------------------- /assets/icons/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rtuszik/KoalaKeys/073a4a9603f9c4d6fc6c5a92fedae9c1f4516934/assets/icons/favicon.ico -------------------------------------------------------------------------------- /assets/images/KoalaKeys_Example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rtuszik/KoalaKeys/073a4a9603f9c4d6fc6c5a92fedae9c1f4516934/assets/images/KoalaKeys_Example.png -------------------------------------------------------------------------------- /cheatsheets/example-cheatsheet.yaml: -------------------------------------------------------------------------------- 1 | title: "KoalaKeys" 2 | RenderKeys: true # defaults to true 3 | AllowText: false # defaults to false - requires RenderKeys: false 4 | layout: 5 | keyboard: US 6 | system: Darwin 7 | shortcuts: 8 | General: 9 | "CMD+C": 10 | description: "Copy selected item" 11 | "CMD+X": 12 | description: "Cut selected item" 13 | File and App Management: 14 | "CMD+N": 15 | description: "Open new window or document" 16 | "CMD+O": 17 | description: "Open selected item or display dialog to choose file to open" 18 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | jinja2==3.1.4 2 | python-dotenv==1.0.1 3 | ruamel.yaml==0.18.6 4 | -------------------------------------------------------------------------------- /src/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rtuszik/KoalaKeys/073a4a9603f9c4d6fc6c5a92fedae9c1f4516934/src/__init__.py -------------------------------------------------------------------------------- /src/generate_cheatsheet.py: -------------------------------------------------------------------------------- 1 | from ruamel.yaml import YAML 2 | from jinja2 import Environment, FileSystemLoader 3 | import sys 4 | import os 5 | from validate_yaml import validate_yaml, lint_yaml 6 | from dotenv import load_dotenv 7 | from template_renderer import render_template 8 | from logger import get_logger 9 | from pathlib import Path 10 | 11 | # Create YAML instances once 12 | yaml_safe = YAML(typ='safe') 13 | yaml_rw = YAML() 14 | yaml_rw.indent(mapping=2, sequence=4, offset=2) 15 | yaml_rw.preserve_quotes = True 16 | yaml_rw.width = 100 17 | 18 | load_dotenv() 19 | 20 | # Define base paths 21 | BASE_DIR = Path(__file__).parent 22 | PROJECT_ROOT = BASE_DIR.parent 23 | 24 | # Define directory paths 25 | OUTPUT_DIR = Path(os.getenv('CHEATSHEET_OUTPUT_DIR') or PROJECT_ROOT / "output") 26 | TEMPLATES_DIR = BASE_DIR / "templates" 27 | LAYOUTS_DIR = BASE_DIR / "layouts" 28 | CHEATSHEETS_DIR = PROJECT_ROOT / "cheatsheets" 29 | 30 | # Ensure output directory exists 31 | OUTPUT_DIR.mkdir(exist_ok=True, parents=True) 32 | 33 | logging = get_logger() 34 | 35 | # Load environment variables 36 | 37 | def load_yaml(file_path: Path) -> dict | None: 38 | try: 39 | with open(file_path, "r", encoding='utf-8') as file: 40 | return yaml_safe.load(file) 41 | except FileNotFoundError: 42 | logging.error(f"Error: YAML file '{file_path}' not found.") 43 | return None 44 | except Exception as e: 45 | logging.error(f"Error reading YAML file '{file_path}': {e}") 46 | return None 47 | 48 | 49 | def load_layout(): 50 | keyboard_layouts = load_yaml(LAYOUTS_DIR / "keyboard_layouts.yaml") 51 | system_mappings = load_yaml(LAYOUTS_DIR / "system_mappings.yaml") 52 | 53 | if keyboard_layouts is None or system_mappings is None: 54 | logging.error("Failed to load configuration files.") 55 | return None, None 56 | 57 | return keyboard_layouts, system_mappings 58 | 59 | def replace_shortcut_names(shortcut, system_mappings): 60 | arrow_key_mappings = { 61 | "Up": "↑", 62 | "Down": "↓", 63 | "Left": "←", 64 | "Right": "→" 65 | } 66 | try: 67 | processed_parts = [] 68 | i = 0 69 | while i < len(shortcut): 70 | if shortcut[i] == '+': 71 | # If next character is also +, it's a key 72 | if i + 1 < len(shortcut) and shortcut[i + 1] == '+': 73 | processed_parts.append('+') 74 | i += 2 # Skip both plus signs 75 | # Otherwise it's a separator 76 | else: 77 | processed_parts.append('') 78 | i += 1 79 | else: 80 | # Collect non-plus characters 81 | current_part = '' 82 | while i < len(shortcut) and shortcut[i] != '+': 83 | current_part += shortcut[i] 84 | i += 1 85 | if current_part.strip(): # Only add non-empty parts 86 | part = current_part.strip() 87 | part = system_mappings.get(part.lower(), part) 88 | if part in ['⌘', '⌥', '⌃', '⇧']: 89 | part = f'{part}' 90 | 91 | part = arrow_key_mappings.get(part, part) 92 | processed_parts.append(part) 93 | 94 | 95 | return ''.join(processed_parts) 96 | except Exception as e: 97 | logging.error(f"Error replacing shortcut names: {e}") 98 | return shortcut 99 | 100 | def normalize_shortcuts(data, system_mappings): 101 | normalized = {} 102 | allow_text = data.get('AllowText', False) 103 | try: 104 | for section, shortcuts in data.get("shortcuts", {}).items(): 105 | normalized[section] = {} 106 | for shortcut, details in shortcuts.items(): 107 | if allow_text: 108 | # When AllowText is true, just pass through the shortcut text 109 | normalized[section][shortcut] = details 110 | else: 111 | # Normal processing for keyboard shortcuts 112 | normalized_shortcut = replace_shortcut_names(shortcut, system_mappings) 113 | normalized[section][normalized_shortcut] = details 114 | except Exception as e: 115 | logging.error(f"Error normalizing shortcuts: {e}") 116 | return normalized 117 | 118 | 119 | def get_layout_info(data): 120 | layout = data.get("layout", {}) 121 | return { 122 | "keyboard": layout.get("keyboard", "US"), 123 | "system": layout.get("system", "Darwin"), 124 | } 125 | 126 | def generate_html(data, keyboard_layouts, system_mappings): 127 | template_path = "cheatsheets/cheatsheet-template.html" 128 | layout_info = get_layout_info(data) 129 | data["shortcuts"] = normalize_shortcuts( 130 | data, system_mappings.get(layout_info["system"], {}) 131 | ) 132 | data["layout"] = layout_info 133 | data["keyboard_layout"] = keyboard_layouts.get(layout_info["keyboard"], {}).get("layout") 134 | data["render_keys"] = data.get("RenderKeys", True) 135 | data["allow_text"] = data.get("AllowText", False) 136 | 137 | return render_template(template_path, data) 138 | 139 | 140 | def validate_and_lint(yaml_file): 141 | validation_result = validate_yaml(yaml_file) 142 | warnings = lint_yaml(yaml_file) 143 | 144 | if not validation_result: 145 | logging.error(f"Validation failed for {yaml_file}") 146 | return False 147 | 148 | if warnings: 149 | logging.warning(f"Linting warnings in {yaml_file}:") 150 | for warning in warnings: 151 | logging.warning(f" - {warning}") 152 | 153 | return True 154 | 155 | def write_html_content(html_output, html_content): 156 | try: 157 | with open(html_output, "w", encoding='utf-8') as file: 158 | file.write(html_content) 159 | except IOError as e: 160 | logging.error(f"Error writing to output file: {e}") 161 | return False 162 | return True 163 | 164 | def main(yaml_file): 165 | if not validate_and_lint(yaml_file): 166 | return None, None 167 | 168 | data = load_yaml(yaml_file) 169 | if data is None or "title" not in data: 170 | logging.error("Error: Invalid YAML file or missing 'title' field.") 171 | return None, None 172 | 173 | keyboard_layouts, system_mappings = load_layout() 174 | if keyboard_layouts is None or system_mappings is None: 175 | return None, None 176 | 177 | html_content = generate_html(data, keyboard_layouts, system_mappings) 178 | if html_content is None: 179 | return None, None 180 | 181 | base_filename = f"{data['title'].lower().replace(' ', '_')}_cheatsheet" 182 | html_output = os.path.join(OUTPUT_DIR, f"{base_filename}.html") 183 | 184 | if not write_html_content(html_output, html_content): 185 | return None, None 186 | 187 | logging.info(f"Cheatsheet generated: {html_output}") 188 | 189 | return data["title"], os.path.basename(html_output) 190 | 191 | 192 | def generate_index(cheatsheets): 193 | template_path = TEMPLATES_DIR / "index_template.html" 194 | env = Environment(loader=FileSystemLoader(os.path.dirname(template_path))) 195 | template = env.get_template(os.path.basename(template_path)) 196 | 197 | html_content = template.render(cheatsheets=cheatsheets) 198 | 199 | index_output = os.path.join(OUTPUT_DIR, "index.html") 200 | 201 | with open(index_output, "w", encoding='utf-8') as file: 202 | file.write(html_content) 203 | 204 | logging.info(f"Index page generated: {index_output}") 205 | 206 | 207 | if __name__ == "__main__": 208 | yaml_files = yaml_files = list(CHEATSHEETS_DIR.glob("*.yaml")) 209 | 210 | if not yaml_files: 211 | print("No YAML files found in the cheatsheets directory.") 212 | sys.exit(1) 213 | 214 | cheatsheets = [] 215 | for yaml_file in yaml_files: 216 | title, filename = main(yaml_file) 217 | if title and filename: 218 | cheatsheets.append({"title": title, "filename": filename}) 219 | 220 | if cheatsheets: 221 | generate_index(cheatsheets) 222 | print(f"Generated cheatsheets for {len(cheatsheets)} YAML files.") 223 | else: 224 | print("No valid cheatsheets were generated due to errors.") 225 | -------------------------------------------------------------------------------- /src/layouts/keyboard_layouts.yaml: -------------------------------------------------------------------------------- 1 | US: 2 | layout: 3 | - [ 4 | "Esc", 5 | "F1", 6 | "F2", 7 | "F3", 8 | "F4", 9 | "F5", 10 | "F6", 11 | "F7", 12 | "F8", 13 | "F9", 14 | "F10", 15 | "F11", 16 | "F12", 17 | ] 18 | - [ 19 | "`", 20 | "1", 21 | "2", 22 | "3", 23 | "4", 24 | "5", 25 | "6", 26 | "7", 27 | "8", 28 | "9", 29 | "0", 30 | "-", 31 | "=", 32 | "Backspace", 33 | ] 34 | - ["Tab", "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "[", "]", "\\"] 35 | - [ 36 | "CapsLock", 37 | "A", 38 | "S", 39 | "D", 40 | "F", 41 | "G", 42 | "H", 43 | "J", 44 | "K", 45 | "L", 46 | ";", 47 | "'", 48 | "Enter", 49 | ] 50 | - ["Shift", "Z", "X", "C", "V", "B", "N", "M", ",", ".", "/", "Shift"] 51 | - [ 52 | "Ctrl", 53 | "Alt", 54 | "Cmd", 55 | "Space", 56 | "Cmd", 57 | "Alt", 58 | "Ctrl", 59 | "Left", 60 | "Up", 61 | "Down", 62 | "Right", 63 | ] 64 | 65 | UK: 66 | layout: 67 | - [ 68 | "Esc", 69 | "F1", 70 | "F2", 71 | "F3", 72 | "F4", 73 | "F5", 74 | "F6", 75 | "F7", 76 | "F8", 77 | "F9", 78 | "F10", 79 | "F11", 80 | "F12", 81 | ] 82 | - [ 83 | "`", 84 | "1", 85 | "2", 86 | "3", 87 | "4", 88 | "5", 89 | "6", 90 | "7", 91 | "8", 92 | "9", 93 | "0", 94 | "-", 95 | "=", 96 | "Backspace", 97 | ] 98 | - ["Tab", "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "[", "]", "\\"] 99 | - [ 100 | "CapsLock", 101 | "A", 102 | "S", 103 | "D", 104 | "F", 105 | "G", 106 | "H", 107 | "J", 108 | "K", 109 | "L", 110 | ";", 111 | "'", 112 | "Enter", 113 | ] 114 | - ["Shift", "\\", "Z", "X", "C", "V", "B", "N", "M", ",", ".", "/", "Shift"] 115 | - ["Ctrl", "Alt", "Cmd", "Space", "Cmd", "Alt", "Ctrl"] 116 | 117 | DE: 118 | layout: 119 | - [ 120 | "Esc", 121 | "F1", 122 | "F2", 123 | "F3", 124 | "F4", 125 | "F5", 126 | "F6", 127 | "F7", 128 | "F8", 129 | "F9", 130 | "F10", 131 | "F11", 132 | "F12", 133 | ] 134 | - [ 135 | "^", 136 | "1", 137 | "2", 138 | "3", 139 | "4", 140 | "5", 141 | "6", 142 | "7", 143 | "8", 144 | "9", 145 | "0", 146 | "ß", 147 | "´", 148 | "Backspace", 149 | ] 150 | - [ 151 | "Tab", 152 | "Q", 153 | "W", 154 | "E", 155 | "R", 156 | "T", 157 | "Z", 158 | "U", 159 | "I", 160 | "O", 161 | "P", 162 | "Ü", 163 | "+", 164 | "Enter", 165 | ] 166 | - ["CapsLock", "A", "S", "D", "F", "G", "H", "J", "K", "L", "Ö", "Ä", "#"] 167 | - ["Shift", "Y", "X", "C", "V", "B", "N", "M", ",", ".", "-", "Shift"] 168 | - ["Ctrl", "Alt", "Cmd", "Space", "Cmd", "Alt", "Ctrl"] 169 | 170 | FR: 171 | layout: 172 | - [ 173 | "Esc", 174 | "F1", 175 | "F2", 176 | "F3", 177 | "F4", 178 | "F5", 179 | "F6", 180 | "F7", 181 | "F8", 182 | "F9", 183 | "F10", 184 | "F11", 185 | "F12", 186 | ] 187 | - [ 188 | "²", 189 | "&", 190 | "é", 191 | '"', 192 | "'", 193 | "(", 194 | "-", 195 | "è", 196 | "_", 197 | "ç", 198 | "à", 199 | ")", 200 | "=", 201 | "Backspace", 202 | ] 203 | - ["Tab", "A", "Z", "E", "R", "T", "Y", "U", "I", "O", "P", "^", "$", "\\"] 204 | - [ 205 | "CapsLock", 206 | "Q", 207 | "S", 208 | "D", 209 | "F", 210 | "G", 211 | "H", 212 | "J", 213 | "K", 214 | "L", 215 | "M", 216 | "ù", 217 | "*", 218 | "Enter", 219 | ] 220 | - ["Shift", "W", "X", "C", "V", "B", "N", ",", ";", ":", "!", "Shift"] 221 | - ["Ctrl", "Alt", "Cmd", "Space", "Cmd", "Alt", "Ctrl"] 222 | 223 | ES: 224 | layout: 225 | - [ 226 | "Esc", 227 | "F1", 228 | "F2", 229 | "F3", 230 | "F4", 231 | "F5", 232 | "F6", 233 | "F7", 234 | "F8", 235 | "F9", 236 | "F10", 237 | "F11", 238 | "F12", 239 | ] 240 | - [ 241 | "º", 242 | "1", 243 | "2", 244 | "3", 245 | "4", 246 | "5", 247 | "6", 248 | "7", 249 | "8", 250 | "9", 251 | "0", 252 | "'", 253 | "¡", 254 | "Backspace", 255 | ] 256 | - ["Tab", "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "`", "+", "\\"] 257 | - [ 258 | "CapsLock", 259 | "A", 260 | "S", 261 | "D", 262 | "F", 263 | "G", 264 | "H", 265 | "J", 266 | "K", 267 | "L", 268 | "Ñ", 269 | "´", 270 | "Enter", 271 | ] 272 | - ["Shift", "Ç", "Z", "X", "C", "V", "B", "N", "M", ",", ".", "-", "Shift"] 273 | - ["Ctrl", "Alt", "Cmd", "Space", "Cmd", "Alt", "Ctrl"] 274 | 275 | DVORAK: 276 | layout: 277 | - [ 278 | "Esc", 279 | "F1", 280 | "F2", 281 | "F3", 282 | "F4", 283 | "F5", 284 | "F6", 285 | "F7", 286 | "F8", 287 | "F9", 288 | "F10", 289 | "F11", 290 | "F12", 291 | ] 292 | - [ 293 | "`", 294 | "1", 295 | "2", 296 | "3", 297 | "4", 298 | "5", 299 | "6", 300 | "7", 301 | "8", 302 | "9", 303 | "0", 304 | "[", 305 | "]", 306 | "Backspace", 307 | ] 308 | - ["Tab", "'", ",", ".", "P", "Y", "F", "G", "C", "R", "L", "/", "=", "\\"] 309 | - [ 310 | "CapsLock", 311 | "A", 312 | "O", 313 | "E", 314 | "U", 315 | "I", 316 | "D", 317 | "H", 318 | "T", 319 | "N", 320 | "S", 321 | "-", 322 | "Enter", 323 | ] 324 | - ["Shift", ";", "Q", "J", "K", "X", "B", "M", "W", "V", "Z", "Shift"] 325 | - [ 326 | "Ctrl", 327 | "Alt", 328 | "Cmd", 329 | "Space", 330 | "Cmd", 331 | "Alt", 332 | "Ctrl", 333 | "Left", 334 | "Up", 335 | "Down", 336 | "Right", 337 | ] 338 | -------------------------------------------------------------------------------- /src/layouts/system_mappings.yaml: -------------------------------------------------------------------------------- 1 | Darwin: 2 | cmd: "⌘" 3 | alt: "⌥" 4 | ctrl: "⌃" 5 | shift: "Shift" 6 | space: "Space" 7 | 8 | Linux: 9 | cmd: "Super" 10 | alt: "Alt" 11 | ctrl: "Ctrl" 12 | shift: "Shift" 13 | space: "Space" 14 | 15 | Windows: 16 | cmd: "Win" 17 | alt: "Alt" 18 | ctrl: "Ctrl" 19 | shift: "Shift" 20 | space: "Space" 21 | -------------------------------------------------------------------------------- /src/logger.py: -------------------------------------------------------------------------------- 1 | import logging 2 | import os 3 | import sys 4 | from logging.handlers import RotatingFileHandler 5 | from typing import Optional 6 | 7 | # Constants with sane defaults 8 | DEFAULT_LOG_FILE = "app.log" 9 | DEFAULT_MAX_BYTES = 10 * 1024 * 1024 # 10MB 10 | DEFAULT_BACKUP_COUNT = 5 11 | DEFAULT_FORMAT = "%(asctime)s - %(name)s - %(levelname)s - %(message)s" 12 | 13 | _logger: Optional[logging.Logger] = None 14 | 15 | def setup_logging( 16 | log_file: str = os.getenv("LOG_FILE", DEFAULT_LOG_FILE), 17 | ) -> logging.Logger: 18 | """ 19 | Configure and return a logger that: 20 | - Prints INFO and above to console 21 | - Writes DEBUG and above to rotating file 22 | """ 23 | global _logger 24 | if _logger is not None: 25 | return _logger 26 | 27 | logger = logging.getLogger("app") 28 | logger.setLevel(logging.DEBUG) # Capture all levels 29 | 30 | # Create formatter 31 | formatter = logging.Formatter(DEFAULT_FORMAT) 32 | 33 | # Remove any existing handlers 34 | logger.handlers.clear() 35 | 36 | # Console handler (stdout) - INFO and above 37 | console_handler = logging.StreamHandler(sys.stdout) 38 | console_handler.setLevel(logging.INFO) 39 | console_handler.setFormatter(formatter) 40 | logger.addHandler(console_handler) 41 | 42 | # File handler - DEBUG and above 43 | try: 44 | file_handler = RotatingFileHandler( 45 | log_file, 46 | maxBytes=DEFAULT_MAX_BYTES, 47 | backupCount=DEFAULT_BACKUP_COUNT, 48 | encoding='utf-8' 49 | ) 50 | file_handler.setLevel(logging.DEBUG) 51 | file_handler.setFormatter(formatter) 52 | logger.addHandler(file_handler) 53 | except PermissionError: 54 | logger.warning(f"Unable to create/access log file: {log_file}") 55 | 56 | # Prevent logging from propagating to the root logger 57 | logger.propagate = False 58 | 59 | _logger = logger 60 | return logger 61 | 62 | def get_logger() -> logging.Logger: 63 | """Get or create a logger instance.""" 64 | global _logger 65 | if _logger is None: 66 | _logger = setup_logging() 67 | return _logger 68 | 69 | -------------------------------------------------------------------------------- /src/template_renderer.py: -------------------------------------------------------------------------------- 1 | from jinja2 import Environment, FileSystemLoader 2 | from logger import get_logger 3 | from pathlib import Path 4 | 5 | logging = get_logger() 6 | 7 | def render_template(template_path, data): 8 | """ 9 | Render a template from the given path with provided data. 10 | """ 11 | try: 12 | # Use the templates directory directly 13 | templates_dir = Path(__file__).parent / "templates" 14 | 15 | env = Environment( 16 | loader=FileSystemLoader(str(templates_dir)) 17 | ) 18 | 19 | template = env.get_template(str(template_path)) 20 | return template.render(**data) 21 | 22 | except FileNotFoundError: 23 | logging.error(f"Error: Template file '{template_path}' not found.") 24 | return None 25 | except Exception as e: 26 | logging.error(f"Error reading template file: {e}") 27 | return None 28 | 29 | -------------------------------------------------------------------------------- /src/templates/base.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | {% block header %}{% endblock %} 7 | 8 | {% block title %}{% endblock %} 9 | 10 | {% block page_styles %}{% endblock %} 11 | 12 | 13 | {% block content %}{% endblock %} 14 | {% block javascript %}{% endblock %} 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/templates/cheatsheets/assets/cheatsheets.css: -------------------------------------------------------------------------------- 1 | /* Catppuccin Latte (Light) Theme */ 2 | :root { 3 | --latte-rosewater: #dc8a78; 4 | --latte-flamingo: #dd7878; 5 | --latte-pink: #ea76cb; 6 | --latte-mauve: #8839ef; 7 | --latte-red: #d20f39; 8 | --latte-maroon: #e64553; 9 | --latte-peach: #fe640b; 10 | --latte-yellow: #df8e1d; 11 | --latte-green: #40a02b; 12 | --latte-teal: #179299; 13 | --latte-sky: #04a5e5; 14 | --latte-sapphire: #209fb5; 15 | --latte-blue: #1e66f5; 16 | --latte-lavender: #7287fd; 17 | --latte-text: #4c4f69; 18 | --latte-subtext1: #5c5f77; 19 | --latte-subtext0: #6c6f85; 20 | --latte-overlay2: #7c7f93; 21 | --latte-overlay1: #8c8fa1; 22 | --latte-overlay0: #9ca0b0; 23 | --latte-surface2: #acb0be; 24 | --latte-surface1: #bcc0cc; 25 | --latte-surface0: #ccd0da; 26 | --latte-base: #eff1f5; 27 | --latte-mantle: #e6e9ef; 28 | --latte-crust: #dce0e8; 29 | } 30 | 31 | /* Catppuccin Mocha (Dark) Theme */ 32 | .dark-mode { 33 | --mocha-rosewater: #f5e0dc; 34 | --mocha-flamingo: #f2cdcd; 35 | --mocha-pink: #f5c2e7; 36 | --mocha-mauve: #cba6f7; 37 | --mocha-red: #f38ba8; 38 | --mocha-maroon: #eba0ac; 39 | --mocha-peach: #fab387; 40 | --mocha-yellow: #f9e2af; 41 | --mocha-green: #a6e3a1; 42 | --mocha-teal: #94e2d5; 43 | --mocha-sky: #89dceb; 44 | --mocha-sapphire: #74c7ec; 45 | --mocha-blue: #89b4fa; 46 | --mocha-lavender: #b4befe; 47 | --mocha-text: #cdd6f4; 48 | --mocha-subtext1: #bac2de; 49 | --mocha-subtext0: #a6adc8; 50 | --mocha-overlay2: #9399b2; 51 | --mocha-overlay1: #7f849c; 52 | --mocha-overlay0: #6c7086; 53 | --mocha-surface2: #585b70; 54 | --mocha-surface1: #45475a; 55 | --mocha-surface0: #313244; 56 | --mocha-base: #1e1e2e; 57 | --mocha-mantle: #181825; 58 | --mocha-crust: #11111b; 59 | } 60 | 61 | body { 62 | font-family: "Iosevka Web", monospace; 63 | line-height: 1.6; 64 | color: var(--latte-text); 65 | max-width: 1400px; 66 | margin: 0 auto; 67 | padding: 0 10px 20px 90px; 68 | background-color: var(--latte-base); 69 | transition: 70 | background-color 0.3s, 71 | color 0.3s; 72 | } 73 | body:not(.dark-mode) { 74 | --text: var(--latte-text); 75 | --subtext1: var(--latte-subtext1); 76 | --subtext0: var(--latte-subtext0); 77 | --overlay2: var(--latte-overlay2); 78 | --overlay1: var(--latte-overlay1); 79 | --overlay0: var(--latte-overlay0); 80 | --surface2: var(--latte-surface2); 81 | --surface1: var(--latte-surface1); 82 | --surface0: var(--latte-surface0); 83 | --base: var(--latte-base); 84 | --mantle: var(--latte-mantle); 85 | --crust: var(--latte-crust); 86 | } 87 | #content-wrapper { 88 | transition: padding-left 0.3s ease; 89 | padding-left: 0; 90 | } 91 | body.nav-active #content-wrapper { 92 | padding-left: 200px; 93 | } 94 | body.dark-mode { 95 | background-color: var(--mocha-base); 96 | color: var(--mocha-text); 97 | } 98 | h1 { 99 | color: var(--latte-mauve); 100 | text-align: center; 101 | margin-bottom: 10px; 102 | font-weight: 700; 103 | font-size: 2.2rem; 104 | position: absolute; 105 | left: 50%; 106 | right: 0; 107 | margin: 0; 108 | white-space: nowrap; 109 | overflow: hidden; 110 | text-overflow: ellipsis; 111 | width: 100vw; 112 | padding: 0; 113 | transform: translateX(-50%); 114 | } 115 | 116 | body.dark-mode h1 { 117 | color: var(--mocha-mauve); 118 | } 119 | .section { 120 | background-color: var(--mantle); 121 | border-radius: 6px; 122 | padding: 8px; 123 | margin-bottom: 15px; 124 | box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); 125 | transition: 126 | background-color 0.3s, 127 | color 0.3s, 128 | box-shadow 0.3s; 129 | } 130 | body.dark-mode .section { 131 | background-color: var(--mocha-surface0); 132 | box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3); 133 | } 134 | .section h2 { 135 | color: var(--latte-lavender); 136 | border-bottom: 1px solid var(--latte-lavender); 137 | padding-bottom: 5px; 138 | margin-top: 0; 139 | margin-bottom: 10px; 140 | font-weight: 600; 141 | font-size: 1.3rem; 142 | } 143 | body.dark-mode .section h2 { 144 | color: var(--mocha-lavender); 145 | border-bottom-color: var(--mocha-lavender); 146 | } 147 | .shortcuts-container { 148 | display: grid; 149 | grid-template-columns: repeat(4, 1fr); 150 | gap: 12px; 151 | } 152 | @media (max-width: 1200px) { 153 | .shortcuts-container { 154 | grid-template-columns: repeat(3, 1fr); 155 | } 156 | } 157 | @media (max-width: 900px) { 158 | .shortcuts-container { 159 | grid-template-columns: repeat(2, 1fr); 160 | } 161 | } 162 | @media (max-width: 600px) { 163 | .shortcuts-container { 164 | grid-template-columns: 1fr; 165 | } 166 | } 167 | .shortcut { 168 | background-color: var(--crust); 169 | border-radius: 5px; 170 | cursor: pointer; 171 | transition: 172 | background-color 0.3s, 173 | transform 0.2s, 174 | box-shadow 0.2s; 175 | box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); 176 | display: flex; 177 | justify-content: space-between; 178 | align-items: center; 179 | min-height: 40px; 180 | overflow: hidden; 181 | } 182 | body.dark-mode .shortcut { 183 | background-color: var(--mocha-surface1); 184 | box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3); 185 | } 186 | .shortcut:hover { 187 | background-color: var(--surface1); 188 | transform: translateY(-2px); 189 | box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15); 190 | } 191 | body.dark-mode .shortcut:hover { 192 | background-color: var(--mocha-surface2); 193 | box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4); 194 | } 195 | .shortcut:active { 196 | transform: translateY(0); 197 | } 198 | .shortcut-key { 199 | font-weight: 600; 200 | font-size: 0.95rem; 201 | color: var(--latte-mauve); 202 | font-family: "Iosevka Web", monospace; 203 | transition: 204 | color 0.3s, 205 | font-size 0.3s; 206 | flex: 1 1 50%; 207 | word-wrap: break-word; 208 | overflow-wrap: break-word; 209 | display: flex; 210 | align-items: center; 211 | height: 100%; 212 | } 213 | 214 | .text-shortcut { 215 | font-size: 0.95rem; 216 | color: var(--latte-text); 217 | } 218 | 219 | body.dark-mode .text-shortcut { 220 | color: var(--mocha-text); 221 | } 222 | body.dark-mode .shortcut-key { 223 | color: var(--mocha-red); 224 | } 225 | 226 | .shortcut-key .key-part { 227 | color: var(--latte-mauve); 228 | } 229 | 230 | body.dark-mode .shortcut-key .key-part { 231 | color: var(--mocha-red); 232 | } 233 | 234 | .shortcut-key .separator { 235 | color: var(--latte-subtext0); 236 | font-weight: normal; 237 | margin-right: 0.3em; 238 | margin-left: 0.3em; 239 | } 240 | 241 | body.dark-mode .shortcut-key .separator { 242 | color: var(--mocha-subtext0); 243 | } 244 | 245 | .shortcut-key .modifier-symbol { 246 | font-size: 1.5em; 247 | display: inline-block; 248 | vertical-align: middle; 249 | } 250 | 251 | .shortcut-key span:has(> span.modifier-symbol) { 252 | line-height: 1; 253 | } 254 | 255 | .shortcut-description { 256 | font-size: 0.85rem; 257 | text-align: right; 258 | flex: 1 1 50%; 259 | word-wrap: break-word; 260 | overflow-wrap: break-word; 261 | transition: font-size 0.3s; 262 | display: flex; 263 | align-items: center; 264 | justify-content: flex-end; 265 | height: 100%; 266 | } 267 | @media (max-width: 600px) { 268 | .shortcuts-container { 269 | grid-template-columns: 1fr; 270 | } 271 | } 272 | 273 | /* Keyboard styles */ 274 | #keyboard-container { 275 | display: flex; 276 | justify-content: center; 277 | margin-bottom: 25px; 278 | } 279 | #keyboard { 280 | width: 100%; 281 | max-width: 1000px; 282 | margin: 0 auto; 283 | border-radius: 10px; 284 | background: var(--crust); 285 | padding: 5px; 286 | transition: 287 | background-color 0.3s, 288 | box-shadow 0.3s; 289 | box-shadow: 0 6px 12px rgba(0, 0, 0, 0.1); 290 | } 291 | body.dark-mode #keyboard { 292 | background: var(--mocha-crust); 293 | box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3); 294 | } 295 | .row { 296 | display: flex; 297 | justify-content: space-between; 298 | margin-bottom: 5px; 299 | } 300 | .key { 301 | width: 50px; 302 | height: 50px; 303 | background: var(--crust); 304 | border: 1px solid var(--overlay0); 305 | border-radius: 4px; 306 | display: flex; 307 | justify-content: center; 308 | align-items: center; 309 | font-size: 14px; 310 | transition: 311 | all 0.2s, 312 | background-color 0.3s, 313 | color 0.3s, 314 | border-color 0.3s, 315 | box-shadow 0.3s; 316 | color: var(--text); 317 | box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); 318 | cursor: pointer; 319 | flex-grow: 1; 320 | margin-right: 4px; 321 | } 322 | .key:last-child { 323 | margin-right: 0; 324 | } 325 | body.dark-mode .key { 326 | background: var(--mocha-surface0); 327 | color: var(--mocha-text); 328 | border-color: var(--mocha-overlay0); 329 | box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3); 330 | } 331 | .key.active { 332 | background: var(--latte-green); 333 | color: var(--latte-base); 334 | box-shadow: 0 0 8px var(--latte-green); 335 | } 336 | body.dark-mode .key.active { 337 | background: var(--mocha-green); 338 | color: var(--mocha-base); 339 | box-shadow: 0 0 8px var(--mocha-green); 340 | } 341 | .key__wide { 342 | width: 75px; 343 | } 344 | .key__wider { 345 | width: 90px; 346 | } 347 | .key__widest { 348 | width: 110px; 349 | } 350 | .key__spacebar { 351 | width: 300px; 352 | } 353 | .key__enter { 354 | width: 112px; 355 | } 356 | .key__shift-left { 357 | width: 100px; 358 | } 359 | .key__backspace { 360 | width: 100px; 361 | } 362 | .key__tab { 363 | width: 75px; 364 | } 365 | .key__caps { 366 | width: 90px; 367 | } 368 | .key__right-shift { 369 | width: 125px; 370 | } 371 | .key__bottom-funct { 372 | width: 70px; 373 | } 374 | .key__arrow { 375 | width: 40px; 376 | font-size: 18px; 377 | } 378 | .key-stack { 379 | display: flex; 380 | flex-direction: column; 381 | width: 40px; 382 | } 383 | .key__arrow-half { 384 | height: 25px; 385 | font-size: 14px; 386 | } 387 | .wide { 388 | width: 65px; 389 | } 390 | .wider { 391 | width: 85px; 392 | } 393 | .widest { 394 | width: 110px; 395 | } 396 | 397 | .layout-info { 398 | text-align: center; 399 | margin-bottom: 20px; 400 | font-size: 1.1rem; 401 | color: var(--latte-subtext1); 402 | } 403 | body.dark-mode .layout-info { 404 | color: var(--mocha-subtext1); 405 | } 406 | 407 | .top-content { 408 | display: flex; 409 | justify-content: space-between; 410 | align-items: center; 411 | padding: 10px 10px; 412 | margin-bottom: 5px; 413 | width: 100%; 414 | position: relative; 415 | box-sizing: border-box; 416 | z-index: 1000; 417 | } 418 | 419 | .search-container { 420 | flex: 0 1 200px; 421 | margin: 0 20px; 422 | transition: margin-left 0.3s ease; 423 | } 424 | 425 | body.nav-active .search-container { 426 | margin-left: 220px; 427 | } 428 | 429 | #shortcut-search { 430 | width: 100%; 431 | padding: 10px; 432 | font-size: 16px; 433 | border: 2px solid var(--latte-surface2); 434 | border-radius: 5px; 435 | background-color: var(--latte-base); 436 | color: var(--latte-text); 437 | transition: 438 | border-color 0.3s, 439 | background-color 0.3s, 440 | color 0.3s, 441 | box-shadow 0.3s, 442 | width 0.3s ease; 443 | box-sizing: border-box; 444 | position: relative; 445 | z-index: 1001; 446 | } 447 | 448 | body.nav-active #shortcut-search { 449 | width: calc(100% - 200px); 450 | } 451 | 452 | body.dark-mode #shortcut-search { 453 | border-color: var(--mocha-surface2); 454 | background-color: var(--mocha-base); 455 | color: var(--mocha-text); 456 | } 457 | 458 | #shortcut-search:focus { 459 | outline: none; 460 | border-color: var(--latte-lavender); 461 | box-shadow: 0 0 5px var(--latte-lavender); 462 | } 463 | 464 | body.dark-mode #shortcut-search:focus { 465 | border-color: var(--mocha-lavender); 466 | box-shadow: 0 0 5px var(--mocha-lavender); 467 | } 468 | 469 | #content-wrapper { 470 | padding-top: 10px; 471 | max-width: 1200px; 472 | margin-left: auto; 473 | margin-right: auto; 474 | transition: padding-left 0.3s ease; 475 | } 476 | 477 | body.nav-active #content-wrapper { 478 | padding-left: 200px; 479 | } 480 | 481 | #dark-mode-toggle { 482 | flex: 0 0 auto; 483 | position: relative; 484 | z-index: 1002; 485 | background: none; 486 | border: none; 487 | cursor: pointer; 488 | font-size: 24px; 489 | color: var(--text); 490 | transition: color 0.3s; 491 | } 492 | 493 | body.dark-mode #dark-mode-toggle { 494 | color: var(--mocha-text); 495 | } 496 | 497 | #category-nav-toggle { 498 | flex: 0 0 auto; 499 | } 500 | #category-nav-toggle { 501 | position: fixed; 502 | top: 20px; 503 | left: 10px; 504 | z-index: 1000; 505 | background: var(--latte-surface1); 506 | border: none; 507 | border-radius: 50%; 508 | width: 40px; 509 | height: 40px; 510 | cursor: pointer; 511 | display: flex; 512 | align-items: center; 513 | justify-content: center; 514 | box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); 515 | transition: 516 | background-color 0.3s, 517 | transform 0.2s, 518 | left 0.3s; 519 | } 520 | body.dark-mode #category-nav-toggle { 521 | background: var(--mocha-surface1); 522 | } 523 | #category-nav-toggle:hover { 524 | transform: scale(1.1); 525 | } 526 | #category-nav-toggle svg { 527 | transition: transform 0.3s; 528 | } 529 | #category-nav-toggle.active svg { 530 | transform: rotate(90deg); 531 | } 532 | #category-nav-toggle.active { 533 | left: 270px; 534 | } 535 | #category-nav { 536 | position: fixed; 537 | top: 0; 538 | left: -200px; 539 | width: 200px; 540 | height: 100vh; 541 | background: var(--surface0); 542 | overflow-y: auto; 543 | transition: left 0.3s ease; 544 | z-index: 998; 545 | padding: 70px 15px 20px; 546 | box-shadow: 2px 0 5px rgba(0, 0, 0, 0.1); 547 | } 548 | #category-nav.active { 549 | left: 0; 550 | } 551 | body.dark-mode #category-nav { 552 | background: var(--mocha-surface0); 553 | box-shadow: 2px 0 5px rgba(0, 0, 0, 0.3); 554 | } 555 | #category-nav ul { 556 | display: none; 557 | } 558 | #category-nav.active ul { 559 | display: block; 560 | } 561 | body.dark-mode #category-nav { 562 | background: var(--mocha-surface0); 563 | } 564 | #category-nav.active { 565 | left: 0; 566 | } 567 | #category-nav-toggle { 568 | z-index: 999; 569 | } 570 | #category-nav ul { 571 | list-style-type: none; 572 | padding: 0; 573 | margin: 0; 574 | } 575 | #category-nav li { 576 | margin-bottom: 10px; 577 | } 578 | #category-nav a { 579 | color: var(--latte-text); 580 | text-decoration: none; 581 | font-size: 1rem; 582 | transition: color 0.2s; 583 | } 584 | body.dark-mode #category-nav a { 585 | color: var(--mocha-text); 586 | } 587 | #category-nav a:hover { 588 | color: var(--latte-lavender); 589 | } 590 | body.dark-mode #category-nav a:hover { 591 | color: var(--mocha-lavender); 592 | } 593 | -------------------------------------------------------------------------------- /src/templates/cheatsheets/cheatsheet-template.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} 2 | 3 | {% block title %}{{ title }} Cheatsheet{% endblock %} 4 | 5 | {% block page_styles %} 6 | 9 | {% endblock %} 10 | 11 | {% block header %} 12 | 13 | {% include 'cheatsheets/components/header.html' %} 14 | {% endblock %} 15 | 16 | {% block content %} 17 | {% include 'cheatsheets/components/body.html' %} 18 | {% endblock %} 19 | 20 | {% block javascript %} 21 | 24 | {% endblock %} 25 | -------------------------------------------------------------------------------- /src/templates/cheatsheets/components/body.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | 18 |

{{ title }}

19 |
20 | 21 |
22 | 27 |
28 | 37 |
38 | {% if render_keys %} 39 |

Keyboard Layout: {{ layout.keyboard }} | System: {{ layout.system }}

40 | 41 |
42 |
45 | 46 |
47 |
Esc
48 |
F1
49 |
F2
50 |
F3
51 |
F4
52 |
F5
53 |
F6
54 |
F7
55 |
F8
56 |
F9
57 |
F10
58 |
F11
59 |
F12
60 |
61 |
62 |
` ~
63 |
1 !
64 |
2 @
65 |
3 #
66 |
4 $
67 |
5 %
68 |
6 ^
69 |
7 &
70 |
8 *
71 |
9 (
72 |
0 )
73 |
- _
74 |
=+
75 |
Backspace
76 |
77 |
78 |
Tab
79 |
Q
80 |
W
81 |
E
82 |
R
83 |
T
84 |
Y
85 |
U
86 |
I
87 |
O
88 |
P
89 |
[{
90 |
]}
91 |
\|
92 |
93 |
94 |
Caps Lock
95 |
A
96 |
S
97 |
D
98 |
F
99 |
G
100 |
H
101 |
J
102 |
K
103 |
L
104 |
; :
105 |
' "
106 |
Enter
107 |
108 |
109 |
Shift
110 |
Z
111 |
X
112 |
C
113 |
V
114 |
B
115 |
N
116 |
M
117 |
<, >
118 |
. >
119 |
/ ?
120 |
Shift
121 |
122 |
123 |
CTRL
124 |
ALT
125 |
CMD
126 |
SPACE
127 |
CMD
128 |
ALT
129 |
CTRL
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 | {% endif %} 138 | {% for section, shortcuts in shortcuts.items() %} 139 |
140 |

{{ section }}

141 |
142 | {% for shortcut, details in shortcuts.items() %} 143 |
145 |
146 | {% if allow_text %} 147 | {{ shortcut }} 148 | {% else %} 149 | {% for key in shortcut.split('') %} 150 | {{ key | safe }} 151 | {% if not loop.last %}+{% endif %} 152 | {% endfor %} 153 | {% endif %} 154 |
155 |
{{ details.description }}
156 |
157 | {% endfor %} 158 |
159 |
160 | {% endfor %} 161 |
162 | -------------------------------------------------------------------------------- /src/templates/cheatsheets/components/header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | {{ title }} Cheatsheet 7 | 9 | -------------------------------------------------------------------------------- /src/templates/cheatsheets/scripts/main.js: -------------------------------------------------------------------------------- 1 | // Key label mappings 2 | const keyLabelMappings = { 3 | Darwin: { 4 | Cmd: "⌘", 5 | Alt: "⌥", 6 | Ctrl: "⌃", 7 | Shift: "Shift", 8 | CapsLock: "Caps", 9 | Tab: "Tab", 10 | Enter: "↩", 11 | Backspace: "⌫", 12 | Space: "", 13 | Esc: "Esc", 14 | "Left": "←", 15 | "Down": "↓", 16 | "Up": "↑", 17 | "Right": "→", 18 | }, 19 | Windows: { 20 | Cmd: "Win", 21 | Alt: "Alt", 22 | Ctrl: "Ctrl", 23 | Shift: "Shift", 24 | CapsLock: "Caps", 25 | Tab: "Tab", 26 | Enter: "Enter", 27 | Backspace: "Backspace", 28 | Space: "Space", 29 | Esc: "Esc", 30 | "←": "←", 31 | "↓": "↓", 32 | "↑": "↑", 33 | "→": "→", 34 | }, 35 | Linux: { 36 | Cmd: "Super", 37 | Alt: "Alt", 38 | Ctrl: "Ctrl", 39 | Shift: "Shift", 40 | CapsLock: "Caps", 41 | Tab: "Tab", 42 | Enter: "Enter", 43 | Backspace: "Backspace", 44 | Space: "Space", 45 | Esc: "Esc", 46 | "←": "←", 47 | "↓": "↓", 48 | "↑": "↑", 49 | "→": "→", 50 | }, 51 | }; 52 | 53 | function getKeyLabel(key, system) { 54 | return keyLabelMappings[system][key] || key; 55 | } 56 | 57 | function wrapModifierSymbols(text) { 58 | // Define the symbols we want to make larger 59 | const modifierSymbols = ['⌘', '⌥', '⌃', '⇧']; 60 | 61 | // Replace each modifier symbol with a wrapped version 62 | modifierSymbols.forEach(symbol => { 63 | text = text.replace( 64 | new RegExp(symbol, 'g'), 65 | `${symbol}` 66 | ); 67 | }); 68 | 69 | return text; 70 | } 71 | function generateKeyboard() { 72 | const keyboard = document.getElementById("keyboard"); 73 | const layout = keyboard.getAttribute("data-layout"); 74 | const system = keyboard.getAttribute("data-system"); 75 | const keyboardLayout = {{ keyboard_layout | tojson | safe }}; 76 | 77 | keyboard.innerHTML = ""; 78 | 79 | keyboardLayout.forEach((row) => { 80 | const rowDiv = document.createElement("div"); 81 | rowDiv.className = "row"; 82 | 83 | row.forEach((key) => { 84 | if (key === "↑↓") { 85 | const stackDiv = document.createElement("div"); 86 | stackDiv.className = "key-stack"; 87 | 88 | const upKeyDiv = document.createElement("div"); 89 | upKeyDiv.className = "key key__arrow key__arrow-half"; 90 | upKeyDiv.setAttribute("data-key", "↑"); 91 | upKeyDiv.textContent = getKeyLabel("↑", system); 92 | 93 | const downKeyDiv = document.createElement("div"); 94 | downKeyDiv.className = "key key__arrow key__arrow-half"; 95 | downKeyDiv.setAttribute("data-key", "↓"); 96 | downKeyDiv.textContent = getKeyLabel("↓", system); 97 | 98 | stackDiv.appendChild(upKeyDiv); 99 | stackDiv.appendChild(downKeyDiv); 100 | rowDiv.appendChild(stackDiv); 101 | } else { 102 | const keyDiv = document.createElement("div"); 103 | keyDiv.className = "key"; 104 | keyDiv.setAttribute("data-key", key); 105 | keyDiv.textContent = getKeyLabel(key, system); 106 | 107 | // Add specific classes for special keys 108 | if (["Backspace", "Tab", "CapsLock", "Enter", "Shift"].includes(key)) { 109 | keyDiv.classList.add(`key__${key.toLowerCase()}`); 110 | } else if (key === "Space") { 111 | keyDiv.classList.add("key__spacebar"); 112 | } else if (["←", "→"].includes(key)) { 113 | keyDiv.classList.add("key__arrow"); 114 | } 115 | 116 | rowDiv.appendChild(keyDiv); 117 | } 118 | }); 119 | 120 | keyboard.appendChild(rowDiv); 121 | }); 122 | } 123 | 124 | // Call generateKeyboard on page load 125 | document.addEventListener("DOMContentLoaded", generateKeyboard); 126 | 127 | // Dark-Mode toggle functionality 128 | const darkModeToggle = document.getElementById('dark-mode-toggle'); 129 | const themeIcon = document.getElementById("theme-icon"); 130 | const body = document.body; 131 | 132 | function updateDarkModeToggle() { 133 | themeIcon.textContent = body.classList.contains("dark-mode") 134 | ? "☀️" 135 | : "🌙"; 136 | } 137 | 138 | darkModeToggle.addEventListener("click", () => { 139 | body.classList.toggle("dark-mode"); 140 | localStorage.setItem("darkMode", body.classList.contains("dark-mode")); 141 | updateDarkModeToggle(); 142 | adjustLayout(); 143 | }); 144 | 145 | function scrollToSection(targetId) { 146 | const targetElement = document.getElementById(targetId); 147 | if (targetElement) { 148 | const headerOffset = 60; // Adjust this value based on your header height 149 | const elementPosition = targetElement.getBoundingClientRect().top; 150 | const offsetPosition = 151 | elementPosition + window.pageYOffset - headerOffset; 152 | 153 | window.scrollTo({ 154 | top: offsetPosition, 155 | behavior: "smooth", 156 | }); 157 | } 158 | } 159 | 160 | // Check for saved dark mode preference, default to dark mode 161 | if (localStorage.getItem("darkMode") === null) { 162 | localStorage.setItem("darkMode", "true"); 163 | } 164 | 165 | if (localStorage.getItem("darkMode") === "true") { 166 | body.classList.add("dark-mode"); 167 | } else { 168 | body.classList.remove("dark-mode"); 169 | } 170 | 171 | updateDarkModeToggle(); 172 | adjustLayout(); 173 | 174 | function highlightKeys(shortcut) { 175 | // Clear any previously highlighted keys 176 | document.querySelectorAll(".key").forEach((key) => key.classList.remove("active")); 177 | 178 | // Get the shortcut key parts 179 | const shortcutParts = shortcut.split('+').map(part => part.trim()); 180 | const system = document.getElementById("keyboard").getAttribute("data-system"); 181 | 182 | shortcutParts.forEach((keyToFind) => { 183 | keyToFind = keyToFind.toLowerCase(); 184 | const keyElements = document.querySelectorAll(".key"); 185 | 186 | keyElements.forEach((element) => { 187 | const dataKey = element.getAttribute("data-key").toLowerCase(); 188 | const keyLabel = element.textContent.toLowerCase(); 189 | 190 | if ( 191 | dataKey === keyToFind || 192 | keyLabel === keyToFind || 193 | (keyToFind === "cmd" && (dataKey === "cmd" || dataKey === "win" || dataKey === "super")) 194 | ) { 195 | element.classList.add("active"); 196 | } 197 | }); 198 | }); 199 | } 200 | 201 | document.querySelectorAll(".shortcut").forEach((shortcut) => { 202 | {% if not allow_text %} 203 | shortcut.addEventListener("click", function() { 204 | // Get the text content and replace with + 205 | const shortcutKey = this.querySelector(".shortcut-key").textContent.replace(/\s*\+\s*/g, '+'); 206 | highlightKeys(shortcutKey); 207 | }); 208 | {% endif %} 209 | }); 210 | 211 | // Keep original case for key data-attributes 212 | document.querySelectorAll(".key").forEach((key) => { 213 | const dataKey = key.getAttribute("data-key"); 214 | key.setAttribute("data-key", dataKey); 215 | }); 216 | 217 | // Category navigation 218 | const categoryNavToggle = document.getElementById("category-nav-toggle"); 219 | const categoryNav = document.getElementById("category-nav"); 220 | 221 | function toggleCategoryNav() { 222 | categoryNavToggle.classList.toggle("active"); 223 | categoryNav.classList.toggle("active"); 224 | document.body.classList.toggle("nav-active"); 225 | adjustLayout(); 226 | adjustSearchContainer(); 227 | } 228 | 229 | function adjustLayout() { 230 | const isNavActive = document.body.classList.contains("nav-active"); 231 | const shortcutKeys = document.querySelectorAll(".shortcut-key"); 232 | const shortcutDescriptions = document.querySelectorAll(".shortcut-description"); 233 | const shortcuts = document.querySelectorAll(".shortcut"); 234 | 235 | shortcuts.forEach((shortcut) => { 236 | shortcut.style.flexDirection = "row"; 237 | shortcut.style.alignItems = "flex-start"; 238 | shortcut.style.minHeight = "40px"; 239 | shortcut.style.height = "auto"; 240 | shortcut.style.padding = "8px"; 241 | }); 242 | 243 | shortcutKeys.forEach((key) => { 244 | key.style.fontSize = isNavActive ? "0.85rem" : "0.95rem"; 245 | key.style.marginRight = "8px"; 246 | key.style.marginBottom = "0"; 247 | key.style.width = isNavActive ? "40%" : "50%"; 248 | key.style.wordWrap = "break-word"; 249 | key.style.overflowWrap = "break-word"; 250 | }); 251 | 252 | shortcutDescriptions.forEach((desc) => { 253 | desc.style.fontSize = isNavActive ? "0.75rem" : "0.85rem"; 254 | desc.style.textAlign = "right"; 255 | desc.style.width = isNavActive ? "60%" : "50%"; 256 | desc.style.wordWrap = "break-word"; 257 | desc.style.overflowWrap = "break-word"; 258 | }); 259 | } 260 | 261 | function adjustSearchContainer() { 262 | const searchContainer = document.querySelector(".search-container"); 263 | const isNavActive = document.body.classList.contains("nav-active"); 264 | searchContainer.style.marginLeft = isNavActive ? "220px" : "20px"; 265 | document.getElementById("shortcut-search").style.width = isNavActive 266 | ? "calc(100% - 200px)" 267 | : "100%"; 268 | } 269 | 270 | categoryNavToggle.addEventListener("click", (e) => { 271 | e.stopPropagation(); 272 | toggleCategoryNav(); 273 | }); 274 | 275 | document.querySelectorAll("#category-nav a").forEach((link) => { 276 | link.addEventListener("click", (e) => { 277 | e.preventDefault(); 278 | const targetId = link.getAttribute("href").slice(1); 279 | scrollToSection(targetId); 280 | toggleCategoryNav(); 281 | }); 282 | }); 283 | 284 | // Close category nav when clicking outside 285 | document.addEventListener("click", (e) => { 286 | if ( 287 | !categoryNav.contains(e.target) && 288 | e.target !== categoryNavToggle && 289 | categoryNav.classList.contains("active") 290 | ) { 291 | toggleCategoryNav(); 292 | } 293 | }); 294 | 295 | // Prevent clicks inside the nav from closing it 296 | categoryNav.addEventListener("click", (e) => { 297 | e.stopPropagation(); 298 | }); 299 | 300 | // Initial category navigation update 301 | updateCategoryNavigation(); 302 | 303 | // Search functionality 304 | const searchInput = document.getElementById("shortcut-search"); 305 | const shortcuts = document.querySelectorAll(".shortcut"); 306 | 307 | searchInput.addEventListener("input", function () { 308 | const searchTerm = this.value.toLowerCase(); 309 | const sections = document.querySelectorAll(".section"); 310 | 311 | sections.forEach((section) => { 312 | const shortcuts = section.querySelectorAll(".shortcut"); 313 | let hasVisibleShortcuts = false; 314 | 315 | shortcuts.forEach((shortcut) => { 316 | const description = shortcut 317 | .querySelector(".shortcut-description") 318 | .textContent.toLowerCase(); 319 | const key = shortcut 320 | .querySelector(".shortcut-key") 321 | .textContent.toLowerCase(); 322 | if (description.includes(searchTerm) || key.includes(searchTerm)) { 323 | shortcut.style.display = ""; 324 | hasVisibleShortcuts = true; 325 | } else { 326 | shortcut.style.display = "none"; 327 | } 328 | }); 329 | 330 | section.style.display = hasVisibleShortcuts ? "" : "none"; 331 | }); 332 | 333 | // Update category navigation 334 | updateCategoryNavigation(); 335 | }); 336 | 337 | function updateCategoryNavigation() { 338 | const categoryLinks = document.querySelectorAll("#category-nav a"); 339 | categoryLinks.forEach((link) => { 340 | const targetId = link.getAttribute("href").slice(1); 341 | const targetSection = document.getElementById(targetId); 342 | if (targetSection) { 343 | link.style.display = targetSection.style.display; 344 | } 345 | }); 346 | } 347 | -------------------------------------------------------------------------------- /src/templates/index_template.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 11 | Cheatsheet Index 12 | 16 | 413 | 414 | 415 |
416 | 421 |

Cheatsheet Index

422 | 425 |
426 |
427 | 430 | 434 | 441 |
442 |
    443 | 446 | 450 | 451 | 571 | 572 | 597 | 598 | -------------------------------------------------------------------------------- /src/validate_yaml.py: -------------------------------------------------------------------------------- 1 | from ruamel.yaml import YAML 2 | from ruamel.yaml.error import YAMLError 3 | import re 4 | from logger import get_logger 5 | 6 | logger = get_logger() 7 | 8 | # Create YAML instances once 9 | yaml_safe = YAML(typ='safe') 10 | yaml_rw = YAML() 11 | yaml_rw.indent(mapping=2, sequence=4, offset=2) 12 | yaml_rw.preserve_quotes = True 13 | yaml_rw.width = 100 14 | 15 | def validate_required_keys(data): 16 | """Validate presence of required top-level keys.""" 17 | required_keys = ['title', 'shortcuts'] 18 | for key in required_keys: 19 | if key not in data: 20 | logger.error(f"Missing required top-level key: '{key}'") 21 | return False 22 | return True 23 | 24 | def validate_title(data): 25 | """Validate title field.""" 26 | if 'title' in data and not isinstance(data['title'], str): 27 | logger.error("Title must be a string") 28 | return False 29 | return True 30 | 31 | def validate_render_options(data): 32 | """Validate RenderKeys and AllowText options.""" 33 | is_valid = True 34 | render_keys = data.get('RenderKeys', True) 35 | allow_text = data.get('AllowText', False) 36 | 37 | if 'RenderKeys' in data and not isinstance(render_keys, bool): 38 | logger.error("RenderKeys must be a boolean value (true/false)") 39 | is_valid = False 40 | 41 | if 'AllowText' in data and not isinstance(allow_text, bool): 42 | logger.error("AllowText must be a boolean value (true/false)") 43 | is_valid = False 44 | 45 | if allow_text and render_keys: 46 | logger.error("AllowText can only be true when RenderKeys is false") 47 | is_valid = False 48 | 49 | return is_valid 50 | 51 | def validate_layout(data): 52 | """Validate keyboard layout configuration.""" 53 | if 'layout' not in data: 54 | return True 55 | 56 | if not isinstance(data['layout'], dict): 57 | logger.error("Layout must be a dictionary") 58 | return False 59 | 60 | valid_keyboards = ['US', 'UK', 'DE', 'FR', 'ES'] 61 | valid_systems = ['Darwin', 'Linux', 'Windows'] 62 | is_valid = True 63 | 64 | if 'keyboard' in data['layout'] and data['layout']['keyboard'] not in valid_keyboards: 65 | logger.error(f"Invalid keyboard layout. Must be one of: {', '.join(valid_keyboards)}") 66 | is_valid = False 67 | 68 | if 'system' in data['layout'] and data['layout']['system'] not in valid_systems: 69 | logger.error(f"Invalid system. Must be one of: {', '.join(valid_systems)}") 70 | is_valid = False 71 | 72 | return is_valid 73 | 74 | def validate_shortcuts(data): 75 | """Validate shortcuts structure and content.""" 76 | if 'shortcuts' not in data: 77 | return True 78 | 79 | if not isinstance(data['shortcuts'], dict): 80 | logger.error("Shortcuts must be a dictionary") 81 | return False 82 | 83 | allow_text = data.get('AllowText', False) 84 | is_valid = True 85 | 86 | for category, shortcuts in data['shortcuts'].items(): 87 | if not isinstance(shortcuts, dict): 88 | logger.error(f"Category '{category}' must contain a dictionary of shortcuts") 89 | is_valid = False 90 | continue 91 | 92 | for shortcut, details in shortcuts.items(): 93 | if not isinstance(details, dict) or 'description' not in details: 94 | logger.error(f"Shortcut '{shortcut}' in category '{category}' must have a 'description' key") 95 | is_valid = False 96 | elif not isinstance(details['description'], str): 97 | logger.error(f"Description for shortcut '{shortcut}' in category '{category}' must be a string") 98 | is_valid = False 99 | 100 | if not allow_text: 101 | if not re.match(r'^[A-Za-z0-9+⌘⌥⌃⇧←→↑↓\s\-\|\[\],.:/`"?<>=\\⌃]+$', shortcut): 102 | logger.error(f"Invalid shortcut format: '{shortcut}' in category '{category}'") 103 | is_valid = False 104 | 105 | return is_valid 106 | 107 | def validate_yaml(file_path): 108 | """Validate YAML file structure and content.""" 109 | try: 110 | with open(file_path, 'r', encoding='utf-8') as file: 111 | data = yaml_safe.load(file) 112 | except YAMLError as e: 113 | logger.error(f"YAML parsing error in {file_path}: {str(e)}") 114 | return False 115 | except FileNotFoundError: 116 | logger.error(f"File not found: {file_path}") 117 | return False 118 | except Exception as e: 119 | logger.error(f"Unexpected error reading {file_path}: {str(e)}") 120 | return False 121 | 122 | if data is None: 123 | logger.error(f"Empty YAML file: {file_path}") 124 | return False 125 | 126 | is_valid = True 127 | 128 | # Perform all validations 129 | if not validate_required_keys(data): 130 | is_valid = False 131 | if not validate_title(data): 132 | is_valid = False 133 | if not validate_render_options(data): 134 | is_valid = False 135 | if not validate_layout(data): 136 | is_valid = False 137 | if not validate_shortcuts(data): 138 | is_valid = False 139 | 140 | if is_valid: 141 | logger.info(f"YAML validation successful: {file_path}") 142 | else: 143 | logger.error(f"YAML validation failed: {file_path}") 144 | 145 | return is_valid 146 | 147 | def lint_yaml(file_path): 148 | warnings = [] 149 | 150 | with open(file_path, 'r', encoding="utf-8") as file: 151 | lines = file.readlines() 152 | 153 | for i, line in enumerate(lines, start=1): 154 | # Check for lines longer than 100 characters 155 | if len(line.rstrip()) > 100: 156 | warnings.append(f"Line {i} is longer than 100 characters") 157 | 158 | # Check for inconsistent indentation 159 | indent = len(line) - len(line.lstrip()) 160 | if indent % 2 != 0: 161 | warnings.append(f"Line {i} has inconsistent indentation") 162 | 163 | # Check for trailing whitespace 164 | if line.rstrip() != line.rstrip('\n'): 165 | warnings.append(f"Line {i} has trailing whitespace") 166 | 167 | return warnings 168 | 169 | def fix_yaml(file_path): 170 | with open(file_path, 'r', encoding="utf-8") as file: 171 | content = file.read() 172 | 173 | fixes = [] 174 | 175 | # Replace special characters and convert to uppercase 176 | special_chars = {'⌘': 'CMD', '⌃': 'CTRL', '⌥': 'ALT', '⇧': 'SHIFT'} 177 | for char, replacement in special_chars.items(): 178 | if char in content: 179 | content = content.replace(char, replacement) 180 | fixes.append(f"Replaced '{char}' with '{replacement}'") 181 | 182 | # Convert lowercase special keys to uppercase 183 | lowercase_keys = ['cmd', 'ctrl', 'alt', 'shift'] 184 | for key in lowercase_keys: 185 | pattern = re.compile(r'\b' + key + r'\b', re.IGNORECASE) 186 | content = pattern.sub(key.upper(), content) 187 | if pattern.search(content): 188 | fixes.append(f"Converted '{key}' to uppercase") 189 | 190 | # Fix indentation 191 | lines = content.split('\n') 192 | fixed_lines = [] 193 | for line in lines: 194 | stripped = line.lstrip() 195 | indent = len(line) - len(stripped) 196 | fixed_indent = (indent // 2) * 2 # Round down to nearest even number 197 | if fixed_indent != indent: 198 | fixes.append(f"Fixed indentation in line: {line.strip()}") 199 | fixed_lines.append(' ' * fixed_indent + stripped.rstrip()) 200 | 201 | fixed_content = '\n'.join(fixed_lines) 202 | 203 | # Write fixed content back to file 204 | with open(file_path, 'w', encoding="utf-8") as file: 205 | file.write(fixed_content) 206 | 207 | return fixes 208 | 209 | def format_yaml(file_path): 210 | yaml = YAML() 211 | yaml.indent(mapping=2, sequence=4, offset=2) 212 | yaml.preserve_quotes = True 213 | yaml.width = 100 214 | 215 | with open(file_path, 'r', encoding='utf-8') as file: 216 | data = yaml.load(file) 217 | 218 | with open(file_path, 'w', encoding='utf-8') as file: 219 | yaml.dump(data, file) 220 | 221 | return "YAML file has been formatted for improved readability." 222 | 223 | def process_yaml(file_path): 224 | print(f"Processing {file_path}...") 225 | 226 | # Validate 227 | errors = validate_yaml(file_path) 228 | if errors: 229 | print("Validation errors:") 230 | for error in errors: 231 | print(f"- {error}") 232 | else: 233 | print("Validation passed.") 234 | 235 | # Lint 236 | warnings = lint_yaml(file_path) 237 | if warnings: 238 | print("Linting warnings:") 239 | for warning in warnings: 240 | print(f"- {warning}") 241 | else: 242 | print("Linting passed.") 243 | 244 | # Fix 245 | fixes = fix_yaml(file_path) 246 | if fixes: 247 | print("Fixes applied:") 248 | for fix in fixes: 249 | print(f"- {fix}") 250 | else: 251 | print("No fixes were necessary.") 252 | 253 | # Format 254 | format_message = format_yaml(file_path) 255 | print(format_message) 256 | 257 | if __name__ == "__main__": 258 | import sys 259 | if len(sys.argv) != 2: 260 | print("Usage: python validate_yaml.py ") 261 | sys.exit(1) 262 | 263 | yaml_file = sys.argv[1] 264 | process_yaml(yaml_file) 265 | -------------------------------------------------------------------------------- /yaml_cheatsheet_spec.md: -------------------------------------------------------------------------------- 1 | # YAML cheat sheet Specification Guide 2 | 3 | ## TLDR 4 | 5 | - Use `.yaml` extension 6 | - Required top-level keys: `title`, `layout`, `shortcuts` 7 | - Optional top-level keys: `RenderKeys`,`AllowText` 8 | - `layout` specifies `keyboard` (US, UK, ...) and `system` (Darwin, Windows, Linux) 9 | - `shortcuts` organized by categories 10 | - Use all caps for key names (CMD, CTRL, SHIFT, ALT) 11 | - Use `+` to combine keys 12 | - For arrow keys, use Up, Down, Left, Right 13 | - Your YAML will be validated, linted, and automatically fixed if possible 14 | 15 | ## File Structure 16 | 17 | Each cheat sheet should be a single YAML file with the `.yaml` extension, located in the `cheatsheets` directory of the project. 18 | 19 | ## Top-Level Keys 20 | 21 | The YAML file must contain the following top-level keys: 22 | 23 | 1. `title`: A string representing the title of the cheat sheet. 24 | 2. `layout`: An object containing keyboard and system information. 25 | 3. `shortcuts`: An object containing categories and their associated shortcuts. 26 | 27 | Optionally, the following keys are also supported: 28 | 29 | 1. `RenderKeys`: `true`/`false` (default: true) 30 | 2. `AllowText`: `true`/`false` (default: false) 31 | 32 | ### Example: 33 | 34 | ```yaml 35 | title: "" 36 | RenderKeys: true # defaults to true 37 | AllowText: false # defaults to false - requires RenderKeys: false 38 | layout: 39 | keyboard: US 40 | system: Darwin 41 | shortcuts: 42 | ``` 43 | 44 | ## Title 45 | 46 | - The `title` should be a descriptive string enclosed in quotes. 47 | 48 | ## Layout 49 | 50 | The `layout` object must contain two keys: 51 | 52 | 1. `keyboard`: Specifies the keyboard layout. 53 | 2. `system`: Specifies the operating system. 54 | 55 | ### Keyboard Layouts 56 | 57 | Valid values for `keyboard` are: 58 | 59 | - `US` (United States) 60 | - `UK` (United Kingdom) 61 | - `DE` (German) 62 | - `FR` (French) 63 | - `ES` (Spanish) 64 | 65 | ### System Types 66 | 67 | Valid values for `system` are: 68 | 69 | - `Darwin` (for macOS) 70 | - `Windows` 71 | - `Linux` 72 | 73 | ## Shortcuts 74 | 75 | The `shortcuts` object contains categories as keys, with each category containing a set of shortcuts. 76 | 77 | ### Categories 78 | 79 | - Use quotation marks for category names containing spaces. 80 | - Use title case for category names. 81 | 82 | ### Shortcuts 83 | 84 | Each shortcut is represented by a key-value pair: 85 | 86 | - The key is the shortcut combination, enclosed in quotes. 87 | - The value is an object with a `description` key. 88 | 89 | #### Shortcut Formatting 90 | 91 | - Use all caps for key names (e.g., `CMD`, `CTRL`, `SHIFT`, `ALT`). 92 | - Use `+` to combine keys in a shortcut. 93 | - For special keys, use their full names: `Space`, `Tab`, `Enter`, `Backspace`, `Delete`, `Esc`. 94 | - For arrow keys, use `Up`, `Down`, `Left`, `Right`. 95 | - For function keys, use `F1`, `F2`, etc. 96 | 97 | #### System-Specific Key Mappings 98 | 99 | - macOS (Darwin): 100 | - `CMD` for Command key (⌘) 101 | - `CTRL` for Control key (⌃) 102 | - `ALT` for Option key (⌥) 103 | - `SHIFT` for Shift key 104 | - Windows: 105 | - `Windows` for Windows key 106 | - `CTRL` for Control key 107 | - `ALT` for Alt key 108 | - `SHIFT` for Shift key 109 | 110 | ### Example: 111 | 112 | ```yaml 113 | shortcuts: 114 | "General": 115 | "CMD+C": 116 | description: "Copy selected item" 117 | "CMD+V": 118 | description: "Paste copied or cut item" 119 | "Text Editing": 120 | "CMD+B": 121 | description: "Bold selected text" 122 | "CMD+Right": 123 | description: "Move cursor to end of current line" 124 | ``` 125 | 126 | ## Validation, Linting, and Fixing 127 | 128 | When you submit your YAML file, it will go through a validation, linting, and fixing process. 129 | 130 | ### Validation 131 | 132 | The system checks for: 133 | 134 | 1. Required top-level keys (`title`, `layout`, `shortcuts`) 135 | 2. Correct data types for each key 136 | 3. Valid values for `keyboard` and `system` in the `layout` section 137 | 4. Proper structure of the `shortcuts` section 138 | 139 | ### Linting 140 | 141 | The linting process checks for: 142 | 143 | 1. Lines longer than 100 characters 144 | 2. Inconsistent indentation (should be multiples of 2 spaces) 145 | 3. Trailing whitespace 146 | 147 | ### Automatic Fixing 148 | 149 | The system will attempt to automatically fix some issues: 150 | 151 | 1. Replacing special characters with their text equivalents (e.g., `⌘` to `CMD`) 152 | 2. Converting lowercase special keys to uppercase (e.g., `cmd` to `CMD`) 153 | 3. Fixing indentation to be consistent (multiples of 2 spaces) 154 | 4. Removing trailing whitespace 155 | 156 | ## Full Example 157 | 158 | Here's a minimal example of a correctly formatted YAML cheatsheet: 159 | 160 | ```yaml 161 | title: "KoalaKeys" 162 | RenderKeys: true # defaults to true 163 | AllowText: false # defaults to false - requires RenderKeys: false 164 | layout: 165 | keyboard: US 166 | system: Darwin 167 | shortcuts: 168 | General: 169 | "CMD+C": 170 | description: "Copy selected item" 171 | "CMD+X": 172 | description: "Cut selected item" 173 | File and App Management: 174 | "CMD+N": 175 | description: "Open new window or document" 176 | "CMD+O": 177 | description: "Open selected item or display dialog to choose file to open" 178 | ``` 179 | --------------------------------------------------------------------------------