├── .stylua.toml ├── LICENSE ├── README.md ├── lua └── typr │ ├── api.lua │ ├── constants │ ├── kblayouts.lua │ ├── phrases.lua │ └── words.lua │ ├── init.lua │ ├── mappings.lua │ ├── state.lua │ ├── stats │ ├── dashboard.lua │ ├── history.lua │ ├── init.lua │ ├── keystrokes.lua │ ├── layout.lua │ └── utils.lua │ ├── ui │ ├── hl.lua │ ├── init.lua │ └── layout.lua │ └── utils.lua └── plugin └── typr.lua /.stylua.toml: -------------------------------------------------------------------------------- 1 | column_width = 120 2 | line_endings = "Unix" 3 | indent_type = "Spaces" 4 | indent_width = 2 5 | quote_style = "AutoPreferDouble" 6 | call_parentheses = "None" 7 | -------------------------------------------------------------------------------- /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 | # Typr 2 | 3 | A Neovim plugin for practice typing with a very beautiful dashboard. 4 | 5 | ![typr](https://github.com/user-attachments/assets/4426d1c4-c4d3-4da7-987a-3b4c4395a4b5) 6 | ![typrstats](https://github.com/user-attachments/assets/b1653de3-05f3-4b90-b35e-9341eed8bf3e) 7 | ![typrstats vertical](https://github.com/user-attachments/assets/1ca824a0-5227-48c4-991c-f793cf62074a) 8 | 9 | # Install 10 | 11 | - Users which used typr before, delete your previous typrstats file. 12 | 13 | ```lua 14 | { 15 | "nvzone/typr", 16 | dependencies = "nvzone/volt", 17 | opts = {}, 18 | cmd = { "Typr", "TyprStats" }, 19 | } 20 | ``` 21 | 22 | - Note: Activity UI is still WIP so dont expect it to work. 23 | 24 | # Config 25 | 26 | https://github.com/nvzone/typr/blob/main/lua/typr/state.lua#L18 27 | 28 | ## Disable completion 29 | 30 | The typr buffer has the filetype set to `typr`. Refer to your completion plugins documentation on 31 | how to disable it for that filetype which you can read using the buffer-scoped option 32 | `vim.bo.filetype`. 33 | 34 | # Mappings 35 | 36 | Whatever buttons you see, the mapping starts from their first letter i.e 37 | 38 | In Typr window 39 | 40 | - s = toggle symbols 41 | - n = toggle numbers 42 | - r = toggle random 43 | - 3 = set 3 lines , and so on! 44 | 45 | In Typrstats vertical window 46 | 47 | - D = dashboard 48 | - H = history 49 | - K = Keystrokes 50 | -------------------------------------------------------------------------------- /lua/typr/api.lua: -------------------------------------------------------------------------------- 1 | local M = {} 2 | local volt = require "volt" 3 | local state = require "typr.state" 4 | local utils = require "typr.utils" 5 | 6 | M.redraw_words_header = function(mode) 7 | state.config.mode = mode or "words" 8 | volt.redraw(state.buf, "headerbtns") 9 | utils.gen_default_lines() 10 | volt.redraw(state.buf, "words") 11 | end 12 | 13 | M.toggle_symbols = function() 14 | state.config.symbols = not state.config.symbols 15 | M.redraw_words_header() 16 | end 17 | 18 | M.toggle_numbers = function() 19 | state.config.numbers = not state.config.numbers 20 | M.redraw_words_header() 21 | end 22 | 23 | M.toggle_random = function() 24 | state.config.random = not state.config.random 25 | M.redraw_words_header() 26 | end 27 | 28 | M.toggle_phrases = function() 29 | state.config.mode = state.config.mode == "phrases" and "words" or "phrases" 30 | 31 | if state.config.mode == "phrases" then 32 | state.config.numbers = false 33 | state.config.symbols = false 34 | state.config.random = false 35 | end 36 | 37 | M.redraw_words_header(state.config.mode) 38 | end 39 | 40 | M.set_linecount = function(x) 41 | local diff = x - state.linecount 42 | state.linecount = x 43 | state.h = state.h + diff 44 | utils.gen_default_lines() 45 | utils.set_emptylines() 46 | vim.api.nvim_win_set_height(state.win, state.h) 47 | 48 | require("typr").initialize_volt() 49 | 50 | volt.redraw(state.buf, "all") 51 | end 52 | 53 | M.restart = function() 54 | if state.stats.rawpm == 0 then 55 | return 56 | end 57 | 58 | state.reset_vars() 59 | 60 | state.h = state.h - 2 61 | vim.api.nvim_win_set_height(state.win, state.h) 62 | utils.set_emptylines() 63 | utils.gen_default_lines() 64 | require("typr").initialize_volt() 65 | volt.redraw(state.buf, "all") 66 | end 67 | 68 | return M 69 | -------------------------------------------------------------------------------- /lua/typr/constants/kblayouts.lua: -------------------------------------------------------------------------------- 1 | return { 2 | qwerty = { 3 | { "q", "w", "e", "r", "t", "y", "u", "i", "o", "p" }, 4 | { "a", "s", "d", "f", "g", "h", "j", "k", "l", ";" }, 5 | { "z", "x", "c", "v", "b", "n", "m", ",", ".", "/" }, 6 | }, 7 | 8 | dvorak = { 9 | { '"', ",", ".", "p", "y", "f", "g", "c", "r", "l" }, 10 | { "a", "o", "e", "u", "i", "d", "h", "t", "n", "s" }, 11 | { ";", "q", "j", "k", "x", "b", "m", "w", "v", "z" }, 12 | }, 13 | 14 | colemak = { 15 | { "q", "w", "f", "p", "g", "j", "l", "u", "y", ";" }, 16 | { "a", "r", "s", "t", "d", "h", "n", "e", "i", "o" }, 17 | { "z", "x", "c", "v", "b", "k", "m", ",", ".", "/" }, 18 | }, 19 | 20 | colemak_dh = { 21 | { "q", "w", "f", "p", "b", "j", "l", "u", "y", ";" }, 22 | { "a", "r", "s", "t", "g", "m", "n", "e", "i", "o" }, 23 | { "z", "x", "c", "d", "v", "k", "h", ",", ".", "/" }, 24 | }, 25 | 26 | azerty = { 27 | { "a", "z", "e", "r", "t", "y", "u", "i", "o", "p" }, 28 | { "q", "s", "d", "f", "g", "h", "j", "k", "l", "m" }, 29 | { "w", "x", "c", "v", "b", "n", ",", ";", ":", "!" }, 30 | }, 31 | } 32 | -------------------------------------------------------------------------------- /lua/typr/constants/phrases.lua: -------------------------------------------------------------------------------- 1 | return { 2 | "On a chilly autumn evening, the sound of leaves rustling in the wind filled the air as the neighborhood prepared for war.", 3 | "After a long and grueling day at work, Jane finally sat down on her favorite armchair, sipping her hot tea while enjoying the warmth of the crackling fireplace.", 4 | "The library was a sanctuary for those seeking knowledge, with its towering shelves filled with books from every genre imaginable and the faint scent of old paper lingering in the air.", 5 | "Under the vast starlit sky, the group of hikers set up their tents and gathered around a campfire, sharing stories and laughter while the wilderness enveloped them.", 6 | "The bustling city was alive with energy as the sound of car horns, chatter, and birds blended together, creating a symphony of urban life that never seemed to sleep.", 7 | "Through the winding mountain paths, a lone traveler carried a heavy backpack filled with essentials, navigating the rugged terrain with determination and grit.", 8 | "As the waves crashed onto the shore, the beach was dotted with children building sandcastles and families enjoying the warm sunlight and cool ocean breeze.", 9 | "The small village nestled in the valley was surrounded by rolling hills covered in a patchwork of green and gold fields, stretching as far as the eye could see.", 10 | "In the depths of the forest, the air was filled with the chirping of birds and the soft rustle of leaves as squirrels darted from tree to tree, gathering food.", 11 | "The old train station stood as a relic of the past, its wooden benches worn smooth by time and its walls echoing with the memories of countless arrivals and departures.", 12 | "The golden rays of the morning sun bathed the landscape in a warm glow as dew glistened on the grass and birds greeted the day with melodic chirping.", 13 | "The massive oak tree in the center of the park provided shade to countless visitors over the years, its roots deeply entwined in the history of the town.", 14 | "The bakery on the corner was famous for its freshly baked bread and pastries, filling the air with an aroma that tempted passersby to stop and indulge.", 15 | "The clear blue waters of the lake reflected the towering mountains surrounding it, creating a picturesque scene that felt like it belonged in a painting.", 16 | "The cobblestone streets of the old town were lined with quaint shops and cafes, bustling with people enjoying the charming atmosphere.", 17 | "The garden was a burst of colors, with vibrant flowers blooming in every shade imaginable, attracting bees and butterflies that danced from petal to petal.", 18 | "The old wooden bridge creaked underfoot as the hiker crossed it carefully, marveling at the serene river flowing gently beneath.", 19 | "The summer fair was a lively celebration, with rides, games, and food stalls scattered across the field, drawing families from neighboring towns.", 20 | "The quiet beach at sunset was a perfect place for reflection, as the waves gently lapped at the shore and the sky turned shades of orange and pink.", 21 | "The mountain cabin was a cozy retreat surrounded by snow-covered trees, offering a peaceful escape from the hustle and bustle of everyday life.", 22 | "The bustling marketplace was a sensory delight, with vibrant stalls selling fresh produce, handmade crafts, and an array of exotic spices.", 23 | "The train ride through the countryside was a scenic journey, offering glimpses of lush green fields, grazing cattle, and quaint farmhouses.", 24 | "The grand old mansion stood at the end of the road, its towering windows and intricate architecture hinting at a bygone era of elegance.", 25 | "The rolling hills were blanketed in wildflowers, swaying gently in the breeze as the sun cast a golden hue across the landscape.", 26 | "The narrow alleyway was alive with activity, as street vendors called out to passersby, offering everything from fresh fruit to handmade jewelry.", 27 | "The serene forest trail was lined with tall trees, their leaves forming a natural canopy that filtered the sunlight into soft patterns on the ground.", 28 | "The coastal cliffs offered breathtaking views of the vast ocean below, with seagulls gliding effortlessly through the salty breeze.", 29 | "The charming village square was the heart of the community, with its fountain surrounded by benches where residents gathered to share stories.", 30 | "The quiet library offered a peaceful escape, with its rows of books and comfortable seating inviting visitors to lose themselves in a story.", 31 | "The old lighthouse stood steadfast against the crashing waves, its beacon of light guiding ships safely through the treacherous waters.", 32 | "The quaint coffee shop on the corner was a favorite spot for locals to catch up over steaming cups of freshly brewed coffee.", 33 | "The vibrant street art on the walls of the urban neighborhood added a splash of color and creativity to the otherwise grey surroundings.", 34 | "The gentle stream meandered through the meadow, its crystal-clear waters reflecting the blue sky and fluffy white clouds above.", 35 | "The bustling harbor was a hub of activity, with fishermen unloading their catch and merchants haggling over prices.", 36 | "The sprawling vineyard stretched as far as the eye could see, its rows of grapevines promising a bountiful harvest.", 37 | "The tranquil lake was a haven for wildlife, with ducks gliding across the water and dragonflies flitting about in the sunlight.", 38 | "The ancient ruins were a testament to a once-great civilization, with crumbling walls and intricate carvings hinting at its former glory.", 39 | "The peaceful hiking trail wound its way through the mountains, offering breathtaking views of the valleys below.", 40 | "The small fishing village was a picturesque scene, with colorful boats bobbing in the harbor and nets drying in the sun.", 41 | "The quaint bookstore was a treasure trove for bibliophiles, with its shelves packed with rare and fascinating titles waiting to be discovered.", 42 | "The riverside picnic was a delightful affair, with friends sharing food, laughter, and the beauty of the surrounding nature.", 43 | "The historic castle on the hill stood as a reminder of times long past, its stone walls echoing with the stories of generations.", 44 | "The charming garden gathering was filled with laughter as guests mingled under strings of twinkling lights and enjoyed delicious treats.", 45 | "The peaceful countryside was a welcome escape from the noise of the city, with rolling hills and endless skies stretching into the horizon.", 46 | "The bustling amusement park was filled with laughter and excitement as children ran from ride to ride, clutching balloons and cotton candy.", 47 | "The tranquil mountain lake was a serene escape, its glassy surface reflecting the surrounding peaks and the occasional ripple from a jumping fish.", 48 | } 49 | -------------------------------------------------------------------------------- /lua/typr/constants/words.lua: -------------------------------------------------------------------------------- 1 | return { 2 | "urgent", 3 | "up", 4 | "treasure", 5 | "zinc", 6 | "unique", 7 | "yes", 8 | "zigzag", 9 | "recruit", 10 | "wilderness", 11 | "relate", 12 | "tiger", 13 | "xylophone", 14 | "science", 15 | "refresh", 16 | "solar", 17 | "yonder", 18 | "upcoming", 19 | "reaction", 20 | "risk", 21 | "tone", 22 | "wise", 23 | "resilient", 24 | "vessel", 25 | "upbeat", 26 | "zookeeper", 27 | "upvote", 28 | "rare", 29 | "utility", 30 | "vividness", 31 | "table", 32 | "xerox", 33 | "sequential", 34 | "transition", 35 | "role", 36 | "reflect", 37 | "vehicle", 38 | "unplug", 39 | "yield", 40 | "solution", 41 | "resilience", 42 | "vibrant", 43 | "youthful", 44 | "zigzagged", 45 | "zoom", 46 | "reverence", 47 | "yolk", 48 | "self", 49 | "social", 50 | "vacuum", 51 | "truthful", 52 | "unpredictable", 53 | "secure", 54 | "serene", 55 | "tasked", 56 | "undertake", 57 | "target", 58 | "xenoblast", 59 | "suitable", 60 | "system", 61 | "reliable", 62 | "yachtsman", 63 | "vibe", 64 | "smart", 65 | "violent", 66 | "survey", 67 | "tension", 68 | "serenity", 69 | "wrap", 70 | "radical", 71 | "serve", 72 | "valley", 73 | "scene", 74 | "timepiece", 75 | "respect", 76 | "xylocarp", 77 | "vacant", 78 | "reset", 79 | "serve", 80 | "trick", 81 | "stability", 82 | "solar", 83 | "signal", 84 | "upend", 85 | "wondering", 86 | "strength", 87 | "untapped", 88 | "timeless", 89 | "vaccine", 90 | "tablets", 91 | "wander", 92 | "xenial", 93 | "revolution", 94 | "sound", 95 | "row", 96 | "zippers", 97 | "trend", 98 | "zoning", 99 | "victory", 100 | "rise", 101 | "read", 102 | "rebuild", 103 | "wildlife", 104 | "velocity", 105 | "wrist", 106 | "xenon", 107 | "wasted", 108 | "robot", 109 | "understand", 110 | "xenolith", 111 | "truth", 112 | "rethink", 113 | "vital", 114 | "zooming", 115 | "venture", 116 | "underfoot", 117 | "weigh", 118 | "radar", 119 | "umbrella", 120 | "zigged", 121 | "train", 122 | "tasker", 123 | "upset", 124 | "ziggly", 125 | "rest", 126 | "reborn", 127 | "yellowed", 128 | "tutor", 129 | "xerothermic", 130 | "restart", 131 | "yes", 132 | "zest", 133 | "willpower", 134 | "ultimate", 135 | "silent", 136 | "result", 137 | "vision", 138 | "security", 139 | "zigzagging", 140 | "targeted", 141 | "tone", 142 | "verbal", 143 | "yes", 144 | "view", 145 | "science", 146 | "ultimate", 147 | "your", 148 | "thought", 149 | "violet", 150 | "reflect", 151 | "yield", 152 | "ready", 153 | "team", 154 | "year", 155 | "victorious", 156 | "uphold", 157 | "robot", 158 | "zone", 159 | "wonder", 160 | "yellow", 161 | "roam", 162 | "subtle", 163 | "stable", 164 | "zip", 165 | "substance", 166 | "respectful", 167 | "vocalist", 168 | "ready", 169 | "serenity", 170 | "task", 171 | "resourceful", 172 | "zipper", 173 | "reluctant", 174 | "structure", 175 | "yearn", 176 | "yes", 177 | "weary", 178 | "vocalize", 179 | "untouched", 180 | "zeal", 181 | "rescue", 182 | "solar", 183 | "together", 184 | "triumph", 185 | "study", 186 | "whisper", 187 | "wise", 188 | "truthful", 189 | "wonderful", 190 | "sample", 191 | "valid", 192 | "signal", 193 | "yachts", 194 | "wish", 195 | "system", 196 | "relax", 197 | "tasker", 198 | "submarine", 199 | "try", 200 | "trade", 201 | "sunset", 202 | "regular", 203 | "venture", 204 | "trend", 205 | "tag", 206 | "rare", 207 | "viewpoint", 208 | "significant", 209 | "view", 210 | "theory", 211 | "time", 212 | "targeted", 213 | "tension", 214 | "wait", 215 | "support", 216 | "teamwork", 217 | "safe", 218 | "reaction", 219 | "sensitive", 220 | "relevant", 221 | "transit", 222 | "verdict", 223 | "wise", 224 | "ultimate", 225 | "serve", 226 | "theoretical", 227 | "vanguard", 228 | "victory", 229 | "wrap", 230 | "work", 231 | "zone", 232 | "reset", 233 | "vision", 234 | "security", 235 | "zillion", 236 | "ready", 237 | "vacuum", 238 | "vitality", 239 | "valiant", 240 | "replay", 241 | "respectful", 242 | "useful", 243 | "tasked", 244 | "relax", 245 | "role", 246 | "serene", 247 | "vector", 248 | "yes", 249 | "valid", 250 | "victorious", 251 | "umbrella", 252 | "synergy", 253 | "velocity", 254 | "unknown", 255 | "wonderful", 256 | "silent", 257 | "systematic", 258 | "unique", 259 | "yachts", 260 | "value", 261 | "yes", 262 | "radial", 263 | "xylotomous", 264 | "unique", 265 | "zany", 266 | "rise", 267 | "ready", 268 | "river", 269 | "zing", 270 | "xenon", 271 | "relevance", 272 | "rebuild", 273 | "truthful", 274 | "resourceful", 275 | "renew", 276 | "season", 277 | "strong", 278 | "reward", 279 | "yellowish", 280 | "return", 281 | "stability", 282 | "wilderness", 283 | "xeroxing", 284 | "substance", 285 | "vow", 286 | "yellow", 287 | "wave", 288 | "yes", 289 | "vigilant", 290 | "yearning", 291 | "ripple", 292 | "venture", 293 | "together", 294 | "stream", 295 | "rest", 296 | "security", 297 | "understand", 298 | "row", 299 | "upbeat", 300 | "vacate", 301 | "result", 302 | "react", 303 | "yes", 304 | "sunshine", 305 | "yellow", 306 | "refresh", 307 | "tiger", 308 | "xenophobic", 309 | "study", 310 | "weigh", 311 | "trust", 312 | "resourceful", 313 | "recruit", 314 | "truthful", 315 | "yellow", 316 | "timeless", 317 | "validity", 318 | "valuable", 319 | "sun", 320 | "reset", 321 | "wonderful", 322 | "solar", 323 | "useful", 324 | "radial", 325 | "stability", 326 | "zestful", 327 | "zoom", 328 | "wonder", 329 | "serenity", 330 | "vector", 331 | "result", 332 | "radical", 333 | "refresh", 334 | "zebra", 335 | "read", 336 | "transition", 337 | "uphold", 338 | "resilient", 339 | "task", 340 | "wonderful", 341 | "wonder", 342 | "unit", 343 | "yellow", 344 | "uplifting", 345 | "visionary", 346 | "unlock", 347 | "velocity", 348 | "relevant", 349 | "yes", 350 | "unique", 351 | "user", 352 | "uplift", 353 | "resourceful", 354 | "zestfully", 355 | "row", 356 | "rest", 357 | "wealth", 358 | "yellow", 359 | "victory", 360 | "yearning", 361 | "wonderful", 362 | "role", 363 | "fire", 364 | "credit", 365 | "caterpillar", 366 | "dog", 367 | "alert", 368 | "dazzling", 369 | "discover", 370 | "efficient", 371 | "evening", 372 | "forest", 373 | "bargain", 374 | "chocolate", 375 | "dawn", 376 | "afraid", 377 | "diagnose", 378 | "elephant", 379 | "fate", 380 | "blossom", 381 | "cold", 382 | "delight", 383 | "accept", 384 | "disclose", 385 | "edge", 386 | "famous", 387 | "ballet", 388 | "couch", 389 | "dare", 390 | "absorb", 391 | "drag", 392 | "end", 393 | "frame", 394 | "banish", 395 | "contrast", 396 | "dear", 397 | "abundant", 398 | "drop", 399 | "enough", 400 | "future", 401 | "bark", 402 | "costume", 403 | "defend", 404 | "achieve", 405 | "dull", 406 | "examine", 407 | "faith", 408 | "bell", 409 | "courage", 410 | "dense", 411 | "action", 412 | "dust", 413 | "envelope", 414 | "french", 415 | "beyond", 416 | "courageous", 417 | "design", 418 | "activity", 419 | "dusty", 420 | "energy", 421 | "feather", 422 | "bitter", 423 | "crash", 424 | "detect", 425 | "adorable", 426 | "downward", 427 | "entry", 428 | "fantastic", 429 | "blade", 430 | "create", 431 | "device", 432 | "adventure", 433 | "dream", 434 | "envy", 435 | "fall", 436 | "blank", 437 | "credit", 438 | "diamond", 439 | "aesthetic", 440 | "drill", 441 | "escape", 442 | "fame", 443 | "block", 444 | "cricket", 445 | "dictate", 446 | "affection", 447 | "drive", 448 | "essential", 449 | "feast", 450 | "blunder", 451 | "crowd", 452 | "diminish", 453 | "agile", 454 | "dizzy", 455 | "event", 456 | "figure", 457 | "bold", 458 | "crystal", 459 | "diploma", 460 | "alarm", 461 | "doctor", 462 | "exactly", 463 | "first", 464 | "bomb", 465 | "cup", 466 | "dirt", 467 | "alert", 468 | "domestic", 469 | "excite", 470 | "fish", 471 | "book", 472 | "current", 473 | "disease", 474 | "align", 475 | "dorm", 476 | "expand", 477 | "flame", 478 | "boost", 479 | "cute", 480 | "displace", 481 | "amazing", 482 | "dormitory", 483 | "expert", 484 | "flock", 485 | "bottle", 486 | "dance", 487 | "distant", 488 | "amplify", 489 | "dormant", 490 | "exposure", 491 | "fluffy", 492 | "boundary", 493 | "dear", 494 | "distribute", 495 | "analyze", 496 | "door", 497 | "extraordinary", 498 | "focus", 499 | "box", 500 | "decide", 501 | "divide", 502 | "anchor", 503 | "doubt", 504 | "face", 505 | "fold", 506 | "branch", 507 | "decline", 508 | "dock", 509 | "angry", 510 | "dove", 511 | "fact", 512 | "fool", 513 | "brave", 514 | "deep", 515 | "dominate", 516 | "answer", 517 | "drastic", 518 | "factor", 519 | "fortune", 520 | "bread", 521 | "defend", 522 | "donate", 523 | "appreciate", 524 | "dream", 525 | "fair", 526 | "forward", 527 | "breathe", 528 | "delicate", 529 | "double", 530 | "approach", 531 | "drought", 532 | "falling", 533 | "frame", 534 | "breeze", 535 | "delight", 536 | "doubtful", 537 | "dull", 538 | "family", 539 | "free", 540 | "brick", 541 | "deliver", 542 | "doubtless", 543 | "arc", 544 | "dust", 545 | "fancy", 546 | "freedom", 547 | "bright", 548 | "deny", 549 | "dragon", 550 | "argue", 551 | "duty", 552 | "fantasy", 553 | "fresh", 554 | "brilliant", 555 | "descent", 556 | "drain", 557 | "arrange", 558 | "eager", 559 | "far", 560 | "friend", 561 | "bring", 562 | "desire", 563 | "draw", 564 | "art", 565 | "earn", 566 | "fast", 567 | "front", 568 | "brisk", 569 | "despair", 570 | "dread", 571 | "assume", 572 | "earth", 573 | "fate", 574 | "frost", 575 | "broad", 576 | "dessert", 577 | "dress", 578 | "asylum", 579 | "east", 580 | "father", 581 | "fruit", 582 | "brother", 583 | "detail", 584 | "drift", 585 | "attempt", 586 | "easy", 587 | "fear", 588 | "fun", 589 | "brush", 590 | "determine", 591 | "drink", 592 | "autumn", 593 | "eat", 594 | "feast", 595 | "funny", 596 | "bubble", 597 | "develop", 598 | "drive", 599 | "available", 600 | "echo", 601 | "feel", 602 | "fur", 603 | "build", 604 | "drop", 605 | "average", 606 | "edge", 607 | "fence", 608 | "furious", 609 | "bump", 610 | "diamond", 611 | "drum", 612 | "aware", 613 | "effect", 614 | "fetch", 615 | "future", 616 | "burn", 617 | "different", 618 | "dry", 619 | "awful", 620 | "efficient", 621 | "fiber", 622 | "fuzzy", 623 | "burst", 624 | "difficult", 625 | "duck", 626 | "awkward", 627 | "effort", 628 | "field", 629 | "family", 630 | "camera", 631 | "dine", 632 | "dust", 633 | "back", 634 | "egg", 635 | "fierce", 636 | "feast", 637 | "camp", 638 | "dinner", 639 | "duty", 640 | "bag", 641 | "eight", 642 | "fifth", 643 | "feature", 644 | "can", 645 | "direct", 646 | "eager", 647 | "balance", 648 | "either", 649 | "fight", 650 | "feel", 651 | "candy", 652 | "dirty", 653 | "earth", 654 | "ball", 655 | "elastic", 656 | "figure", 657 | "fence", 658 | "cannon", 659 | "disease", 660 | "east", 661 | "banana", 662 | "electric", 663 | "fill", 664 | "cap", 665 | "dish", 666 | "easy", 667 | "band", 668 | "elephant", 669 | "film", 670 | "fetch", 671 | "car", 672 | "disk", 673 | "eat", 674 | "bang", 675 | "eleven", 676 | "final", 677 | "few", 678 | "card", 679 | "display", 680 | "echo", 681 | "bank", 682 | "else", 683 | "find", 684 | "field", 685 | "care", 686 | "distant", 687 | "effect", 688 | "bar", 689 | "empty", 690 | "fine", 691 | "fierce", 692 | "careful", 693 | "divide", 694 | "effort", 695 | "bare", 696 | "end", 697 | "finger", 698 | "fifteen", 699 | "carriage", 700 | "do", 701 | "egg", 702 | "bark", 703 | "enemy", 704 | "finish", 705 | "fight", 706 | "carry", 707 | "doctor", 708 | "eight", 709 | "barn", 710 | "energy", 711 | "fire", 712 | "figure", 713 | "cart", 714 | "dog", 715 | "either", 716 | "base", 717 | "engine", 718 | "first", 719 | "fill", 720 | "cat", 721 | "door", 722 | "elastic", 723 | "basket", 724 | "enjoy", 725 | "fish", 726 | "film", 727 | "catch", 728 | "double", 729 | "electric", 730 | "bat", 731 | "enough", 732 | "fit", 733 | "finger", 734 | "cattle", 735 | "down", 736 | "eleven", 737 | "battle", 738 | "enter", 739 | "five", 740 | "fire", 741 | "cause", 742 | "drain", 743 | "else", 744 | "bay", 745 | "equal", 746 | "fix", 747 | "first", 748 | "center", 749 | "draw", 750 | "empty", 751 | "be", 752 | "error", 753 | "flag", 754 | "fish", 755 | "chain", 756 | "dream", 757 | "end", 758 | "bead", 759 | "even", 760 | "flame", 761 | "fit", 762 | "chair", 763 | "dress", 764 | "enemy", 765 | "beam", 766 | "ever", 767 | "flash", 768 | "five", 769 | "chalk", 770 | "drink", 771 | "energy", 772 | "bean", 773 | "every", 774 | "flat", 775 | "fix", 776 | "chance", 777 | "drive", 778 | "engine", 779 | "bear", 780 | "exact", 781 | "flight", 782 | "flag", 783 | "change", 784 | "drop", 785 | "enjoy", 786 | "beautiful", 787 | "example", 788 | "float", 789 | "flame", 790 | "channel", 791 | "dry", 792 | "enough", 793 | "beauty", 794 | "excellent", 795 | "floor", 796 | "flash", 797 | "charm", 798 | "duck", 799 | "enter", 800 | "bed", 801 | "exercise", 802 | "flow", 803 | "flat", 804 | "chase", 805 | "dust", 806 | "equal", 807 | "bee", 808 | "exist", 809 | "flower", 810 | "flight", 811 | "cheap", 812 | "duty", 813 | "error", 814 | "beef", 815 | "expect", 816 | "fly", 817 | "float", 818 | "check", 819 | "each", 820 | "even", 821 | "eye", 822 | "fold", 823 | "floor", 824 | "cheese", 825 | "ear", 826 | "ever", 827 | "beg", 828 | "face", 829 | "follow", 830 | "flow", 831 | "chest", 832 | "early", 833 | "every", 834 | "behavior", 835 | "fact", 836 | "food", 837 | "fly", 838 | "chicken", 839 | "earth", 840 | "example", 841 | "bell", 842 | "fade", 843 | "fool", 844 | "foam", 845 | "chief", 846 | "east", 847 | "excellent", 848 | "belt", 849 | "fail", 850 | "foot", 851 | "fold", 852 | "child", 853 | "easy", 854 | "exist", 855 | "bend", 856 | "faint", 857 | "for", 858 | "follow", 859 | "chin", 860 | "eat", 861 | "expect", 862 | "berry", 863 | "fair", 864 | "force", 865 | "food", 866 | "edge", 867 | "eye", 868 | "between", 869 | "fall", 870 | "foreign", 871 | "foot", 872 | "circle", 873 | "effect", 874 | "face", 875 | "big", 876 | "false", 877 | "forest", 878 | "for", 879 | "clam", 880 | "egg", 881 | "fact", 882 | "bill", 883 | "family", 884 | "forget", 885 | "force", 886 | "class", 887 | "eight", 888 | "fade", 889 | "bird", 890 | "far", 891 | "fork", 892 | "foreign", 893 | "clean", 894 | "either", 895 | "fail", 896 | "birth", 897 | "farm", 898 | "form", 899 | "forest", 900 | "clear", 901 | "elastic", 902 | "faint", 903 | "bit", 904 | "fast", 905 | "forward", 906 | "forget", 907 | "clock", 908 | "electric", 909 | "fair", 910 | "bite", 911 | "fat", 912 | "fowl", 913 | "form", 914 | "close", 915 | "eleven", 916 | "fall", 917 | "black", 918 | "father", 919 | "frame", 920 | "forward", 921 | "cloth", 922 | "else", 923 | "false", 924 | "blade", 925 | "fear", 926 | "free", 927 | "fowl", 928 | "cloud", 929 | "empty", 930 | "family", 931 | "blood", 932 | "feather", 933 | "frequent", 934 | "fox", 935 | "coal", 936 | "end", 937 | "far", 938 | "blow", 939 | "feeble", 940 | "fresh", 941 | "frame", 942 | "coat", 943 | "enemy", 944 | "farm", 945 | "blue", 946 | "feel", 947 | "friend", 948 | "free", 949 | "energy", 950 | "fast", 951 | "board", 952 | "feet", 953 | "front", 954 | "frequent", 955 | "coffee", 956 | "engine", 957 | "fat", 958 | "boat", 959 | "female", 960 | "fruit", 961 | "fresh", 962 | "cold", 963 | "enjoy", 964 | "father", 965 | "bone", 966 | "fence", 967 | "full", 968 | "friend", 969 | "collar", 970 | "enough", 971 | "fear", 972 | "book", 973 | "fertile", 974 | "future", 975 | "glide", 976 | "hatch", 977 | "gobble", 978 | "influence", 979 | "june", 980 | "hopeful", 981 | "glowing", 982 | "insight", 983 | "juice", 984 | "gaze", 985 | "knucklehead", 986 | "goblin", 987 | "knot", 988 | "guava", 989 | "inquire", 990 | "hollow", 991 | "keyhole", 992 | "joy", 993 | "glow", 994 | "health", 995 | "identify", 996 | "knuckle", 997 | "kooky", 998 | "gentle", 999 | "knightmare", 1000 | "goosebumps", 1001 | "internal", 1002 | "kindred", 1003 | "kith", 1004 | "gorge", 1005 | "griddle", 1006 | "kangaroo", 1007 | "glorious", 1008 | "input", 1009 | "gather", 1010 | "kerfuffle", 1011 | "giraffe", 1012 | "knuckles", 1013 | "hobby", 1014 | "kick", 1015 | "grip", 1016 | "horror", 1017 | "hot", 1018 | "justice", 1019 | "jungle", 1020 | "heart", 1021 | "gaunt", 1022 | "habit", 1023 | "guess", 1024 | "intact", 1025 | "grape", 1026 | "happiness", 1027 | "inspire", 1028 | "jovial", 1029 | "kicker", 1030 | "glory", 1031 | "information", 1032 | "glue", 1033 | "improvise", 1034 | "knot", 1035 | "glow", 1036 | "kale", 1037 | "gutsy", 1038 | "harbor", 1039 | "harm", 1040 | "kernel", 1041 | "impact", 1042 | "gain", 1043 | "improve", 1044 | "kettlebell", 1045 | "jaunty", 1046 | "glisten", 1047 | "hungry", 1048 | "initiative", 1049 | "gems", 1050 | "juggle", 1051 | "kitchen", 1052 | "kindness", 1053 | "glare", 1054 | "goalkeeper", 1055 | "jammed", 1056 | "kaleidoscope", 1057 | "incredible", 1058 | "goat", 1059 | "kit", 1060 | "integrate", 1061 | "keypad", 1062 | "kitten", 1063 | "kite", 1064 | "hype", 1065 | "hilarious", 1066 | "knave", 1067 | "jelly", 1068 | "kiln", 1069 | "jolt", 1070 | "gap", 1071 | "help", 1072 | "gather", 1073 | "harvest", 1074 | "kneeled", 1075 | "knit", 1076 | "interested", 1077 | "humble", 1078 | "jeopardy", 1079 | "klutz", 1080 | "imagine", 1081 | "grim", 1082 | "jagged", 1083 | "journalize", 1084 | "hologram", 1085 | "huddle", 1086 | "identity", 1087 | "glimmer", 1088 | "hallway", 1089 | "insight", 1090 | "human", 1091 | "install", 1092 | "juggle", 1093 | "germicide", 1094 | "knotty", 1095 | "ignition", 1096 | "jumble", 1097 | "gather", 1098 | "knee", 1099 | "kiwi", 1100 | "insightful", 1101 | "keen", 1102 | "half", 1103 | "jacket", 1104 | "hero", 1105 | "goose", 1106 | "heritage", 1107 | "jasmine", 1108 | "gully", 1109 | "gentleman", 1110 | "harmony", 1111 | "height", 1112 | "jester", 1113 | "jaunt", 1114 | "hasty", 1115 | "knife", 1116 | "hollowed", 1117 | "house", 1118 | "horizon", 1119 | "glimmer", 1120 | "justice", 1121 | "inspire", 1122 | "gland", 1123 | "illusion", 1124 | "history", 1125 | "jolted", 1126 | "kilogram", 1127 | "knowledgeable", 1128 | "hundred", 1129 | "green", 1130 | "hopeful", 1131 | "gentle", 1132 | "interact", 1133 | "guarantee", 1134 | "hike", 1135 | "garden", 1136 | "gasp", 1137 | "glance", 1138 | "gallop", 1139 | "hit", 1140 | "hand", 1141 | "holidays", 1142 | "jump", 1143 | "important", 1144 | "hectic", 1145 | "jibe", 1146 | "important", 1147 | "kaboom", 1148 | "knack", 1149 | "glued", 1150 | "gather", 1151 | "healthful", 1152 | "jamboree", 1153 | "keep", 1154 | "incognito", 1155 | "joke", 1156 | "keystone", 1157 | "kittenish", 1158 | "hug", 1159 | "habitual", 1160 | "glimmer", 1161 | "hoop", 1162 | "gadget", 1163 | "hustle", 1164 | "gorgeous", 1165 | "growth", 1166 | "kind", 1167 | "harder", 1168 | "hands", 1169 | "hypocrite", 1170 | "grilled", 1171 | "goofy", 1172 | "kabinet", 1173 | "hearing", 1174 | "grapevine", 1175 | "happening", 1176 | "hurry", 1177 | "generosity", 1178 | "keen", 1179 | "jolty", 1180 | "individual", 1181 | "holler", 1182 | "initiative", 1183 | "heart", 1184 | "intelligence", 1185 | "glow", 1186 | "glow", 1187 | "great", 1188 | "glamour", 1189 | "jigsaw", 1190 | "hike", 1191 | "icon", 1192 | "mission", 1193 | "love", 1194 | "operate", 1195 | "pencil", 1196 | "niche", 1197 | "quality", 1198 | "material", 1199 | "loud", 1200 | "orchid", 1201 | "naive", 1202 | "peaceful", 1203 | "quilt", 1204 | "light", 1205 | "nostalgic", 1206 | "matter", 1207 | "path", 1208 | "obstacle", 1209 | "maze", 1210 | "question", 1211 | "notify", 1212 | "mind", 1213 | "quantum", 1214 | "perfect", 1215 | "negative", 1216 | "quixotic", 1217 | "party", 1218 | "obligated", 1219 | "observe", 1220 | "mango", 1221 | "natural", 1222 | "power", 1223 | "object", 1224 | "navigate", 1225 | "latch", 1226 | "map", 1227 | "quash", 1228 | "lien", 1229 | "night", 1230 | "quiver", 1231 | "mountain", 1232 | "new", 1233 | "quicksand", 1234 | "presence", 1235 | "outlet", 1236 | "ocean", 1237 | "neat", 1238 | "momentum", 1239 | "license", 1240 | "lively", 1241 | "nice", 1242 | "quarter", 1243 | "perform", 1244 | "original", 1245 | "narrative", 1246 | "march", 1247 | "prison", 1248 | "pet", 1249 | "meet", 1250 | "normal", 1251 | "luxury", 1252 | "magnify", 1253 | "over", 1254 | "noble", 1255 | "move", 1256 | "nest", 1257 | "model", 1258 | "lamp", 1259 | "near", 1260 | "nothing", 1261 | "machine", 1262 | "motive", 1263 | "nation", 1264 | "national", 1265 | "note", 1266 | "loyal", 1267 | "malignant", 1268 | "laptop", 1269 | "prefer", 1270 | "learn", 1271 | "magnet", 1272 | "qualify", 1273 | "mist", 1274 | "positive", 1275 | "noodles", 1276 | "outreach", 1277 | "picture", 1278 | "literature", 1279 | "manipulate", 1280 | "nationwide", 1281 | "private", 1282 | "magnetic", 1283 | "name", 1284 | "limit", 1285 | "passion", 1286 | "land", 1287 | "patient", 1288 | "participate", 1289 | "laugh", 1290 | "mirror", 1291 | "outgoing", 1292 | "program", 1293 | "legend", 1294 | "overjoyed", 1295 | "mutual", 1296 | "last", 1297 | "lemon", 1298 | "obscure", 1299 | "leader", 1300 | "overall", 1301 | "opposition", 1302 | "obstacle", 1303 | "park", 1304 | "quick", 1305 | "progress", 1306 | "lifestyle", 1307 | "manual", 1308 | "obtain", 1309 | "proposal", 1310 | "lively", 1311 | "problem", 1312 | "local", 1313 | "prevent", 1314 | "lounge", 1315 | "mood", 1316 | "loop", 1317 | "matter", 1318 | "profit", 1319 | "projector", 1320 | "label", 1321 | "mosaic", 1322 | "lotion", 1323 | "opulent", 1324 | "perfectly", 1325 | "permanent", 1326 | "large", 1327 | "prepare", 1328 | "luxury", 1329 | "place", 1330 | "lunar", 1331 | "lucky", 1332 | "plan", 1333 | "leap", 1334 | "lively", 1335 | "privilege", 1336 | "post", 1337 | "locate", 1338 | "point", 1339 | "lecture", 1340 | "mean", 1341 | "laughter", 1342 | "public", 1343 | "pioneer", 1344 | "perform", 1345 | "lose", 1346 | "position", 1347 | "lemonade", 1348 | "passionate", 1349 | "level", 1350 | "liquid", 1351 | "protect", 1352 | "long", 1353 | "planter", 1354 | "leverage", 1355 | "pleasure", 1356 | "lull", 1357 | "leverage", 1358 | "lonely", 1359 | "lit", 1360 | "lily", 1361 | "paint", 1362 | "peach", 1363 | "pollution", 1364 | "preference", 1365 | "popularity", 1366 | "landscape", 1367 | "library", 1368 | "quaint", 1369 | "quota", 1370 | "quiz", 1371 | "quarrel", 1372 | "qualify", 1373 | "quench", 1374 | "quote", 1375 | "quality", 1376 | "quadrant", 1377 | "quiver", 1378 | "quantity", 1379 | "quaintly", 1380 | "quantum", 1381 | "quash", 1382 | "quibble", 1383 | "quaintness", 1384 | "quorum", 1385 | "quest", 1386 | } 1387 | -------------------------------------------------------------------------------- /lua/typr/init.lua: -------------------------------------------------------------------------------- 1 | local M = {} 2 | local api = vim.api 3 | local state = require "typr.state" 4 | local layout = require "typr.ui.layout" 5 | local volt = require "volt" 6 | local utils = require "typr.utils" 7 | local voltstate = require "volt.state" 8 | 9 | M.setup = function(opts) 10 | state.config = vim.tbl_deep_extend("force", state.config, opts or {}) 11 | require("typr.stats.utils").restore_stats() 12 | end 13 | 14 | M.initialize_volt = function() 15 | volt.gen_data { 16 | { buf = state.buf, layout = layout, xpad = state.xpad, ns = state.ns }, 17 | } 18 | end 19 | 20 | M.open = function() 21 | if state.buf then 22 | return 23 | end 24 | 25 | require "typr.ui.hl"(0) 26 | 27 | state.buf = api.nvim_create_buf(false, true) 28 | 29 | local dim_buf = api.nvim_create_buf(false, true) 30 | local dim_win = api.nvim_open_win(dim_buf, false, { 31 | focusable = false, 32 | row = 0, 33 | col = 0, 34 | width = vim.o.columns, 35 | height = vim.o.lines - 2, 36 | relative = "editor", 37 | style = "minimal", 38 | border = "none", 39 | }) 40 | 41 | vim.wo[dim_win].winblend = 20 42 | 43 | utils.gen_default_lines() 44 | 45 | M.initialize_volt() 46 | 47 | state.h = voltstate[state.buf].h 48 | 49 | state.win = api.nvim_open_win(state.buf, true, { 50 | row = (vim.o.lines / 2) - (state.h / 2), 51 | col = (vim.o.columns / 2) - (state.w / 2), 52 | width = state.w, 53 | height = state.h, 54 | relative = "editor", 55 | style = "minimal", 56 | border = "single", 57 | zindex = 100, 58 | }) 59 | 60 | api.nvim_win_set_hl_ns(state.win, state.ns) 61 | 62 | api.nvim_set_hl(state.ns, "FloatBorder", { link = "typrborder" }) 63 | api.nvim_set_hl(state.ns, "Normal", { link = "typrnormal" }) 64 | 65 | api.nvim_set_current_win(state.win) 66 | 67 | volt.run(state.buf, { 68 | h = 10, 69 | w = state.w_with_pad, 70 | custom_empty_lines = utils.set_emptylines, 71 | }) 72 | 73 | if state.config.insert_on_start then 74 | vim.api.nvim_command "startinsert" 75 | end 76 | 77 | ----------------- keymaps -------------------------- 78 | volt.mappings { 79 | bufs = { state.buf, dim_buf }, 80 | winclosed_event = true, 81 | after_close = function() 82 | state.reset_vars() 83 | state.buf = nil 84 | end, 85 | } 86 | 87 | vim.bo[state.buf].filetype = "typr" 88 | vim.bo[state.buf].ma = true 89 | vim.wo[state.win].wrap = true 90 | vim.wo[state.win].sidescrolloff = 0 91 | vim.wo[state.win].virtualedit = "all" 92 | 93 | api.nvim_win_set_cursor(state.win, { state.words_row + 1, state.xpad }) 94 | 95 | local lasttime = 0 96 | 97 | api.nvim_buf_attach(state.buf, false, { 98 | on_lines = function(_, _, _, line) 99 | if not state.lastchar and api.nvim_get_mode().mode == "i" then 100 | utils.start_timer() 101 | end 102 | 103 | local curline = api.nvim_get_current_line():sub(3) 104 | local words_row = line - state.words_row + 1 105 | local default_line = state.default_lines[words_row] 106 | 107 | if not default_line then 108 | return 109 | end 110 | 111 | state.ui_lines[words_row] = utils.gen_lines_diff(default_line, curline) 112 | 113 | api.nvim_buf_set_extmark(state.buf, state.ns, line, 0, { 114 | virt_text = state.ui_lines[words_row], 115 | virt_text_win_col = state.xpad, 116 | id = line + 1, 117 | }) 118 | 119 | state.lastchar = curline:sub(-1) 120 | 121 | local cur = vim.uv.hrtime() 122 | table.insert(state.stats.char_times, { state.lastchar, (cur - lasttime) / 1e6 }) 123 | lasttime = cur 124 | 125 | utils.handle_test_end() 126 | end, 127 | }) 128 | 129 | require "typr.mappings"() 130 | 131 | pcall(function() 132 | require("cmp").setup.buffer { enabled = false } 133 | end) 134 | 135 | if type(state.config.on_attach) == "function" then 136 | state.config.on_attach(state.buf) 137 | end 138 | end 139 | 140 | return M 141 | -------------------------------------------------------------------------------- /lua/typr/mappings.lua: -------------------------------------------------------------------------------- 1 | local state = require "typr.state" 2 | local map = vim.keymap.set 3 | local api = vim.api 4 | local myapi = require "typr.api" 5 | 6 | return function() 7 | map("n", "i", function() 8 | api.nvim_win_set_cursor(state.win, { state.words_row + 1, state.xpad }) 9 | vim.cmd.startinsert() 10 | end, { buffer = state.buf }) 11 | 12 | map("n", "", function() 13 | api.nvim_win_set_cursor(state.win, { state.words_row + 1, state.xpad }) 14 | myapi.restart() 15 | end, { buffer = state.buf }) 16 | 17 | map("n", "s", myapi.toggle_symbols, { buffer = state.buf }) 18 | map("n", "n", myapi.toggle_numbers, { buffer = state.buf }) 19 | map("n", "r", myapi.toggle_random, { buffer = state.buf }) 20 | map("n", "p", myapi.toggle_phrases, { buffer = state.buf }) 21 | 22 | for _, v in ipairs { 3, 6, 9 } do 23 | map("n", tostring(v), function() 24 | myapi.set_linecount(v) 25 | end, { buffer = state.buf }) 26 | end 27 | 28 | map("n", "o", "", { buffer = state.buf }) 29 | map("i", "", "", { buffer = state.buf }) 30 | 31 | if state.config.mappings then 32 | state.config.mappings(state.buf) 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /lua/typr/state.lua: -------------------------------------------------------------------------------- 1 | local M = { 2 | ns = vim.api.nvim_create_namespace "Typr", 3 | xpad = 2, 4 | w = 80, 5 | h = 20, 6 | linecount = 2, 7 | default_lines = {}, 8 | ui_lines = {}, 9 | lastchar = nil, 10 | words_row = 4, 11 | timer = vim.uv.new_timer(), 12 | secs = 0, 13 | months_toggled = false, 14 | tab = " Dashboard", 15 | winlayout = "horizontal", 16 | horiz_i = 1, 17 | 18 | -- temporary! 19 | -- stats = {} -- data stored here after test finishes 20 | -- then saved to disk and this table is reset 21 | 22 | ----------------------- user config ----------------------- 23 | config = { 24 | mode = "words", -- words, phrases 25 | winlayout = "responsive", 26 | kblayout = "qwerty", 27 | wpm_goal = 130, 28 | numbers = false, 29 | symbols = false, 30 | random = false, 31 | phrases = nil, -- can be a table of strings 32 | insert_on_start = false, 33 | stats_filepath = vim.fn.stdpath "data" .. "/typrstats", 34 | mappings = nil, 35 | -- or function(buf) end 36 | -- mappings = function(buf) 37 | -- vim.keymap.set("n", "a, anything, { buffer = buf }) 38 | -- end, 39 | on_attach = nil, 40 | -- or function(buf) end 41 | -- on_attach = function(buf) 42 | -- vim.b[buf].minipairs_disable = true 43 | -- end, 44 | }, 45 | 46 | -- for stats 47 | data = {}, 48 | } 49 | 50 | M.reset_vars = function() 51 | M.lastchar = nil 52 | M.secs = 0 53 | 54 | M.stats = { 55 | accuracy = 0, 56 | wpm = 0, 57 | rawpm = 0, 58 | correct_word_ratio = "?", 59 | total_char_count = 0, 60 | typed_char_count = 0, 61 | char_times = {}, 62 | char_stats = { all = 0, wrong = 0 }, 63 | word_stats = { all = 0, wrong = 0 }, 64 | } 65 | 66 | M.timer:stop() 67 | end 68 | 69 | M.reset_vars() 70 | 71 | M.w_with_pad = M.w - (2 * M.xpad) 72 | 73 | return M 74 | -------------------------------------------------------------------------------- /lua/typr/stats/dashboard.lua: -------------------------------------------------------------------------------- 1 | local state = require "typr.state" 2 | local config = state.config 3 | local voltui = require "volt.ui" 4 | 5 | local function secsTodhm(secs) 6 | local days = math.floor(secs / 86400) 7 | local hours = math.floor((secs % 86400) / 3600) 8 | local minutes = math.floor((secs % 3600) / 60) 9 | return string.format("%02d:%02d:%02d", days, hours, minutes) 10 | end 11 | 12 | local function get_lvlstats(my_secs, wpm_ratio) 13 | local level = math.floor(my_secs / 200) + 1 14 | local next_lvl = (level + 1) * 200 15 | local next_perc = math.floor(((my_secs + wpm_ratio) / next_lvl) * 100) 16 | 17 | return { 18 | val = level, 19 | next_perc = 100 - next_perc, 20 | } 21 | end 22 | 23 | local progress = function() 24 | local barlen = state.w_with_pad / 3 - 1 25 | local wpm_progress = (state.data.wpm.avg / config.wpm_goal) * 100 26 | 27 | local wpm_stats = { 28 | { { "", "exgreen" }, { " WPM ~ " }, { tostring(state.data.wpm.avg) .. " / " .. tostring(config.wpm_goal) } }, 29 | {}, 30 | voltui.progressbar { 31 | w = barlen, 32 | val = wpm_progress > 100 and 100 or wpm_progress, 33 | icon = { on = "┃", off = "┃" }, 34 | hl = { on = "exgreen", off = "linenr" }, 35 | }, 36 | } 37 | 38 | local accuracy_stats = { 39 | { { "", "exred" }, { " Accuracy ~ " }, { tostring(state.data.accuracy) .. " %" } }, 40 | {}, 41 | voltui.progressbar { 42 | w = barlen, 43 | val = state.data.accuracy, 44 | icon = { on = "┃", off = "┃" }, 45 | }, 46 | } 47 | 48 | local lvl_stats = get_lvlstats(state.data.total_secs, wpm_progress) 49 | 50 | local lvl_stats_ui = { 51 | { { "", "exyellow" }, { " Level ~ " }, { tostring(lvl_stats.val) } }, 52 | {}, 53 | voltui.progressbar { 54 | w = barlen, 55 | val = lvl_stats.next_perc, 56 | hl = { on = "exyellow" }, 57 | icon = { on = "┃", off = "┃" }, 58 | }, 59 | } 60 | 61 | return voltui.grid_col { 62 | { lines = wpm_stats, w = barlen, pad = 2 }, 63 | { lines = accuracy_stats, w = barlen, pad = 2 }, 64 | { lines = lvl_stats_ui, w = barlen }, 65 | } 66 | end 67 | 68 | local tabular_stats = function() 69 | local tb = { 70 | { 71 | " Total time", 72 | " Tests", 73 | " Lowest", 74 | " Highest", 75 | " RAW WPM", 76 | }, 77 | 78 | { 79 | secsTodhm(state.data.total_secs), 80 | state.data.times, 81 | state.data.wpm.min .. " WPM", 82 | state.data.wpm.max .. " WPM", 83 | state.data.rawpm.avg .. " WPM", 84 | }, 85 | } 86 | 87 | return voltui.table(tb, state.w_with_pad) 88 | end 89 | 90 | local graph = function() 91 | local data = vim.tbl_map(function(x) 92 | return math.floor(x / config.wpm_goal * 100) 93 | end, state.data.wpm_hist) 94 | 95 | local wpm_graph_data = { 96 | val = data, 97 | footer_label = { " Last 10 WPM stats" }, 98 | 99 | format_labels = function(x) 100 | return tostring((x / 100) * config.wpm_goal) 101 | end, 102 | 103 | baropts = { 104 | w = 2, 105 | gap = 1, 106 | hl = "exgreen", 107 | dual_hl = { "exlightgrey", "commentfg" }, 108 | -- format_hl = function(x) 109 | -- return x > 50 and "exred" or "normal" 110 | -- end, 111 | }, 112 | w = state.w_with_pad / 2, 113 | } 114 | 115 | local accuracy_graph_data = { 116 | val = state.data.accuracy_hist, 117 | w = state.w_with_pad / 2, 118 | footer_label = { "Last 10 Accuracy stats" }, 119 | } 120 | 121 | return voltui.grid_col { 122 | { lines = voltui.graphs.bar(wpm_graph_data), w = (state.w_with_pad - 1) / 2, pad = 2 }, 123 | { lines = voltui.graphs.dot(accuracy_graph_data), w = (state.w_with_pad - 1) / 2 }, 124 | } 125 | end 126 | 127 | local rawpm = function() 128 | local data = vim.tbl_map(function(x) 129 | return math.floor(x / config.wpm_goal * 100) 130 | end, state.data.rawpm_hist) 131 | 132 | local wpm_graph_data = { 133 | val = data, 134 | footer_label = { " Last 32 RAW WPM stats" }, 135 | 136 | format_labels = function(x) 137 | return tostring((x / 100) * config.wpm_goal) 138 | end, 139 | 140 | baropts = { 141 | w = 1, 142 | gap = 1, 143 | format_hl = function(x) 144 | if x > 85 then 145 | return "exgreen" 146 | elseif x > 60 then 147 | return "exred" 148 | end 149 | return "normal" 150 | end, 151 | }, 152 | w = state.w_with_pad / 2, 153 | } 154 | 155 | return voltui.graphs.bar(wpm_graph_data) 156 | end 157 | 158 | return function() 159 | return require("volt.ui").grid_row { 160 | progress(), 161 | { {} }, 162 | tabular_stats(), 163 | { {} }, 164 | graph(), 165 | { {} }, 166 | rawpm(), 167 | { {} }, 168 | } 169 | end 170 | -------------------------------------------------------------------------------- /lua/typr/stats/history.lua: -------------------------------------------------------------------------------- 1 | local state = require "typr.state" 2 | local config = state.config 3 | local voltui = require "volt.ui" 4 | 5 | local tabular_stats = function() 6 | local tb = { { "Time", "WPM", "RAW", "Accuracy" } } 7 | 8 | local history = state.data.test_history 9 | 10 | for i = 1, 8 do 11 | local data = history[i] 12 | table.insert(tb, { data.time, data.wpm, data.rawpm, data.accuracy }) 13 | end 14 | 15 | local w1 = state.w_with_pad - 30 16 | local w2 = 29 17 | 18 | local goalTb = { 19 | { { { " WPM GOAL ~ " .. config.wpm_goal, "normal" } } }, 20 | } 21 | 22 | for i, _ in ipairs(tb) do 23 | if i ~= 1 then 24 | local progressbar = voltui.progressbar { 25 | w = w2 - 4, 26 | val = math.floor(tb[i][2] / state.config.wpm_goal * 100), 27 | hl = { on = "exblue" }, 28 | icon = { on = "|", off = "|" }, 29 | } 30 | table.insert(goalTb, { progressbar }) 31 | end 32 | end 33 | 34 | return voltui.grid_col { 35 | { 36 | lines = voltui.table(tb, w1), 37 | w = w1, 38 | pad = 1, 39 | }, 40 | { 41 | lines = voltui.table(goalTb, w2), 42 | w = w2, 43 | }, 44 | } 45 | end 46 | 47 | local rawpm = function() 48 | local char_times = state.data.char_times 49 | local sum = 0 50 | 51 | for _, v in pairs(char_times) do 52 | sum = sum + v 53 | end 54 | 55 | local footerTxt = "" 56 | local data = {} 57 | 58 | for i = 97, 122 do 59 | local char = string.char(i) 60 | char_times[char] = char_times[char] or 0 61 | data[char] = math.floor((char_times[char] / sum) * 1000) 62 | footerTxt = footerTxt .. char .. (i ~= 122 and " " or "") 63 | end 64 | 65 | local dotdata = {} 66 | 67 | for i = 97, 122 do 68 | table.insert(dotdata, data[string.char(i)]) 69 | end 70 | 71 | local wpm_graph_data = { 72 | val = dotdata, 73 | 74 | format_labels = function(x) 75 | return tostring((x / 100) * 150) 76 | end, 77 | 78 | baropts = { 79 | w = 1, 80 | gap = 1, 81 | sidelabels = false, 82 | icons = { on = "󰄰", off = "·" }, 83 | 84 | format_hl = function(x) 85 | if x > 60 then 86 | return "exred" 87 | end 88 | return x > 30 and "exblue" or "exgreen" 89 | end, 90 | }, 91 | w = state.w_with_pad / 2, 92 | } 93 | 94 | local lines = voltui.graphs.dot(wpm_graph_data) 95 | local linew = voltui.line_w(lines[1]) 96 | table.insert(lines, { { string.rep("─", linew), "comment" } }) 97 | table.insert(lines, { { footerTxt, "exlightgrey" } }) 98 | voltui.border(lines) 99 | 100 | return lines 101 | end 102 | 103 | return function() 104 | return require("volt.ui").grid_row { 105 | { { { "  History of last 8 tests" } } }, 106 | 107 | tabular_stats(), 108 | { {} }, 109 | { { { " Average speed of each key per test (lower is better)" } } }, 110 | rawpm(), 111 | } 112 | end 113 | -------------------------------------------------------------------------------- /lua/typr/stats/init.lua: -------------------------------------------------------------------------------- 1 | local M = {} 2 | local api = vim.api 3 | local state = require "typr.state" 4 | local volt = require "volt" 5 | local voltstate = require "volt.state" 6 | local utils = require "typr.stats.utils" 7 | 8 | M.open = function() 9 | if state.statsbuf then 10 | return 11 | end 12 | 13 | state.statsbuf = api.nvim_create_buf(false, true) 14 | 15 | if state.config.winlayout == "responsive" then 16 | state.winlayout = vim.o.columns > ((2 * state.w) + 10) and "horizontal" or "vertical" 17 | else 18 | state.winlayout = state.config.winlayout 19 | end 20 | 21 | local dim_buf = api.nvim_create_buf(false, true) 22 | local dim_win = api.nvim_open_win(dim_buf, false, { 23 | focusable = false, 24 | row = 0, 25 | col = 0, 26 | width = vim.o.columns, 27 | height = vim.o.lines - 2, 28 | relative = "editor", 29 | style = "minimal", 30 | border = "none", 31 | }) 32 | 33 | vim.wo[dim_win].winblend = 20 34 | 35 | require("typr.stats.utils").init_volt() 36 | state.h = voltstate[state.statsbuf].h 37 | 38 | local winconf = utils.make_winconf() 39 | state.win = api.nvim_open_win(state.statsbuf, true, winconf) 40 | 41 | api.nvim_win_set_hl_ns(state.win, state.ns) 42 | api.nvim_set_hl(state.ns, "FloatBorder", { link = "typrborder" }) 43 | api.nvim_set_hl(state.ns, "Normal", { link = "typrnormal" }) 44 | 45 | volt.run(state.statsbuf, { h = state.h + 1, w = state.w_with_pad }) 46 | 47 | require "typr.ui.hl"(state.ns, "stats") 48 | 49 | volt.mappings { 50 | bufs = { state.statsbuf, dim_buf }, 51 | winclosed_event = true, 52 | after_close = function() 53 | state.statsbuf = nil 54 | -- vim.api.nvim_del_augroup_by_name "TyprResize" 55 | end, 56 | } 57 | 58 | vim.keymap.set("n", "", function() 59 | state.months_toggled = not state.months_toggled 60 | volt.redraw(state.statsbuf, "typrStats") 61 | end, { buffer = state.statsbuf }) 62 | 63 | vim.keymap.set("n", "D", function() 64 | state.tab = " Dashboard" 65 | volt.redraw(state.statsbuf, "all") 66 | end, { buffer = state.statsbuf }) 67 | 68 | vim.keymap.set("n", "K", function() 69 | state.tab = "Keystrokes" 70 | volt.redraw(state.statsbuf, "all") 71 | end, { buffer = state.statsbuf }) 72 | 73 | vim.keymap.set("n", "H", function() 74 | state.tab = " History" 75 | volt.redraw(state.statsbuf, "all") 76 | end, { buffer = state.statsbuf }) 77 | 78 | vim.keymap.set("n", "", function() 79 | state.horiz_i = state.horiz_i == 3 and 1 or state.horiz_i + 1 80 | volt.redraw(state.statsbuf, "all") 81 | end, { buffer = state.statsbuf }) 82 | 83 | vim.bo[state.statsbuf].filetype = "typrstats" 84 | 85 | -- vim.api.nvim_create_autocmd("VimResized", { 86 | -- group = vim.api.nvim_create_augroup("TyprResize", {}), 87 | -- callback = function() 88 | -- if state.config.winlayout == "responsive" then 89 | -- state.winlayout = vim.o.columns > ((2 * state.w) + 10) and "horizontal" or "vertical" 90 | -- state.h = state.h == 40 and 36 or 40 91 | -- 92 | -- vim.bo[state.statsbuf].modifiable = true 93 | -- require("volt").set_empty_lines(state.statsbuf, state.h, 1) 94 | -- vim.bo[state.statsbuf].modifiable = false 95 | -- 96 | -- utils.init_volt() 97 | -- volt.redraw(state.statsbuf, "all") 98 | -- end 99 | -- 100 | -- local conf = utils.make_winconf() 101 | -- api.nvim_win_set_config(state.win, conf) 102 | -- api.nvim_win_set_hl_ns(state.win, state.ns) 103 | -- end, 104 | -- }) 105 | end 106 | 107 | return M 108 | -------------------------------------------------------------------------------- /lua/typr/stats/keystrokes.lua: -------------------------------------------------------------------------------- 1 | local state = require "typr.state" 2 | local config = state.config 3 | local voltui = require "volt.ui" 4 | local kblayouts = require "typr.constants.kblayouts" 5 | 6 | local border_chars = { 7 | mid = { top = "┬", bot = "┴", none = "┼" }, 8 | corners_left = { top = "┌", bot = "└", none = "├" }, 9 | corners_right = { top = "┐", bot = "┘", none = "┤" }, 10 | vline = "│", 11 | } 12 | 13 | local keys_accuracy = function() 14 | local data = state.data.char_accuracy 15 | local lines = {} 16 | local line = string.rep("─", (10 * 4) + 1) 17 | 18 | local keys = {} 19 | for k, v in pairs(data) do 20 | table.insert(keys, { k, v }) 21 | end 22 | 23 | table.sort(keys, function(a, b) 24 | return a[2] < b[2] 25 | end) 26 | 27 | local kblayout = type(config.kblayout) == "table" and config.kblayout or kblayouts[config.kblayout] 28 | 29 | for i, v in ipairs(kblayout) do 30 | local row = {} 31 | 32 | for _, letter in ipairs(v) do 33 | local score = data[letter] or 100 34 | local hl = score == 100 and "TyprGrey" or "TyprRed" 35 | 36 | if score > 90 and score < 100 then 37 | hl = "TyprYellow" 38 | end 39 | 40 | table.insert(row, { " " .. letter:upper() .. " ", hl }) 41 | table.insert(row, { " " }) 42 | end 43 | 44 | table.remove(row) 45 | 46 | if i ~= 1 then 47 | table.insert(lines, { { border_chars.corners_left.none .. line .. border_chars.corners_right.none, "linenr" } }) 48 | end 49 | 50 | table.insert(row, 1, { border_chars.vline .. " ", "linenr" }) 51 | table.insert(row, { " " .. border_chars.vline, "linenr" }) 52 | table.insert(lines, row) 53 | 54 | if i == 1 then 55 | table.insert(lines, 1, { { border_chars.corners_left.top .. line .. border_chars.corners_right.top, "linenr" } }) 56 | elseif i == 3 then 57 | table.insert(lines, { { border_chars.corners_left.bot .. line .. border_chars.corners_right.bot, "linenr" } }) 58 | end 59 | end 60 | 61 | table.insert(lines, 1, { { "  Average of Key Accuracies" } }) 62 | 63 | if state.winlayout == "horizontal" then 64 | table.insert(lines[1], { " " }) 65 | 66 | local virts = 67 | { { " Ctrl ", "visual" }, { " + ", "comment" }, { " t ", "visual" }, { " Cycle panes ", "commentfg" } } 68 | 69 | for _, v in ipairs(virts) do 70 | table.insert(lines[1], v) 71 | end 72 | end 73 | 74 | local worst_keys = "" 75 | if #keys >= 3 then 76 | worst_keys = keys[1][1] .. " " .. keys[2][1] .. " " .. keys[3][1] 77 | else 78 | worst_keys = "No Data" 79 | end 80 | 81 | local indicators = { 82 | { { "󱓻 ", "commentfg" }, { "100% accuracy!" } }, 83 | { { "󱓻 ", "exyellow" }, { "Less than 90%" } }, 84 | { { "󱓻 ", "exred" }, { "Less than 80%" } }, 85 | { { "" } }, 86 | { { "Top worst keys: ", "exred" }, { worst_keys, "exlightgrey" } }, 87 | } 88 | 89 | voltui.border(indicators, "exred") 90 | table.insert(indicators, 1, {}) 91 | 92 | return voltui.grid_col { 93 | { lines = lines, w = state.w_with_pad - 32, pad = 1 }, 94 | { lines = indicators, w = 20 }, 95 | } 96 | end 97 | 98 | local slice_tb = function(tb, start, stop) 99 | local result = {} 100 | local start_i = start > stop and -1 or 1 101 | 102 | for i = start, stop, start_i do 103 | table.insert(result, tb[i]) 104 | end 105 | 106 | return result 107 | end 108 | 109 | local key_word_stats = function(w) 110 | local words = state.data.word_stats 111 | local keys = state.data.char_stats 112 | local wordavg = ((words.all - words.wrong) / words.all) * 100 113 | local charavg = ((keys.all - keys.wrong) / keys.all) * 100 114 | 115 | local tb = { 116 | { 117 | "Total", 118 | { { " Correct", "exgreen" } }, 119 | { { " Wrong", "exred" } }, 120 | "Avg", 121 | }, 122 | 123 | { words.all, words.all - words.wrong, words.wrong, math.floor(wordavg) }, 124 | } 125 | 126 | local wordStats = voltui.table(tb, w, "normal", { "  Overall word stats" }) 127 | 128 | local tb2 = { 129 | { 130 | "Total", 131 | { { " Correct", "exgreen" } }, 132 | { { " Wrong", "exred" } }, 133 | "Avg", 134 | }, 135 | 136 | { keys.all, keys.all - keys.wrong, keys.wrong, math.floor(charavg) }, 137 | } 138 | 139 | local keyStats = voltui.table(tb2, w, "normal") 140 | 141 | local progressTxt = " Keystrokes " 142 | 143 | local progressbar = voltui.progressbar { 144 | w = w - 2 - #progressTxt, 145 | val = state.data.accuracy, 146 | hl = { on = "exblue" }, 147 | icon = { on = "|", off = "|" }, 148 | } 149 | 150 | table.insert(progressbar, 1, { progressTxt }) 151 | 152 | progressbar = { progressbar } 153 | 154 | voltui.border(progressbar) 155 | 156 | return voltui.grid_row { 157 | wordStats, 158 | progressbar, 159 | keyStats, 160 | } 161 | end 162 | 163 | local char_times = function() 164 | local char_times = state.data.char_times 165 | 166 | local list = {} 167 | 168 | for k, v in pairs(char_times) do 169 | v = math.floor(v) 170 | table.insert(list, { k, v }) 171 | end 172 | 173 | table.sort(list, function(a, b) 174 | return a[2] > b[2] 175 | end) 176 | 177 | local tb1 = slice_tb(list, 1, 5) 178 | table.insert(tb1, 1, { "Key", "Avg" }) 179 | 180 | tb1 = vim.tbl_map(function(x) 181 | return { { { x[1], "exred" } }, x[2] } 182 | end, tb1) 183 | 184 | local tb2 = slice_tb(list, #list, #list - 4) 185 | table.insert(tb2, 1, { "Key", "Avg" }) 186 | 187 | tb2 = vim.tbl_map(function(x) 188 | return { { { x[1], "exblue" } }, x[2] } 189 | end, tb2) 190 | 191 | local slowest_keys_ui = voltui.table(tb1, "fit", "normal", { "Slowest keys" }) 192 | local fastest_keys_ui = voltui.table(tb2, "fit", "normal", { "Fastest keys" }) 193 | 194 | local w1 = voltui.line_w(slowest_keys_ui[1]) 195 | local w2 = voltui.line_w(fastest_keys_ui[1]) 196 | local w3 = state.w_with_pad - w1 - w2 - 4 197 | 198 | return voltui.grid_col { 199 | { lines = slowest_keys_ui, pad = 2, w = w1 }, 200 | { lines = fastest_keys_ui, pad = 2, w = w2 }, 201 | { lines = key_word_stats(w3), w = w3 }, 202 | } 203 | end 204 | 205 | local year = os.date "%Y" 206 | 207 | local getday_i = function(day, month) 208 | return tonumber(os.date("%w", os.time { year = tostring(year), month = month, day = day })) + 1 209 | end 210 | 211 | local double_digits = function(day) 212 | return day > 10 and day or "0" .. day 213 | end 214 | 215 | local get_activity_hl = function(n) 216 | if n > 20 then 217 | return "0" 218 | elseif n > 10 then 219 | return "1" 220 | elseif n > 0 then 221 | return "2" 222 | else 223 | return "3" 224 | end 225 | end 226 | 227 | local activity_heatmap = function() 228 | local months = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" } 229 | local days_in_months = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } 230 | local days = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" } 231 | 232 | local four_colors = { "red", "green", "blue", "yellow" } 233 | local monthshl = vim.list_extend(vim.list_extend(four_colors, four_colors), four_colors) 234 | 235 | local months_i = state.months_toggled and 6 or 1 236 | local months_end = (months_i + 6) 237 | local months_to_show = 7 238 | local squares_len = months_to_show * 4 239 | 240 | local lines = { 241 | { { "  ", "exgreen" }, { " " } }, 242 | {}, 243 | } 244 | 245 | for i = months_i, months_end do 246 | local hl = "ex" .. monthshl[i] 247 | table.insert(lines[1], { " " .. months[i] .. " ", hl }) 248 | table.insert(lines[1], { i == months_end and "" or " " }) 249 | end 250 | 251 | local hrline = voltui.separator("─", squares_len * 2 + (months_to_show - 1 + 5), "exlightgrey") 252 | table.insert(lines[2], hrline[1]) 253 | 254 | for day = 1, 7 do -- 7 weakdays 255 | local line = { { days[day], "exlightgrey" }, { " │ ", "linenr" } } 256 | table.insert(lines, line) 257 | end 258 | 259 | for i = months_i, months_end do 260 | local month_i = i 261 | 262 | local start_day = getday_i(1, month_i) 263 | if start_day ~= 1 and month_i == 1 then 264 | for n = 1, start_day - 1 do 265 | table.insert(lines[n + 2], { " " }) 266 | end 267 | end 268 | 269 | for n = 1, days_in_months[month_i] do 270 | local day = getday_i(n, month_i) 271 | local key = double_digits(n) .. double_digits(month_i) .. year 272 | 273 | local activity = state.data.activity[key] or 0 274 | local hl = "Typr" .. monthshl[month_i] .. get_activity_hl(activity) 275 | hl = activity == 0 and "Linenr" or hl 276 | 277 | table.insert(lines[day + 2], { "󱓻" .. " ", hl }) 278 | end 279 | end 280 | 281 | voltui.border(lines) 282 | 283 | local header = { 284 | { "  Activity" }, 285 | { " " }, 286 | { " TAB ", "lazyh1" }, 287 | { " " }, 288 | { "Toggle Months", "commentfg" }, 289 | { "_pad_" }, 290 | { " Less " }, 291 | } 292 | 293 | local hlgroups = { "linenr", "typrgreen3", "typrgreen2", "typrgreen1", "typrgreen0" } 294 | 295 | for _, v in ipairs(hlgroups) do 296 | table.insert(header, { "󱓻 ", v }) 297 | end 298 | 299 | table.insert(header, { " More" }) 300 | table.insert(lines, 1, voltui.hpad(header, 80)) 301 | 302 | return lines 303 | end 304 | 305 | return function() 306 | return require("volt.ui").grid_row { 307 | keys_accuracy(), 308 | { {} }, 309 | char_times(), 310 | { {} }, 311 | activity_heatmap(), 312 | } 313 | end 314 | -------------------------------------------------------------------------------- /lua/typr/stats/layout.lua: -------------------------------------------------------------------------------- 1 | local dashboard = require "typr.stats.dashboard" 2 | local keystrokes = require "typr.stats.keystrokes" 3 | local voltui = require "volt.ui" 4 | local state = require "typr.state" 5 | local history = require "typr.stats.history" 6 | 7 | local components = { 8 | [" Dashboard"] = dashboard, 9 | Keystrokes = keystrokes, 10 | [" History"] = history, 11 | } 12 | 13 | local divider = function() 14 | local result = {} 15 | 16 | for _ = 1, state.h do 17 | table.insert(result, { { "│", "linenr" } }) 18 | end 19 | 20 | return result 21 | end 22 | 23 | local horiz_layout = { 24 | { 25 | name = "typrStats", 26 | lines = function() 27 | local view_order = { dashboard, keystrokes, history } 28 | local i = state.horiz_i 29 | local i2 = i == 3 and 1 or i + 1 30 | 31 | return voltui.grid_col { 32 | { lines = view_order[i](), w = state.w_with_pad, pad = 2 }, 33 | { lines = divider(), pad = 2, w = 1 }, 34 | { lines = view_order[i2](), w = state.w_with_pad }, 35 | } 36 | end, 37 | }, 38 | } 39 | 40 | local vertical_layout = { 41 | { 42 | lines = function() 43 | local data = { " Dashboard", "Keystrokes", "_pad_", " History" } 44 | return voltui.tabs(data, state.w_with_pad, { active = state.tab }) 45 | end, 46 | name = "tabs", 47 | }, 48 | 49 | { 50 | lines = function() 51 | return { {} } 52 | end, 53 | name = "emptyline", 54 | }, 55 | 56 | { 57 | lines = function() 58 | return components[state.tab]() 59 | end, 60 | name = "typrStats", 61 | }, 62 | } 63 | 64 | return { 65 | vertical = vertical_layout, 66 | horizontal = horiz_layout, 67 | } 68 | -------------------------------------------------------------------------------- /lua/typr/stats/utils.lua: -------------------------------------------------------------------------------- 1 | local M = {} 2 | local state = require "typr.state" 3 | local layout = require "typr.stats.layout" 4 | 5 | M.gen_default_stats = function() 6 | local default_stats = { 7 | times = 0, 8 | total_secs = 0, 9 | wpm = { avg = 0, max = 0, min = 0 }, 10 | rawpm = { avg = 0, max = 0, min = 0 }, 11 | accuracy = 0, 12 | rawpm_hist = {}, 13 | wpm_hist = {}, 14 | accuracy_hist = {}, 15 | char_accuracy = {}, 16 | char_times = {}, 17 | char_stats = { all = 0, wrong = 0 }, 18 | word_stats = { all = 0, wrong = 0 }, 19 | test_history = {}, 20 | activity = {}, 21 | } 22 | 23 | for i = 1, 32 do 24 | if i <= 10 then 25 | table.insert(default_stats.wpm_hist, 0) 26 | table.insert(default_stats.accuracy_hist, 0) 27 | end 28 | 29 | table.insert(default_stats.rawpm_hist, 0) 30 | end 31 | 32 | for _ = 1, 8 do 33 | table.insert(default_stats.test_history, { wpm = 0, rawpm = 0, accuracy = 0, time = 0 }) 34 | end 35 | 36 | return default_stats 37 | end 38 | 39 | M.save_str_tofile = function(tb) 40 | local str = "'" .. vim.json.encode(tb) .. "'" 41 | 42 | local data = "return string.dump(function()return" .. str .. "end, true)" 43 | local path = state.config.stats_filepath 44 | local file = io.open(path, "wb") 45 | file:write(loadstring(data)()) 46 | file:close() 47 | end 48 | 49 | M.restore_stats = function() 50 | local path = state.config.stats_filepath 51 | local ok, stats = pcall(dofile, path) 52 | 53 | if ok then 54 | state.data = vim.json.decode(stats) 55 | else 56 | state.data = M.gen_default_stats() 57 | M.save_str_tofile(state.data) 58 | end 59 | end 60 | 61 | M.save = function() 62 | local stats = state.stats 63 | local tmp = state.data 64 | 65 | tmp.times = tmp.times + 1 66 | local oldtimes = tmp.times - 1 67 | local times = tmp.times 68 | 69 | -- calc wpm 70 | tmp.wpm.avg = ((tmp.wpm.avg * oldtimes) + stats.wpm) / times 71 | tmp.wpm.avg = math.floor(tmp.wpm.avg) 72 | tmp.wpm.max = (stats.wpm > tmp.wpm.max and stats.wpm) or tmp.wpm.max 73 | 74 | if tmp.wpm.min == 0 then 75 | tmp.wpm.min = stats.wpm 76 | else 77 | tmp.wpm.min = (stats.wpm < tmp.wpm.min and stats.wpm) or tmp.wpm.min 78 | end 79 | 80 | table.insert(tmp.wpm_hist, stats.wpm) 81 | table.remove(tmp.wpm_hist, 1) 82 | 83 | -- calc rawpm 84 | tmp.rawpm.avg = ((tmp.rawpm.avg * oldtimes) + stats.rawpm) / times 85 | tmp.rawpm.avg = math.floor(tmp.rawpm.avg) 86 | tmp.rawpm.max = (stats.rawpm > tmp.rawpm.max and stats.rawpm) or tmp.rawpm.max 87 | 88 | table.insert(tmp.rawpm_hist, stats.rawpm) 89 | table.remove(tmp.rawpm_hist, 1) 90 | 91 | -- calc accuracy 92 | table.insert(tmp.accuracy_hist, stats.accuracy) 93 | table.remove(tmp.accuracy_hist, 1) 94 | 95 | -- accuracy average 96 | tmp.accuracy = ((tmp.accuracy * oldtimes) + stats.accuracy) / times 97 | tmp.accuracy = math.floor(tmp.accuracy) 98 | 99 | tmp.total_secs = tmp.total_secs + state.secs 100 | 101 | -- calc wrong chars 102 | for k, v in pairs(stats.char_accuracy) do 103 | local char_avg = tmp.char_accuracy[k] or 100 104 | 105 | tmp.char_accuracy[k] = ((char_avg * oldtimes) + v) / times 106 | tmp.char_accuracy[k] = math.floor(tmp.char_accuracy[k]) 107 | end 108 | 109 | -- calc char times 110 | for k, v in pairs(stats.char_times) do 111 | tmp.char_times[k] = ((tmp.char_times[k] or 0) + v) / times 112 | end 113 | 114 | tmp.char_stats = { 115 | all = tmp.char_stats.all + stats.char_stats.all, 116 | wrong = tmp.char_stats.wrong + stats.char_stats.wrong, 117 | } 118 | 119 | tmp.word_stats = { 120 | all = tmp.word_stats.all + stats.word_stats.all, 121 | wrong = tmp.word_stats.wrong + stats.word_stats.wrong, 122 | } 123 | 124 | table.insert(tmp.test_history, { 125 | wpm = stats.wpm, 126 | rawpm = stats.rawpm, 127 | accuracy = stats.accuracy, 128 | time = state.secs, 129 | }) 130 | 131 | table.remove(tmp.test_history, 1) 132 | 133 | local date = os.date "%d%m%Y" 134 | tmp.activity[date] = (tmp.activity[date] or 0) + 1 135 | 136 | state.data = tmp 137 | state.stats.char_times = {} 138 | 139 | M.save_str_tofile(tmp) 140 | end 141 | 142 | M.init_volt = function() 143 | require("volt").gen_data { 144 | { buf = state.statsbuf, layout = layout[state.winlayout], xpad = state.xpad, ns = state.ns }, 145 | } 146 | end 147 | 148 | M.make_winconf = function() 149 | local large_screen = state.h + 10 < vim.o.lines 150 | local h = large_screen and state.h or vim.o.lines - 7 151 | local winw = state.w 152 | 153 | if state.winlayout == "horizontal" then 154 | winw = winw * 2 155 | end 156 | 157 | return { 158 | row = large_screen and ((vim.o.lines / 2) - (state.h / 2)) or 2, 159 | col = (vim.o.columns / 2) - (winw / 2), 160 | width = winw, 161 | height = h, 162 | relative = "editor", 163 | style = "minimal", 164 | border = "single", 165 | zindex = 100, 166 | } 167 | end 168 | 169 | return M 170 | -------------------------------------------------------------------------------- /lua/typr/ui/hl.lua: -------------------------------------------------------------------------------- 1 | local lighten = require("volt.color").change_hex_lightness 2 | local mix = require("volt.color").mix 3 | local api = vim.api 4 | 5 | local hexadecimal_to_hex = function(hex) 6 | return "#" .. ("%06x"):format(hex == nil and 0 or hex) 7 | end 8 | 9 | local function get_hl(name) 10 | local hl = api.nvim_get_hl(0, { name = name }) 11 | local result = {} 12 | 13 | if hl.fg ~= nil then 14 | result.fg = hexadecimal_to_hex(hl.fg) 15 | end 16 | 17 | if hl.bg ~= nil then 18 | result.bg = hexadecimal_to_hex(hl.bg) 19 | end 20 | 21 | return result 22 | end 23 | 24 | return function(ns, winType) 25 | local bg 26 | 27 | if vim.g.base46_cache then 28 | local colors = dofile(vim.g.base46_cache .. "colors") 29 | bg = colors.black 30 | else 31 | bg = get_hl("Normal").bg 32 | end 33 | 34 | local transparent = not bg 35 | 36 | if not transparent then 37 | bg = lighten(bg, 2) 38 | api.nvim_set_hl(ns, "TyprBorder", { fg = bg, bg = bg }) 39 | api.nvim_set_hl(ns, "TyprNormal", { bg = bg }) 40 | else 41 | bg = "#000000" 42 | end 43 | 44 | if winType ~= "stats" then 45 | return 46 | end 47 | 48 | local exred = get_hl("ExRed").fg 49 | api.nvim_set_hl(ns, "TyprRed", { bg = mix(exred, bg, 80), fg = exred }) 50 | 51 | local exgreen = get_hl("ExGreen").fg 52 | 53 | api.nvim_set_hl(ns, "TyprGreen", { bg = mix(exgreen, bg, 80), fg = exgreen }) 54 | api.nvim_set_hl(ns, "TyprGreen0", { fg = mix(exgreen, bg, 10) }) 55 | api.nvim_set_hl(ns, "TyprGreen1", { fg = mix(exgreen, bg, 40) }) 56 | api.nvim_set_hl(ns, "TyprGreen2", { fg = mix(exgreen, bg, 60) }) 57 | api.nvim_set_hl(ns, "TyprGreen3", { fg = mix(exgreen, bg, 80) }) 58 | 59 | local exblue = get_hl("ExBlue").fg 60 | api.nvim_set_hl(ns, "TyprBlue", { bg = mix(exblue, bg, 80), fg = exblue }) 61 | api.nvim_set_hl(ns, "TyprBlue0", { fg = mix(exblue, bg, 10) }) 62 | api.nvim_set_hl(ns, "TyprBlue1", { fg = mix(exblue, bg, 40) }) 63 | api.nvim_set_hl(ns, "TyprBlue2", { fg = mix(exblue, bg, 60) }) 64 | api.nvim_set_hl(ns, "TyprBlue3", { fg = mix(exblue, bg, 80) }) 65 | 66 | api.nvim_set_hl(ns, "TyprRed0", { fg = mix(exred, bg, 10) }) 67 | api.nvim_set_hl(ns, "TyprRed1", { fg = mix(exred, bg, 40) }) 68 | api.nvim_set_hl(ns, "TyprRed2", { fg = mix(exred, bg, 60) }) 69 | api.nvim_set_hl(ns, "TyprRed3", { fg = mix(exred, bg, 80) }) 70 | 71 | local exyellow = get_hl("ExYellow").fg 72 | api.nvim_set_hl(ns, "TyprYellow0", { fg = mix(exyellow, bg, 10) }) 73 | api.nvim_set_hl(ns, "TyprYellow1", { fg = mix(exyellow, bg, 40) }) 74 | api.nvim_set_hl(ns, "TyprYellow2", { fg = mix(exyellow, bg, 60) }) 75 | api.nvim_set_hl(ns, "TyprYellow3", { fg = mix(exyellow, bg, 80) }) 76 | 77 | -- local exyellow = get_hl("ExYellow").fg 78 | api.nvim_set_hl(ns, "TyprYellow", { bg = mix(exyellow, bg, 80, transparent), fg = exyellow }) 79 | 80 | local x = vim.o.bg == "dark" and 1 or -1 81 | 82 | local commentfg = get_hl("comment").fg 83 | 84 | if transparent then 85 | api.nvim_set_hl(ns, "TyprGrey", { bg = lighten(commentfg, -22) }) 86 | else 87 | api.nvim_set_hl(ns, "TyprGrey", { bg = lighten(bg, 6 * x), fg = lighten(commentfg, 10 * x) }) 88 | end 89 | end 90 | -------------------------------------------------------------------------------- /lua/typr/ui/init.lua: -------------------------------------------------------------------------------- 1 | local M = {} 2 | local state = require "typr.state" 3 | local voltui = require "volt.ui" 4 | 5 | M.words = function() 6 | return state.ui_lines 7 | end 8 | 9 | M.headerbtns = function() 10 | local config = state.config 11 | 12 | local line = { 13 | { " Symbols ", config.symbols and "exgreen" or "normal" }, 14 | { "  Numbers ", config.numbers and "exgreen" or "normal" }, 15 | { "  Random ", config.random and "exgreen" or "normal" }, 16 | { "  Phrases ", config.mode == 'phrases' and "exgreen" or "normal" }, 17 | { "_pad_" }, 18 | { "Lines ", "exred" }, 19 | { " 3 *", state.linecount == 3 and "" or "commentfg" }, 20 | { " 6 *", state.linecount == 6 and "" or "commentfg" }, 21 | { " 9", state.linecount == 9 and "" or "commentfg" }, 22 | } 23 | 24 | local lines = { voltui.hpad(line, state.w + 1) } 25 | voltui.border(lines) 26 | return lines 27 | end 28 | 29 | M.stats = function() 30 | local stats = state.stats 31 | 32 | if state.secs == 0 then 33 | return { {}, {} } 34 | end 35 | 36 | if stats.rawpm == 0 then 37 | return { 38 | { { string.rep(" ", (state.w_with_pad / 2) - 3) }, { " " .. state.secs .. "s " } }, 39 | } 40 | end 41 | 42 | local txts = { 43 | { "Results:", "Added" }, 44 | { " Words : " .. stats.correct_word_ratio }, 45 | { "  Accuracy: " .. stats.accuracy .. "%" }, 46 | { "_pad_" }, 47 | { "  " .. state.secs .. "s " }, 48 | { " WPM ", "pmenusel" }, 49 | { " " .. stats.wpm .. " ", "visual" }, 50 | } 51 | 52 | local totalstrlen = 0 53 | 54 | for _, v in ipairs(txts) do 55 | totalstrlen = totalstrlen + vim.api.nvim_strwidth(v[1]) 56 | end 57 | 58 | local lines = { voltui.hpad(txts, state.w + 1) } 59 | voltui.border(lines) 60 | table.insert(lines, {}) 61 | return lines 62 | end 63 | 64 | M.mappings = function() 65 | return { 66 | { 67 | { " ESC ", "visual" }, 68 | { " or ", "commentfg" }, 69 | { " q ", "visual" }, 70 | { " - Quit ", "commentfg" }, 71 | 72 | { " " }, 73 | 74 | { " i ", "visual" }, 75 | { " - Start ", "commentfg" }, 76 | 77 | { " " }, 78 | 79 | { " CTRL ", "visual" }, 80 | { " " }, 81 | { " R ", "visual" }, 82 | { " - Restart ", "commentfg" }, 83 | }, 84 | } 85 | end 86 | 87 | return M 88 | -------------------------------------------------------------------------------- /lua/typr/ui/layout.lua: -------------------------------------------------------------------------------- 1 | local ui = require "typr.ui" 2 | 3 | local empty_line = { 4 | lines = function() 5 | return { {} } 6 | end, 7 | name = "emptyline", 8 | } 9 | 10 | return { 11 | { 12 | lines = ui.headerbtns, 13 | name = "headerbtns", 14 | }, 15 | 16 | empty_line, 17 | 18 | { 19 | lines = ui.words, 20 | name = "words", 21 | }, 22 | 23 | empty_line, 24 | 25 | { 26 | lines = ui.stats, 27 | name = "stats", 28 | }, 29 | 30 | { 31 | lines = ui.mappings, 32 | name = "mappings", 33 | }, 34 | } 35 | -------------------------------------------------------------------------------- /lua/typr/utils.lua: -------------------------------------------------------------------------------- 1 | local M = {} 2 | local state = require "typr.state" 3 | local words = require "typr.constants.words" 4 | local phrases = require "typr.constants.phrases" 5 | local volt = require "volt" 6 | 7 | local symbols = { 8 | "!", 9 | '"', 10 | "#", 11 | "$", 12 | "%", 13 | "&", 14 | "'", 15 | "(", 16 | ")", 17 | "*", 18 | "+", 19 | ",", 20 | "-", 21 | ".", 22 | "/", 23 | ":", 24 | ";", 25 | "<", 26 | "=", 27 | ">", 28 | "?", 29 | "@", 30 | "[", 31 | "\\", 32 | "]", 33 | "^", 34 | "_", 35 | "`", 36 | "{", 37 | "|", 38 | "}", 39 | "~", 40 | } 41 | 42 | local punct_symbolslen = #symbols 43 | 44 | local gen_random_word = function() 45 | local word = "" 46 | local length = math.random(1, 7) 47 | 48 | for _ = 1, length do 49 | local randomChar = string.char(math.random(97, 122)) 50 | word = word .. randomChar 51 | end 52 | 53 | return word 54 | end 55 | 56 | M.gen_word = function() 57 | local word 58 | local frequency = math.random(1, 4) 59 | local config = state.config 60 | local wordslen = #words 61 | 62 | if frequency == 4 and state.config.numbers then 63 | word = tostring(math.random(1, 1000)) 64 | else 65 | word = config.random and gen_random_word() or words[math.random(1, wordslen)] 66 | end 67 | 68 | if state.config.symbols then 69 | local tmp_i = math.random(0, punct_symbolslen) 70 | local symbol = tmp_i > 0 and symbols[tmp_i] or "" 71 | word = word .. symbol 72 | end 73 | 74 | return word 75 | end 76 | 77 | M.words_to_lines = function() 78 | local lines = {} 79 | local maxw = state.w_with_pad 80 | 81 | for i = 1, state.linecount do 82 | local lineWords = {} 83 | local lineLength = 0 84 | 85 | while lineLength < maxw do 86 | local word = M.gen_word() 87 | if lineLength + #word + 1 > maxw then 88 | break 89 | end 90 | table.insert(lineWords, word) 91 | lineLength = lineLength + #word + 1 -- +1 for the space 92 | end 93 | 94 | local str = table.concat(lineWords, " ") 95 | if i < state.linecount then 96 | str = str .. " " 97 | end 98 | table.insert(lines, str) 99 | end 100 | 101 | return lines 102 | end 103 | 104 | M.phrases_to_lines = function() 105 | local data = state.config.phrases or phrases 106 | local maxw = state.w_with_pad 107 | local datalen = #data 108 | local phrase = data[math.random(1, datalen)] 109 | local lines = { "" } 110 | 111 | while state.linecount >= #lines do 112 | for _, v in ipairs(vim.split(phrase, " ")) do 113 | local arrlen = #lines 114 | local lastline_len = #lines[arrlen] 115 | 116 | if lastline_len + #v + 2 > maxw then 117 | local space = arrlen == state.linecount and "" or " " 118 | lines[arrlen] = lines[arrlen] .. space 119 | table.insert(lines, v) 120 | else 121 | local space = lastline_len == 0 and "" or " " 122 | lines[arrlen] = lines[arrlen] .. space .. v 123 | end 124 | end 125 | 126 | phrase = data[math.random(1, datalen)] 127 | end 128 | 129 | return vim.list_slice(lines, 1, state.linecount) 130 | end 131 | 132 | M.mode_funcs = { 133 | words = M.words_to_lines, 134 | phrases = M.phrases_to_lines, 135 | } 136 | 137 | M.gen_default_lines = function() 138 | state.default_lines = M.mode_funcs[state.config.mode]() 139 | 140 | local ui_lines = {} 141 | 142 | for _, v in ipairs(state.default_lines) do 143 | local line = {} 144 | for word in string.gmatch(v, "%S+") do 145 | table.insert(line, { word .. " ", "commentfg" }) 146 | end 147 | 148 | table.insert(ui_lines, line) 149 | end 150 | 151 | state.ui_lines = ui_lines 152 | end 153 | 154 | M.gen_lines_diff = function(line, userline) 155 | local result = {} 156 | local userlinelen = #userline 157 | local croppedline = line:sub(1, userlinelen) 158 | 159 | for i = 1, #croppedline do 160 | local char = line:sub(i, i) 161 | local expected = userline:sub(i, i) 162 | 163 | local status = char == expected and "Added" or "Removed" 164 | 165 | local resultlen = #result 166 | 167 | if expected ~= char and expected == " " then 168 | expected = "x" 169 | end 170 | 171 | if resultlen > 0 and result[resultlen][2] == status then 172 | result[resultlen][1] = result[resultlen][1] .. expected 173 | else 174 | table.insert(result, { expected, status }) 175 | end 176 | end 177 | 178 | table.insert(result, { line:sub(#userline + 1), "commentfg" }) 179 | 180 | return result 181 | end 182 | 183 | M.count_correct_words = function() 184 | local count = 0 185 | local unmatched_count = 0 186 | local curchar_count = 0 187 | local total_char_count = 0 188 | local userlines = {} 189 | 190 | for _, line in ipairs(state.ui_lines) do 191 | userlines = vim.list_extend(userlines, line) 192 | end 193 | 194 | for _, v in ipairs(userlines) do 195 | local wordslen = #vim.split(v[1], " ") 196 | 197 | if v[2] == "Added" then 198 | count = count + wordslen 199 | curchar_count = curchar_count + #v[1] 200 | elseif v[2] == "Removed" and v[1] ~= " " and v[1] ~= "" then 201 | unmatched_count = unmatched_count + wordslen 202 | end 203 | 204 | total_char_count = total_char_count + #v[1] 205 | end 206 | 207 | local total_words = count + unmatched_count 208 | state.stats.correct_word_ratio = count .. " / " .. total_words 209 | state.stats.word_stats = { all = total_words, wrong = unmatched_count } 210 | state.stats.wpm = math.floor(((curchar_count / 5) / state.secs) * 60) 211 | state.stats.rawpm = math.floor(((total_char_count / 5) / state.secs) * 60) 212 | end 213 | 214 | M.get_accuracy = function() 215 | local lines = state.ui_lines 216 | local mystr = "" 217 | 218 | for _, line in ipairs(lines) do 219 | for _, val in ipairs(line) do 220 | if val[2] == "Added" then 221 | mystr = mystr .. val[1] 222 | end 223 | end 224 | end 225 | 226 | local mystrlen = #mystr 227 | local total_char_count = #table.concat(state.default_lines) 228 | local accuracy = (mystrlen / total_char_count) * 100 229 | 230 | state.stats.accuracy = math.floor(accuracy) 231 | state.stats.total_char_count = total_char_count 232 | state.stats.typed_char_count = mystrlen 233 | end 234 | 235 | M.char_accuracy = function() 236 | local userlines = vim.tbl_map(function(line) 237 | local userwords = vim.tbl_map(function(v) 238 | return v[1] 239 | end, line) 240 | 241 | local userstrs = table.concat(userwords, "") 242 | 243 | return vim.split(userstrs, "") 244 | end, state.ui_lines) 245 | 246 | local default_lines = vim.tbl_map(function(line) 247 | return vim.split(line, "") 248 | end, state.default_lines) 249 | 250 | local wrongchars = {} 251 | local wrongchars_count = 0 252 | local totalchars_count = 0 253 | local rightchars = {} 254 | local result = {} 255 | 256 | for i, line in ipairs(default_lines) do 257 | for j, char in ipairs(line) do 258 | totalchars_count = totalchars_count + 1 259 | if userlines[i][j] == char then 260 | rightchars[char] = (rightchars[char] or 0) + 1 261 | else 262 | wrongchars[char] = (wrongchars[char] or 0) + 1 263 | wrongchars_count = wrongchars_count + 1 264 | end 265 | end 266 | end 267 | 268 | state.stats.char_stats = { all = totalchars_count, wrong = wrongchars_count } 269 | 270 | for key, val in pairs(rightchars) do 271 | local sum = (wrongchars[key] or 0) + val 272 | result[key] = math.floor((val / sum) * 100) 273 | end 274 | 275 | state.stats.char_accuracy = result 276 | end 277 | 278 | M.char_times_calc = function() 279 | local t = state.stats.char_times 280 | 281 | local chars = {} 282 | local pressed = {} 283 | 284 | for _, v in ipairs(t) do 285 | if v[1] ~= "" and v[1] ~= " " then 286 | chars[v[1]] = (chars[v[1]] or 0) + v[2] 287 | pressed[v[1]] = (pressed[v[1]] or 0) + 1 288 | end 289 | end 290 | 291 | for k, v in pairs(chars) do 292 | chars[k] = v / pressed[k] 293 | end 294 | 295 | state.stats.char_times = chars 296 | end 297 | 298 | M.start_timer = function() 299 | state.timer:start( 300 | 0, 301 | 1000, 302 | vim.schedule_wrap(function() 303 | state.secs = state.secs + 1 304 | volt.redraw(state.buf, "stats") 305 | end) 306 | ) 307 | end 308 | 309 | M.set_emptylines = function() 310 | local maxline = (state.linecount + state.words_row) 311 | state.words_row_end = maxline 312 | 313 | local lines = {} 314 | 315 | for i = 1, state.h do 316 | local str = (i > state.words_row and i <= maxline) and "" or string.rep(" ", state.w_with_pad) 317 | table.insert(lines, str) 318 | end 319 | 320 | vim.api.nvim_buf_set_lines(state.buf, 0, -1, false, lines) 321 | end 322 | 323 | M.on_finish = function() 324 | state.timer:stop() 325 | vim.cmd.stopinsert() 326 | 327 | state.h = state.h + 2 328 | vim.api.nvim_win_set_height(state.win, state.h) 329 | 330 | vim.schedule(function() 331 | M.get_accuracy() 332 | M.count_correct_words() 333 | M.char_accuracy() 334 | M.char_times_calc() 335 | 336 | M.set_emptylines() 337 | require("typr").initialize_volt() 338 | volt.redraw(state.buf, "all") 339 | 340 | require("typr.stats.utils").save() 341 | end) 342 | end 343 | 344 | M.handle_test_end = function() 345 | local pos = vim.api.nvim_win_get_cursor(state.win) 346 | local curline_endcol = #state.default_lines[pos[1] - state.words_row] 347 | local cur_col = pos[2] - 1 348 | 349 | if cur_col == curline_endcol then 350 | if state.words_row_end == pos[1] then 351 | M.on_finish() 352 | return 353 | end 354 | 355 | vim.schedule(function() 356 | vim.api.nvim_win_set_cursor(state.win, { pos[1] + 1, state.xpad }) 357 | end) 358 | end 359 | end 360 | 361 | return M 362 | -------------------------------------------------------------------------------- /plugin/typr.lua: -------------------------------------------------------------------------------- 1 | vim.api.nvim_create_user_command("Typr", function() 2 | require("typr").open() 3 | end, {}) 4 | 5 | vim.api.nvim_create_user_command("TyprStats", function() 6 | require("typr.stats").open() 7 | end, {}) 8 | --------------------------------------------------------------------------------