├── .gitattributes
├── .gitignore
├── .vscode
└── settings.json
├── LICENSE
├── README.md
├── examples
├── default.py
└── filesystem.py
├── poetry.lock
├── pyproject.toml
└── src
└── ctui
├── __init__.py
├── application.py
├── base.py
├── commands.py
├── completion.py
├── dialogs.py
├── functions.py
├── kaitai
└── velocio.ksy
├── keybindings.py
├── layout.py
├── style.py
└── types.py
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .venv
2 | .DS_Store
3 | dist/
4 | build/
5 | .mypy_cache/
6 | *.pyc
7 | */__pycache__/
8 | *.egg-info/
9 |
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "python.pythonPath": ".venv/bin/python",
3 | "python.linting.pylintEnabled": true,
4 | "python.linting.enabled": true,
5 | "python.formatting.provider": "black",
6 | "editor.formatOnSave": true,
7 | "[python]": {
8 | "editor.codeActionsOnSave": {
9 | "source.organizeImports": "explicit"
10 | }
11 | },
12 | "cSpell.enabled": false
13 | }
--------------------------------------------------------------------------------
/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 | {one line to give the program's name and a brief idea of what it does.}
635 | Copyright (C) 2018 {name of author}
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 | ct-samples Copyright (C) 2018 meeas
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 | # ControlThings User Interface
2 |
3 | The `ctui` is a library for creating terminal-based user interfaces, and is used in all the ControlThings tools at controlthings.io. It is similar to using Click or Python's standard Cmd library, but with a curses-like interface written in pure Python.
4 |
5 | # Installation
6 |
7 | Ctui is primarily developed on Linux, but should work in both Mac and Windows as well.
8 |
9 | As long as you have git and Python 3.6 or later installed, all you should need to do is:
10 |
11 | ```
12 | pip3 install ctui
13 | ```
14 |
15 | # Usage
16 |
17 | Import the library, instantiate a Ctui object, and start the ctui application, like:
18 |
19 | ```
20 | from ctui import Ctui
21 |
22 | myapp = Ctui()
23 | myapp.run()
24 | ```
25 |
26 | Of course you can configure you app in a number of different ways by modifying your app's attributes or by adding your own custom commands. Check out the `examples` folder to walk you through some of these. For more complex examples how to use ctui, check out the various ControlThings Tools, most of which use ctui. You can find these at .
27 |
28 | # Fork and Develop
29 |
30 | To set up a development environment for ctui, you will first need to install [Python Poetry]() which is used to manage all the project dependencies and publish the pypi packages. I strongly recommend checking out the website and at least reading through the [Basic Usage](https://python-poetry.org/docs/basic-usage/) page, but if you want the TLDR, just run:
31 |
32 | curl -sSL https://install.python-poetry.org | python3 -
33 |
34 | Once Poetry is installed, pull the repo and :
35 |
36 | git clone https://github.com/ControlThings-io/ctui.git
37 | cd ctui
38 | poetry install
39 | poetry shell
40 |
41 | That last command will open a shell in a python virtual environment where you can do live edits to the code. If you are a VS Code user, VS Code will automatically load the repo configs with all the linting rules I use through the repo, and should automatically open the debug tools and terminal inside the virtual environment.
42 |
43 | # Author
44 |
45 | * Justin Searle
46 |
--------------------------------------------------------------------------------
/examples/default.py:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2018 Justin Searle
2 | #
3 | # This program is free software: you can redistribute it and/or modify it under
4 | # the terms of the GNU General Public License as published by the Free Software
5 | # Foundation, either version 3 of the License, or any later version.
6 | #
7 | # This program is distributed in the hope that it will be useful, but WITHOUT
8 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
10 | # details at .
11 |
12 | from ctui import Ctui
13 |
14 | myapp = Ctui()
15 | myapp.run()
16 |
--------------------------------------------------------------------------------
/examples/filesystem.py:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2018 Justin Searle
2 | #
3 | # This program is free software: you can redistribute it and/or modify it under
4 | # the terms of the GNU General Public License as published by the Free Software
5 | # Foundation, either version 3 of the License, or any later version.
6 | #
7 | # This program is distributed in the hope that it will be useful, but WITHOUT
8 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
10 | # details at .
11 |
12 | import os
13 |
14 | from ctui.application import Ctui
15 |
16 | # from ctui.types import *
17 |
18 | # Add your own commands by extending the Ctui class
19 | myapp = Ctui()
20 |
21 | myapp.name = "ctui_filesystem"
22 | myapp.version = "0.1"
23 | myapp.description = "Example filesystem application using ctui"
24 | myapp.prompt = "fs> "
25 | myapp.help_message = "Type your Linux commands on top...\nresults appear on the bottom."
26 |
27 | # Each function representing a command must:
28 | # - start with a do_
29 | # - accept (self, args, output_text) as params
30 | # args: is the text the user passed to your command
31 | # output_text: is the current text in the window
32 | # - return a string to print, None, or False
33 | # Returning a False does nothing, forcing users to correct mistakes
34 |
35 |
36 | # Example of a command with no arguments
37 | @myapp.command
38 | def do_ls():
39 | """Help menu for ls.""" # <--- this will be used in help messages
40 | output_text = myapp.output_text # Grab existing output text
41 | output_text += "Contents of " + os.getcwd() + ":\n"
42 | # notice that we appended that text onto the existing output_text
43 | for item in os.listdir():
44 | output_text += " " + item + "\n"
45 | return output_text
46 |
47 |
48 | # Example of a command with 1 argument
49 | @myapp.command
50 | def do_cd(directory: str):
51 | """Help menu for cd.
52 |
53 | :PARAM dir: Directory to change into
54 | """
55 | try:
56 | os.chdir(directory)
57 | except FileNotFoundError:
58 | # Returning False on bad input forces users to edit their input
59 | return False
60 | output_text = myapp.output_text # Grab existing output text
61 | output_text = output_text + "Directory changed to " + os.getcwd() + "\n"
62 | return output_text
63 |
64 |
65 | myapp.run()
66 |
--------------------------------------------------------------------------------
/poetry.lock:
--------------------------------------------------------------------------------
1 | # This file is automatically @generated by Poetry 1.8.2 and should not be changed by hand.
2 |
3 | [[package]]
4 | name = "astroid"
5 | version = "2.15.8"
6 | description = "An abstract syntax tree for Python with inference support."
7 | optional = false
8 | python-versions = ">=3.7.2"
9 | files = [
10 | {file = "astroid-2.15.8-py3-none-any.whl", hash = "sha256:1aa149fc5c6589e3d0ece885b4491acd80af4f087baafa3fb5203b113e68cd3c"},
11 | {file = "astroid-2.15.8.tar.gz", hash = "sha256:6c107453dffee9055899705de3c9ead36e74119cee151e5a9aaf7f0b0e020a6a"},
12 | ]
13 |
14 | [package.dependencies]
15 | lazy-object-proxy = ">=1.4.0"
16 | typing-extensions = {version = ">=4.0.0", markers = "python_version < \"3.11\""}
17 | wrapt = [
18 | {version = ">=1.11,<2", markers = "python_version < \"3.11\""},
19 | {version = ">=1.14,<2", markers = "python_version >= \"3.11\""},
20 | ]
21 |
22 | [[package]]
23 | name = "black"
24 | version = "23.12.1"
25 | description = "The uncompromising code formatter."
26 | optional = false
27 | python-versions = ">=3.8"
28 | files = [
29 | {file = "black-23.12.1-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:e0aaf6041986767a5e0ce663c7a2f0e9eaf21e6ff87a5f95cbf3675bfd4c41d2"},
30 | {file = "black-23.12.1-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:c88b3711d12905b74206227109272673edce0cb29f27e1385f33b0163c414bba"},
31 | {file = "black-23.12.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:a920b569dc6b3472513ba6ddea21f440d4b4c699494d2e972a1753cdc25df7b0"},
32 | {file = "black-23.12.1-cp310-cp310-win_amd64.whl", hash = "sha256:3fa4be75ef2a6b96ea8d92b1587dd8cb3a35c7e3d51f0738ced0781c3aa3a5a3"},
33 | {file = "black-23.12.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:8d4df77958a622f9b5a4c96edb4b8c0034f8434032ab11077ec6c56ae9f384ba"},
34 | {file = "black-23.12.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:602cfb1196dc692424c70b6507593a2b29aac0547c1be9a1d1365f0d964c353b"},
35 | {file = "black-23.12.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9c4352800f14be5b4864016882cdba10755bd50805c95f728011bcb47a4afd59"},
36 | {file = "black-23.12.1-cp311-cp311-win_amd64.whl", hash = "sha256:0808494f2b2df923ffc5723ed3c7b096bd76341f6213989759287611e9837d50"},
37 | {file = "black-23.12.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:25e57fd232a6d6ff3f4478a6fd0580838e47c93c83eaf1ccc92d4faf27112c4e"},
38 | {file = "black-23.12.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:2d9e13db441c509a3763a7a3d9a49ccc1b4e974a47be4e08ade2a228876500ec"},
39 | {file = "black-23.12.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6d1bd9c210f8b109b1762ec9fd36592fdd528485aadb3f5849b2740ef17e674e"},
40 | {file = "black-23.12.1-cp312-cp312-win_amd64.whl", hash = "sha256:ae76c22bde5cbb6bfd211ec343ded2163bba7883c7bc77f6b756a1049436fbb9"},
41 | {file = "black-23.12.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:1fa88a0f74e50e4487477bc0bb900c6781dbddfdfa32691e780bf854c3b4a47f"},
42 | {file = "black-23.12.1-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:a4d6a9668e45ad99d2f8ec70d5c8c04ef4f32f648ef39048d010b0689832ec6d"},
43 | {file = "black-23.12.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b18fb2ae6c4bb63eebe5be6bd869ba2f14fd0259bda7d18a46b764d8fb86298a"},
44 | {file = "black-23.12.1-cp38-cp38-win_amd64.whl", hash = "sha256:c04b6d9d20e9c13f43eee8ea87d44156b8505ca8a3c878773f68b4e4812a421e"},
45 | {file = "black-23.12.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:3e1b38b3135fd4c025c28c55ddfc236b05af657828a8a6abe5deec419a0b7055"},
46 | {file = "black-23.12.1-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:4f0031eaa7b921db76decd73636ef3a12c942ed367d8c3841a0739412b260a54"},
47 | {file = "black-23.12.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:97e56155c6b737854e60a9ab1c598ff2533d57e7506d97af5481141671abf3ea"},
48 | {file = "black-23.12.1-cp39-cp39-win_amd64.whl", hash = "sha256:dd15245c8b68fe2b6bd0f32c1556509d11bb33aec9b5d0866dd8e2ed3dba09c2"},
49 | {file = "black-23.12.1-py3-none-any.whl", hash = "sha256:78baad24af0f033958cad29731e27363183e140962595def56423e626f4bee3e"},
50 | {file = "black-23.12.1.tar.gz", hash = "sha256:4ce3ef14ebe8d9509188014d96af1c456a910d5b5cbf434a09fef7e024b3d0d5"},
51 | ]
52 |
53 | [package.dependencies]
54 | click = ">=8.0.0"
55 | mypy-extensions = ">=0.4.3"
56 | packaging = ">=22.0"
57 | pathspec = ">=0.9.0"
58 | platformdirs = ">=2"
59 | tomli = {version = ">=1.1.0", markers = "python_version < \"3.11\""}
60 | typing-extensions = {version = ">=4.0.1", markers = "python_version < \"3.11\""}
61 |
62 | [package.extras]
63 | colorama = ["colorama (>=0.4.3)"]
64 | d = ["aiohttp (>=3.7.4)", "aiohttp (>=3.7.4,!=3.9.0)"]
65 | jupyter = ["ipython (>=7.8.0)", "tokenize-rt (>=3.2.0)"]
66 | uvloop = ["uvloop (>=0.15.2)"]
67 |
68 | [[package]]
69 | name = "click"
70 | version = "8.1.7"
71 | description = "Composable command line interface toolkit"
72 | optional = false
73 | python-versions = ">=3.7"
74 | files = [
75 | {file = "click-8.1.7-py3-none-any.whl", hash = "sha256:ae74fb96c20a0277a1d615f1e4d73c8414f5a98db8b799a7931d1582f3390c28"},
76 | {file = "click-8.1.7.tar.gz", hash = "sha256:ca9853ad459e787e2192211578cc907e7594e294c7ccc834310722b41b9ca6de"},
77 | ]
78 |
79 | [package.dependencies]
80 | colorama = {version = "*", markers = "platform_system == \"Windows\""}
81 |
82 | [[package]]
83 | name = "colorama"
84 | version = "0.4.6"
85 | description = "Cross-platform colored terminal text."
86 | optional = false
87 | python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7"
88 | files = [
89 | {file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"},
90 | {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"},
91 | ]
92 |
93 | [[package]]
94 | name = "dill"
95 | version = "0.3.8"
96 | description = "serialize all of Python"
97 | optional = false
98 | python-versions = ">=3.8"
99 | files = [
100 | {file = "dill-0.3.8-py3-none-any.whl", hash = "sha256:c36ca9ffb54365bdd2f8eb3eff7d2a21237f8452b57ace88b1ac615b7e815bd7"},
101 | {file = "dill-0.3.8.tar.gz", hash = "sha256:3ebe3c479ad625c4553aca177444d89b486b1d84982eeacded644afc0cf797ca"},
102 | ]
103 |
104 | [package.extras]
105 | graph = ["objgraph (>=1.7.2)"]
106 | profile = ["gprof2dot (>=2022.7.29)"]
107 |
108 | [[package]]
109 | name = "isort"
110 | version = "5.13.2"
111 | description = "A Python utility / library to sort Python imports."
112 | optional = false
113 | python-versions = ">=3.8.0"
114 | files = [
115 | {file = "isort-5.13.2-py3-none-any.whl", hash = "sha256:8ca5e72a8d85860d5a3fa69b8745237f2939afe12dbf656afbcb47fe72d947a6"},
116 | {file = "isort-5.13.2.tar.gz", hash = "sha256:48fdfcb9face5d58a4f6dde2e72a1fb8dcaf8ab26f95ab49fab84c2ddefb0109"},
117 | ]
118 |
119 | [package.extras]
120 | colors = ["colorama (>=0.4.6)"]
121 |
122 | [[package]]
123 | name = "lazy-object-proxy"
124 | version = "1.10.0"
125 | description = "A fast and thorough lazy object proxy."
126 | optional = false
127 | python-versions = ">=3.8"
128 | files = [
129 | {file = "lazy-object-proxy-1.10.0.tar.gz", hash = "sha256:78247b6d45f43a52ef35c25b5581459e85117225408a4128a3daf8bf9648ac69"},
130 | {file = "lazy_object_proxy-1.10.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:855e068b0358ab916454464a884779c7ffa312b8925c6f7401e952dcf3b89977"},
131 | {file = "lazy_object_proxy-1.10.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:7ab7004cf2e59f7c2e4345604a3e6ea0d92ac44e1c2375527d56492014e690c3"},
132 | {file = "lazy_object_proxy-1.10.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:dc0d2fc424e54c70c4bc06787e4072c4f3b1aa2f897dfdc34ce1013cf3ceef05"},
133 | {file = "lazy_object_proxy-1.10.0-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:e2adb09778797da09d2b5ebdbceebf7dd32e2c96f79da9052b2e87b6ea495895"},
134 | {file = "lazy_object_proxy-1.10.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:b1f711e2c6dcd4edd372cf5dec5c5a30d23bba06ee012093267b3376c079ec83"},
135 | {file = "lazy_object_proxy-1.10.0-cp310-cp310-win32.whl", hash = "sha256:76a095cfe6045c7d0ca77db9934e8f7b71b14645f0094ffcd842349ada5c5fb9"},
136 | {file = "lazy_object_proxy-1.10.0-cp310-cp310-win_amd64.whl", hash = "sha256:b4f87d4ed9064b2628da63830986c3d2dca7501e6018347798313fcf028e2fd4"},
137 | {file = "lazy_object_proxy-1.10.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:fec03caabbc6b59ea4a638bee5fce7117be8e99a4103d9d5ad77f15d6f81020c"},
138 | {file = "lazy_object_proxy-1.10.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:02c83f957782cbbe8136bee26416686a6ae998c7b6191711a04da776dc9e47d4"},
139 | {file = "lazy_object_proxy-1.10.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:009e6bb1f1935a62889ddc8541514b6a9e1fcf302667dcb049a0be5c8f613e56"},
140 | {file = "lazy_object_proxy-1.10.0-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:75fc59fc450050b1b3c203c35020bc41bd2695ed692a392924c6ce180c6f1dc9"},
141 | {file = "lazy_object_proxy-1.10.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:782e2c9b2aab1708ffb07d4bf377d12901d7a1d99e5e410d648d892f8967ab1f"},
142 | {file = "lazy_object_proxy-1.10.0-cp311-cp311-win32.whl", hash = "sha256:edb45bb8278574710e68a6b021599a10ce730d156e5b254941754a9cc0b17d03"},
143 | {file = "lazy_object_proxy-1.10.0-cp311-cp311-win_amd64.whl", hash = "sha256:e271058822765ad5e3bca7f05f2ace0de58a3f4e62045a8c90a0dfd2f8ad8cc6"},
144 | {file = "lazy_object_proxy-1.10.0-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:e98c8af98d5707dcdecc9ab0863c0ea6e88545d42ca7c3feffb6b4d1e370c7ba"},
145 | {file = "lazy_object_proxy-1.10.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:952c81d415b9b80ea261d2372d2a4a2332a3890c2b83e0535f263ddfe43f0d43"},
146 | {file = "lazy_object_proxy-1.10.0-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:80b39d3a151309efc8cc48675918891b865bdf742a8616a337cb0090791a0de9"},
147 | {file = "lazy_object_proxy-1.10.0-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:e221060b701e2aa2ea991542900dd13907a5c90fa80e199dbf5a03359019e7a3"},
148 | {file = "lazy_object_proxy-1.10.0-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:92f09ff65ecff3108e56526f9e2481b8116c0b9e1425325e13245abfd79bdb1b"},
149 | {file = "lazy_object_proxy-1.10.0-cp312-cp312-win32.whl", hash = "sha256:3ad54b9ddbe20ae9f7c1b29e52f123120772b06dbb18ec6be9101369d63a4074"},
150 | {file = "lazy_object_proxy-1.10.0-cp312-cp312-win_amd64.whl", hash = "sha256:127a789c75151db6af398b8972178afe6bda7d6f68730c057fbbc2e96b08d282"},
151 | {file = "lazy_object_proxy-1.10.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:9e4ed0518a14dd26092614412936920ad081a424bdcb54cc13349a8e2c6d106a"},
152 | {file = "lazy_object_proxy-1.10.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5ad9e6ed739285919aa9661a5bbed0aaf410aa60231373c5579c6b4801bd883c"},
153 | {file = "lazy_object_proxy-1.10.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:2fc0a92c02fa1ca1e84fc60fa258458e5bf89d90a1ddaeb8ed9cc3147f417255"},
154 | {file = "lazy_object_proxy-1.10.0-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:0aefc7591920bbd360d57ea03c995cebc204b424524a5bd78406f6e1b8b2a5d8"},
155 | {file = "lazy_object_proxy-1.10.0-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:5faf03a7d8942bb4476e3b62fd0f4cf94eaf4618e304a19865abf89a35c0bbee"},
156 | {file = "lazy_object_proxy-1.10.0-cp38-cp38-win32.whl", hash = "sha256:e333e2324307a7b5d86adfa835bb500ee70bfcd1447384a822e96495796b0ca4"},
157 | {file = "lazy_object_proxy-1.10.0-cp38-cp38-win_amd64.whl", hash = "sha256:cb73507defd385b7705c599a94474b1d5222a508e502553ef94114a143ec6696"},
158 | {file = "lazy_object_proxy-1.10.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:366c32fe5355ef5fc8a232c5436f4cc66e9d3e8967c01fb2e6302fd6627e3d94"},
159 | {file = "lazy_object_proxy-1.10.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:2297f08f08a2bb0d32a4265e98a006643cd7233fb7983032bd61ac7a02956b3b"},
160 | {file = "lazy_object_proxy-1.10.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:18dd842b49456aaa9a7cf535b04ca4571a302ff72ed8740d06b5adcd41fe0757"},
161 | {file = "lazy_object_proxy-1.10.0-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:217138197c170a2a74ca0e05bddcd5f1796c735c37d0eee33e43259b192aa424"},
162 | {file = "lazy_object_proxy-1.10.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:9a3a87cf1e133e5b1994144c12ca4aa3d9698517fe1e2ca82977781b16955658"},
163 | {file = "lazy_object_proxy-1.10.0-cp39-cp39-win32.whl", hash = "sha256:30b339b2a743c5288405aa79a69e706a06e02958eab31859f7f3c04980853b70"},
164 | {file = "lazy_object_proxy-1.10.0-cp39-cp39-win_amd64.whl", hash = "sha256:a899b10e17743683b293a729d3a11f2f399e8a90c73b089e29f5d0fe3509f0dd"},
165 | {file = "lazy_object_proxy-1.10.0-pp310.pp311.pp312.pp38.pp39-none-any.whl", hash = "sha256:80fa48bd89c8f2f456fc0765c11c23bf5af827febacd2f523ca5bc1893fcc09d"},
166 | ]
167 |
168 | [[package]]
169 | name = "mccabe"
170 | version = "0.7.0"
171 | description = "McCabe checker, plugin for flake8"
172 | optional = false
173 | python-versions = ">=3.6"
174 | files = [
175 | {file = "mccabe-0.7.0-py2.py3-none-any.whl", hash = "sha256:6c2d30ab6be0e4a46919781807b4f0d834ebdd6c6e3dca0bda5a15f863427b6e"},
176 | {file = "mccabe-0.7.0.tar.gz", hash = "sha256:348e0240c33b60bbdf4e523192ef919f28cb2c3d7d5c7794f74009290f236325"},
177 | ]
178 |
179 | [[package]]
180 | name = "mypy-extensions"
181 | version = "1.0.0"
182 | description = "Type system extensions for programs checked with the mypy type checker."
183 | optional = false
184 | python-versions = ">=3.5"
185 | files = [
186 | {file = "mypy_extensions-1.0.0-py3-none-any.whl", hash = "sha256:4392f6c0eb8a5668a69e23d168ffa70f0be9ccfd32b5cc2d26a34ae5b844552d"},
187 | {file = "mypy_extensions-1.0.0.tar.gz", hash = "sha256:75dbf8955dc00442a438fc4d0666508a9a97b6bd41aa2f0ffe9d2f2725af0782"},
188 | ]
189 |
190 | [[package]]
191 | name = "packaging"
192 | version = "24.0"
193 | description = "Core utilities for Python packages"
194 | optional = false
195 | python-versions = ">=3.7"
196 | files = [
197 | {file = "packaging-24.0-py3-none-any.whl", hash = "sha256:2ddfb553fdf02fb784c234c7ba6ccc288296ceabec964ad2eae3777778130bc5"},
198 | {file = "packaging-24.0.tar.gz", hash = "sha256:eb82c5e3e56209074766e6885bb04b8c38a0c015d0a30036ebe7ece34c9989e9"},
199 | ]
200 |
201 | [[package]]
202 | name = "pathspec"
203 | version = "0.12.1"
204 | description = "Utility library for gitignore style pattern matching of file paths."
205 | optional = false
206 | python-versions = ">=3.8"
207 | files = [
208 | {file = "pathspec-0.12.1-py3-none-any.whl", hash = "sha256:a0d503e138a4c123b27490a4f7beda6a01c6f288df0e4a8b79c7eb0dc7b4cc08"},
209 | {file = "pathspec-0.12.1.tar.gz", hash = "sha256:a482d51503a1ab33b1c67a6c3813a26953dbdc71c31dacaef9a838c4e29f5712"},
210 | ]
211 |
212 | [[package]]
213 | name = "platformdirs"
214 | version = "4.2.0"
215 | description = "A small Python package for determining appropriate platform-specific dirs, e.g. a \"user data dir\"."
216 | optional = false
217 | python-versions = ">=3.8"
218 | files = [
219 | {file = "platformdirs-4.2.0-py3-none-any.whl", hash = "sha256:0614df2a2f37e1a662acbd8e2b25b92ccf8632929bc6d43467e17fe89c75e068"},
220 | {file = "platformdirs-4.2.0.tar.gz", hash = "sha256:ef0cc731df711022c174543cb70a9b5bd22e5a9337c8624ef2c2ceb8ddad8768"},
221 | ]
222 |
223 | [package.extras]
224 | docs = ["furo (>=2023.9.10)", "proselint (>=0.13)", "sphinx (>=7.2.6)", "sphinx-autodoc-typehints (>=1.25.2)"]
225 | test = ["appdirs (==1.4.4)", "covdefaults (>=2.3)", "pytest (>=7.4.3)", "pytest-cov (>=4.1)", "pytest-mock (>=3.12)"]
226 |
227 | [[package]]
228 | name = "prompt-toolkit"
229 | version = "3.0.43"
230 | description = "Library for building powerful interactive command lines in Python"
231 | optional = false
232 | python-versions = ">=3.7.0"
233 | files = [
234 | {file = "prompt_toolkit-3.0.43-py3-none-any.whl", hash = "sha256:a11a29cb3bf0a28a387fe5122cdb649816a957cd9261dcedf8c9f1fef33eacf6"},
235 | {file = "prompt_toolkit-3.0.43.tar.gz", hash = "sha256:3527b7af26106cbc65a040bcc84839a3566ec1b051bb0bfe953631e704b0ff7d"},
236 | ]
237 |
238 | [package.dependencies]
239 | wcwidth = "*"
240 |
241 | [[package]]
242 | name = "pygments"
243 | version = "2.17.2"
244 | description = "Pygments is a syntax highlighting package written in Python."
245 | optional = false
246 | python-versions = ">=3.7"
247 | files = [
248 | {file = "pygments-2.17.2-py3-none-any.whl", hash = "sha256:b27c2826c47d0f3219f29554824c30c5e8945175d888647acd804ddd04af846c"},
249 | {file = "pygments-2.17.2.tar.gz", hash = "sha256:da46cec9fd2de5be3a8a784f434e4c4ab670b4ff54d605c4c2717e9d49c4c367"},
250 | ]
251 |
252 | [package.extras]
253 | plugins = ["importlib-metadata"]
254 | windows-terminal = ["colorama (>=0.4.6)"]
255 |
256 | [[package]]
257 | name = "pylint"
258 | version = "2.17.7"
259 | description = "python code static checker"
260 | optional = false
261 | python-versions = ">=3.7.2"
262 | files = [
263 | {file = "pylint-2.17.7-py3-none-any.whl", hash = "sha256:27a8d4c7ddc8c2f8c18aa0050148f89ffc09838142193fdbe98f172781a3ff87"},
264 | {file = "pylint-2.17.7.tar.gz", hash = "sha256:f4fcac7ae74cfe36bc8451e931d8438e4a476c20314b1101c458ad0f05191fad"},
265 | ]
266 |
267 | [package.dependencies]
268 | astroid = ">=2.15.8,<=2.17.0-dev0"
269 | colorama = {version = ">=0.4.5", markers = "sys_platform == \"win32\""}
270 | dill = [
271 | {version = ">=0.2", markers = "python_version < \"3.11\""},
272 | {version = ">=0.3.6", markers = "python_version >= \"3.11\""},
273 | ]
274 | isort = ">=4.2.5,<6"
275 | mccabe = ">=0.6,<0.8"
276 | platformdirs = ">=2.2.0"
277 | tomli = {version = ">=1.1.0", markers = "python_version < \"3.11\""}
278 | tomlkit = ">=0.10.1"
279 | typing-extensions = {version = ">=3.10.0", markers = "python_version < \"3.10\""}
280 |
281 | [package.extras]
282 | spelling = ["pyenchant (>=3.2,<4.0)"]
283 | testutils = ["gitpython (>3)"]
284 |
285 | [[package]]
286 | name = "six"
287 | version = "1.16.0"
288 | description = "Python 2 and 3 compatibility utilities"
289 | optional = false
290 | python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*"
291 | files = [
292 | {file = "six-1.16.0-py2.py3-none-any.whl", hash = "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"},
293 | {file = "six-1.16.0.tar.gz", hash = "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926"},
294 | ]
295 |
296 | [[package]]
297 | name = "tabulate"
298 | version = "0.8.10"
299 | description = "Pretty-print tabular data"
300 | optional = false
301 | python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
302 | files = [
303 | {file = "tabulate-0.8.10-py3-none-any.whl", hash = "sha256:0ba055423dbaa164b9e456abe7920c5e8ed33fcc16f6d1b2f2d152c8e1e8b4fc"},
304 | {file = "tabulate-0.8.10.tar.gz", hash = "sha256:6c57f3f3dd7ac2782770155f3adb2db0b1a269637e42f27599925e64b114f519"},
305 | ]
306 |
307 | [package.extras]
308 | widechars = ["wcwidth"]
309 |
310 | [[package]]
311 | name = "tinydb"
312 | version = "4.8.0"
313 | description = "TinyDB is a tiny, document oriented database optimized for your happiness :)"
314 | optional = false
315 | python-versions = ">=3.7,<4.0"
316 | files = [
317 | {file = "tinydb-4.8.0-py3-none-any.whl", hash = "sha256:30c06d12383d7c332e404ca6a6103fb2b32cbf25712689648c39d9a6bd34bd3d"},
318 | {file = "tinydb-4.8.0.tar.gz", hash = "sha256:6dd686a9c5a75dfa9280088fd79a419aefe19cd7f4bd85eba203540ef856d564"},
319 | ]
320 |
321 | [[package]]
322 | name = "tomli"
323 | version = "2.0.1"
324 | description = "A lil' TOML parser"
325 | optional = false
326 | python-versions = ">=3.7"
327 | files = [
328 | {file = "tomli-2.0.1-py3-none-any.whl", hash = "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc"},
329 | {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"},
330 | ]
331 |
332 | [[package]]
333 | name = "tomlkit"
334 | version = "0.12.4"
335 | description = "Style preserving TOML library"
336 | optional = false
337 | python-versions = ">=3.7"
338 | files = [
339 | {file = "tomlkit-0.12.4-py3-none-any.whl", hash = "sha256:5cd82d48a3dd89dee1f9d64420aa20ae65cfbd00668d6f094d7578a78efbb77b"},
340 | {file = "tomlkit-0.12.4.tar.gz", hash = "sha256:7ca1cfc12232806517a8515047ba66a19369e71edf2439d0f5824f91032b6cc3"},
341 | ]
342 |
343 | [[package]]
344 | name = "typing-extensions"
345 | version = "4.11.0"
346 | description = "Backported and Experimental Type Hints for Python 3.8+"
347 | optional = false
348 | python-versions = ">=3.8"
349 | files = [
350 | {file = "typing_extensions-4.11.0-py3-none-any.whl", hash = "sha256:c1f94d72897edaf4ce775bb7558d5b79d8126906a14ea5ed1635921406c0387a"},
351 | {file = "typing_extensions-4.11.0.tar.gz", hash = "sha256:83f085bd5ca59c80295fc2a82ab5dac679cbe02b9f33f7d83af68e241bea51b0"},
352 | ]
353 |
354 | [[package]]
355 | name = "wcwidth"
356 | version = "0.2.13"
357 | description = "Measures the displayed width of unicode strings in a terminal"
358 | optional = false
359 | python-versions = "*"
360 | files = [
361 | {file = "wcwidth-0.2.13-py2.py3-none-any.whl", hash = "sha256:3da69048e4540d84af32131829ff948f1e022c1c6bdb8d6102117aac784f6859"},
362 | {file = "wcwidth-0.2.13.tar.gz", hash = "sha256:72ea0c06399eb286d978fdedb6923a9eb47e1c486ce63e9b4e64fc18303972b5"},
363 | ]
364 |
365 | [[package]]
366 | name = "wrapt"
367 | version = "1.16.0"
368 | description = "Module for decorators, wrappers and monkey patching."
369 | optional = false
370 | python-versions = ">=3.6"
371 | files = [
372 | {file = "wrapt-1.16.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:ffa565331890b90056c01db69c0fe634a776f8019c143a5ae265f9c6bc4bd6d4"},
373 | {file = "wrapt-1.16.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:e4fdb9275308292e880dcbeb12546df7f3e0f96c6b41197e0cf37d2826359020"},
374 | {file = "wrapt-1.16.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:bb2dee3874a500de01c93d5c71415fcaef1d858370d405824783e7a8ef5db440"},
375 | {file = "wrapt-1.16.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:2a88e6010048489cda82b1326889ec075a8c856c2e6a256072b28eaee3ccf487"},
376 | {file = "wrapt-1.16.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ac83a914ebaf589b69f7d0a1277602ff494e21f4c2f743313414378f8f50a4cf"},
377 | {file = "wrapt-1.16.0-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:73aa7d98215d39b8455f103de64391cb79dfcad601701a3aa0dddacf74911d72"},
378 | {file = "wrapt-1.16.0-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:807cc8543a477ab7422f1120a217054f958a66ef7314f76dd9e77d3f02cdccd0"},
379 | {file = "wrapt-1.16.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:bf5703fdeb350e36885f2875d853ce13172ae281c56e509f4e6eca049bdfb136"},
380 | {file = "wrapt-1.16.0-cp310-cp310-win32.whl", hash = "sha256:f6b2d0c6703c988d334f297aa5df18c45e97b0af3679bb75059e0e0bd8b1069d"},
381 | {file = "wrapt-1.16.0-cp310-cp310-win_amd64.whl", hash = "sha256:decbfa2f618fa8ed81c95ee18a387ff973143c656ef800c9f24fb7e9c16054e2"},
382 | {file = "wrapt-1.16.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:1a5db485fe2de4403f13fafdc231b0dbae5eca4359232d2efc79025527375b09"},
383 | {file = "wrapt-1.16.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:75ea7d0ee2a15733684badb16de6794894ed9c55aa5e9903260922f0482e687d"},
384 | {file = "wrapt-1.16.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a452f9ca3e3267cd4d0fcf2edd0d035b1934ac2bd7e0e57ac91ad6b95c0c6389"},
385 | {file = "wrapt-1.16.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:43aa59eadec7890d9958748db829df269f0368521ba6dc68cc172d5d03ed8060"},
386 | {file = "wrapt-1.16.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:72554a23c78a8e7aa02abbd699d129eead8b147a23c56e08d08dfc29cfdddca1"},
387 | {file = "wrapt-1.16.0-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:d2efee35b4b0a347e0d99d28e884dfd82797852d62fcd7ebdeee26f3ceb72cf3"},
388 | {file = "wrapt-1.16.0-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:6dcfcffe73710be01d90cae08c3e548d90932d37b39ef83969ae135d36ef3956"},
389 | {file = "wrapt-1.16.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:eb6e651000a19c96f452c85132811d25e9264d836951022d6e81df2fff38337d"},
390 | {file = "wrapt-1.16.0-cp311-cp311-win32.whl", hash = "sha256:66027d667efe95cc4fa945af59f92c5a02c6f5bb6012bff9e60542c74c75c362"},
391 | {file = "wrapt-1.16.0-cp311-cp311-win_amd64.whl", hash = "sha256:aefbc4cb0a54f91af643660a0a150ce2c090d3652cf4052a5397fb2de549cd89"},
392 | {file = "wrapt-1.16.0-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:5eb404d89131ec9b4f748fa5cfb5346802e5ee8836f57d516576e61f304f3b7b"},
393 | {file = "wrapt-1.16.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:9090c9e676d5236a6948330e83cb89969f433b1943a558968f659ead07cb3b36"},
394 | {file = "wrapt-1.16.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:94265b00870aa407bd0cbcfd536f17ecde43b94fb8d228560a1e9d3041462d73"},
395 | {file = "wrapt-1.16.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:f2058f813d4f2b5e3a9eb2eb3faf8f1d99b81c3e51aeda4b168406443e8ba809"},
396 | {file = "wrapt-1.16.0-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:98b5e1f498a8ca1858a1cdbffb023bfd954da4e3fa2c0cb5853d40014557248b"},
397 | {file = "wrapt-1.16.0-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:14d7dc606219cdd7405133c713f2c218d4252f2a469003f8c46bb92d5d095d81"},
398 | {file = "wrapt-1.16.0-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:49aac49dc4782cb04f58986e81ea0b4768e4ff197b57324dcbd7699c5dfb40b9"},
399 | {file = "wrapt-1.16.0-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:418abb18146475c310d7a6dc71143d6f7adec5b004ac9ce08dc7a34e2babdc5c"},
400 | {file = "wrapt-1.16.0-cp312-cp312-win32.whl", hash = "sha256:685f568fa5e627e93f3b52fda002c7ed2fa1800b50ce51f6ed1d572d8ab3e7fc"},
401 | {file = "wrapt-1.16.0-cp312-cp312-win_amd64.whl", hash = "sha256:dcdba5c86e368442528f7060039eda390cc4091bfd1dca41e8046af7c910dda8"},
402 | {file = "wrapt-1.16.0-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:d462f28826f4657968ae51d2181a074dfe03c200d6131690b7d65d55b0f360f8"},
403 | {file = "wrapt-1.16.0-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a33a747400b94b6d6b8a165e4480264a64a78c8a4c734b62136062e9a248dd39"},
404 | {file = "wrapt-1.16.0-cp36-cp36m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:b3646eefa23daeba62643a58aac816945cadc0afaf21800a1421eeba5f6cfb9c"},
405 | {file = "wrapt-1.16.0-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3ebf019be5c09d400cf7b024aa52b1f3aeebeff51550d007e92c3c1c4afc2a40"},
406 | {file = "wrapt-1.16.0-cp36-cp36m-musllinux_1_1_aarch64.whl", hash = "sha256:0d2691979e93d06a95a26257adb7bfd0c93818e89b1406f5a28f36e0d8c1e1fc"},
407 | {file = "wrapt-1.16.0-cp36-cp36m-musllinux_1_1_i686.whl", hash = "sha256:1acd723ee2a8826f3d53910255643e33673e1d11db84ce5880675954183ec47e"},
408 | {file = "wrapt-1.16.0-cp36-cp36m-musllinux_1_1_x86_64.whl", hash = "sha256:bc57efac2da352a51cc4658878a68d2b1b67dbe9d33c36cb826ca449d80a8465"},
409 | {file = "wrapt-1.16.0-cp36-cp36m-win32.whl", hash = "sha256:da4813f751142436b075ed7aa012a8778aa43a99f7b36afe9b742d3ed8bdc95e"},
410 | {file = "wrapt-1.16.0-cp36-cp36m-win_amd64.whl", hash = "sha256:6f6eac2360f2d543cc875a0e5efd413b6cbd483cb3ad7ebf888884a6e0d2e966"},
411 | {file = "wrapt-1.16.0-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:a0ea261ce52b5952bf669684a251a66df239ec6d441ccb59ec7afa882265d593"},
412 | {file = "wrapt-1.16.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:7bd2d7ff69a2cac767fbf7a2b206add2e9a210e57947dd7ce03e25d03d2de292"},
413 | {file = "wrapt-1.16.0-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:9159485323798c8dc530a224bd3ffcf76659319ccc7bbd52e01e73bd0241a0c5"},
414 | {file = "wrapt-1.16.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:a86373cf37cd7764f2201b76496aba58a52e76dedfaa698ef9e9688bfd9e41cf"},
415 | {file = "wrapt-1.16.0-cp37-cp37m-musllinux_1_1_aarch64.whl", hash = "sha256:73870c364c11f03ed072dda68ff7aea6d2a3a5c3fe250d917a429c7432e15228"},
416 | {file = "wrapt-1.16.0-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:b935ae30c6e7400022b50f8d359c03ed233d45b725cfdd299462f41ee5ffba6f"},
417 | {file = "wrapt-1.16.0-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:db98ad84a55eb09b3c32a96c576476777e87c520a34e2519d3e59c44710c002c"},
418 | {file = "wrapt-1.16.0-cp37-cp37m-win32.whl", hash = "sha256:9153ed35fc5e4fa3b2fe97bddaa7cbec0ed22412b85bcdaf54aeba92ea37428c"},
419 | {file = "wrapt-1.16.0-cp37-cp37m-win_amd64.whl", hash = "sha256:66dfbaa7cfa3eb707bbfcd46dab2bc6207b005cbc9caa2199bcbc81d95071a00"},
420 | {file = "wrapt-1.16.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:1dd50a2696ff89f57bd8847647a1c363b687d3d796dc30d4dd4a9d1689a706f0"},
421 | {file = "wrapt-1.16.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:44a2754372e32ab315734c6c73b24351d06e77ffff6ae27d2ecf14cf3d229202"},
422 | {file = "wrapt-1.16.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:8e9723528b9f787dc59168369e42ae1c3b0d3fadb2f1a71de14531d321ee05b0"},
423 | {file = "wrapt-1.16.0-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:dbed418ba5c3dce92619656802cc5355cb679e58d0d89b50f116e4a9d5a9603e"},
424 | {file = "wrapt-1.16.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:941988b89b4fd6b41c3f0bfb20e92bd23746579736b7343283297c4c8cbae68f"},
425 | {file = "wrapt-1.16.0-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:6a42cd0cfa8ffc1915aef79cb4284f6383d8a3e9dcca70c445dcfdd639d51267"},
426 | {file = "wrapt-1.16.0-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:1ca9b6085e4f866bd584fb135a041bfc32cab916e69f714a7d1d397f8c4891ca"},
427 | {file = "wrapt-1.16.0-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:d5e49454f19ef621089e204f862388d29e6e8d8b162efce05208913dde5b9ad6"},
428 | {file = "wrapt-1.16.0-cp38-cp38-win32.whl", hash = "sha256:c31f72b1b6624c9d863fc095da460802f43a7c6868c5dda140f51da24fd47d7b"},
429 | {file = "wrapt-1.16.0-cp38-cp38-win_amd64.whl", hash = "sha256:490b0ee15c1a55be9c1bd8609b8cecd60e325f0575fc98f50058eae366e01f41"},
430 | {file = "wrapt-1.16.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:9b201ae332c3637a42f02d1045e1d0cccfdc41f1f2f801dafbaa7e9b4797bfc2"},
431 | {file = "wrapt-1.16.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:2076fad65c6736184e77d7d4729b63a6d1ae0b70da4868adeec40989858eb3fb"},
432 | {file = "wrapt-1.16.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:c5cd603b575ebceca7da5a3a251e69561bec509e0b46e4993e1cac402b7247b8"},
433 | {file = "wrapt-1.16.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:b47cfad9e9bbbed2339081f4e346c93ecd7ab504299403320bf85f7f85c7d46c"},
434 | {file = "wrapt-1.16.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f8212564d49c50eb4565e502814f694e240c55551a5f1bc841d4fcaabb0a9b8a"},
435 | {file = "wrapt-1.16.0-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:5f15814a33e42b04e3de432e573aa557f9f0f56458745c2074952f564c50e664"},
436 | {file = "wrapt-1.16.0-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:db2e408d983b0e61e238cf579c09ef7020560441906ca990fe8412153e3b291f"},
437 | {file = "wrapt-1.16.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:edfad1d29c73f9b863ebe7082ae9321374ccb10879eeabc84ba3b69f2579d537"},
438 | {file = "wrapt-1.16.0-cp39-cp39-win32.whl", hash = "sha256:ed867c42c268f876097248e05b6117a65bcd1e63b779e916fe2e33cd6fd0d3c3"},
439 | {file = "wrapt-1.16.0-cp39-cp39-win_amd64.whl", hash = "sha256:eb1b046be06b0fce7249f1d025cd359b4b80fc1c3e24ad9eca33e0dcdb2e4a35"},
440 | {file = "wrapt-1.16.0-py3-none-any.whl", hash = "sha256:6906c4100a8fcbf2fa735f6059214bb13b97f75b1a61777fcf6432121ef12ef1"},
441 | {file = "wrapt-1.16.0.tar.gz", hash = "sha256:5f370f952971e7d17c7d1ead40e49f32345a7f7a5373571ef44d800d06b1899d"},
442 | ]
443 |
444 | [metadata]
445 | lock-version = "2.0"
446 | python-versions = "^3.8"
447 | content-hash = "ec1a92418f7601013d3b590f32d4a5f526b6b3a5fa1961e9d00a3b583872a989"
448 |
--------------------------------------------------------------------------------
/pyproject.toml:
--------------------------------------------------------------------------------
1 | [tool.poetry]
2 | name = "ctui"
3 | version = "0.7.9"
4 | description = "The ctui library is similar to Python's built in cmd library, but with a curses-like user interface"
5 | authors = ["Justin Searle "]
6 | license = "LGPL"
7 | readme = "README.md"
8 | homepage = "https://www.controlthings.io"
9 | repository = "https://github.com/ControlThings-io/ctserial"
10 | keywords = ["serial", "fieldbus", "ICS", "control", "ControlThings"]
11 | classifiers = [
12 | 'Development Status :: 5 - Production/Stable',
13 | 'Intended Audience :: Developers',
14 | 'Intended Audience :: Information Technology',
15 | 'Intended Audience :: Manufacturing',
16 | 'Intended Audience :: Other Audience',
17 | 'Intended Audience :: Science/Research',
18 | 'Operating System :: Unix',
19 | 'Operating System :: POSIX',
20 | 'Operating System :: Microsoft :: Windows',
21 | 'Topic :: Utilities',
22 | ]
23 |
24 | [tool.poetry.dependencies]
25 | python = "^3.8"
26 | prompt-toolkit = "^3.0.36"
27 | Pygments = "^2.14.0"
28 | tabulate = "^0.8.0"
29 | tinydb = "^4.7.1"
30 | six = "^1.16.0"
31 |
32 | [tool.poetry.group.dev.dependencies]
33 | pylint = "^2.16.2"
34 | black = "^23.1.0"
35 | isort = "^5.12.0"
36 |
37 | [build-system]
38 | requires = ["poetry-core"]
39 | build-backend = "poetry.core.masonry.api"
40 |
41 | [tool.pylint.messages_control]
42 | disable = "C0330, C0326"
43 |
44 | [tool.pylint.format]
45 | max-line-length = "88"
46 |
47 | [tool.isort]
48 | multi_line_output = 3
49 | include_trailing_comma = true
50 | force_grid_wrap = 0
51 | use_parentheses = true
52 | ensure_newline_before_comments = true
53 | line_length = 88
54 |
--------------------------------------------------------------------------------
/src/ctui/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | Control Things User Interface, aka ctui.py
3 |
4 | # Copyright (C) 2019 Justin Searle
5 | #
6 | # This program is free software: you can redistribute it and/or modify it under
7 | # the terms of the GNU General Public License as published by the Free Software
8 | # Foundation, either version 3 of the License, or any later version.
9 | #
10 | # This program is distributed in the hope that it will be useful, but WITHOUT
11 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 | # details at .
14 | """
15 | import ctui.types
16 | from ctui.application import Ctui
17 |
18 | __all__ = [
19 | "Ctui",
20 | ]
21 |
--------------------------------------------------------------------------------
/src/ctui/application.py:
--------------------------------------------------------------------------------
1 | """
2 | Control Things User Interface, aka ctui.py
3 |
4 | # Copyright (C) 2019 Justin Searle
5 | #
6 | # This program is free software: you can redistribute it and/or modify it under
7 | # the terms of the GNU General Public License as published by the Free Software
8 | # Foundation, either version 3 of the License, or any later version.
9 | #
10 | # This program is distributed in the hope that it will be useful, but WITHOUT
11 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 | # details at .
14 | """
15 | from datetime import datetime
16 | from pathlib import Path
17 |
18 | from prompt_toolkit.application import Application
19 | from prompt_toolkit.application.current import get_app
20 | from prompt_toolkit.layout.layout import Layout
21 | from tinydb import TinyDB
22 |
23 | from ctui.commands import Commands, register_default_commands
24 | from ctui.keybindings import get_key_bindings
25 | from ctui.layout import CtuiLayout
26 | from ctui.style import CtuiStyle
27 |
28 | from .dialogs import yes_no_dialog
29 |
30 |
31 | class Ctui(object):
32 | """
33 | Class with commands that users may use at the application prompt.
34 |
35 | Each function representing a command must:
36 | - start with a do_
37 | - accept self, input_text, output_text, and event as params
38 | - return a string to print, None, or False
39 | Returning a False does nothing, forcing users to correct mistakes
40 | """
41 |
42 | # User setable variables
43 | name = "MyApp"
44 | version = "0.1.0" # must be string
45 | description = "My App does something..."
46 | prompt = "> "
47 | help_message = "Commands go on top, results appear on the bottom."
48 | wrap_lines = False # Wrap lines in main output window or not
49 |
50 | # sets various defaults if not overriden with subclass
51 | def __init__(self, layout=None):
52 | self.status_dict = {}
53 | self.commands = Commands()
54 | register_default_commands(ctui=self)
55 | self.project_name = "default"
56 |
57 | @property
58 | def welcome(self):
59 | return f"Welcome to {self.name}{self.version}\n\n{self.description}"
60 |
61 | @property
62 | def project_folder(self):
63 | return f"{Path.home()}/.{self.name}/projects/"
64 |
65 | @property
66 | def _project_path(self):
67 | return f"{self.project_folder}{self.project_name}.{self.name}"
68 |
69 | # TODO: Fix broken status bar
70 | @property
71 | def _statusbar(self):
72 | self.status_dict["Project"] = self.project_name
73 | return " ".join([f"{k}: {v}" for k, v in self.status_dict.items()])
74 |
75 | def _init_db(self):
76 | """setup database storage"""
77 | self.db = TinyDB(self._project_path)
78 | self.settings = self.db.table("settings")
79 | self.storage = self.db.table("storage")
80 | self.history = self.db.table("history")
81 |
82 | def command(self, func):
83 | return self.commands.register(func)
84 |
85 | def run(self):
86 | """Start the python_prompt application with ctui's default settings"""
87 | Path(self.project_folder).mkdir(parents=True, exist_ok=True)
88 | if Path(
89 | self._project_path
90 | ).exists(): # start with clean default project at each start
91 | Path.unlink(Path(self._project_path))
92 | self._init_db()
93 | self.layout = CtuiLayout(self)
94 | self.style = CtuiStyle()
95 | self._mode = "term_ui" # For future headless mode
96 | layout = Layout(
97 | self.layout.root_container, focused_element=self.layout.input_field
98 | )
99 | self.app = Application(
100 | layout=layout,
101 | key_bindings=get_key_bindings(self),
102 | style=self.style.dark_theme,
103 | enable_page_navigation_bindings=False,
104 | mouse_support=True,
105 | full_screen=True,
106 | )
107 | self.app.run()
108 |
109 | def _log_and_exit(self):
110 | date, time = str(datetime.today()).split()
111 | self.history.insert(
112 | {"Date": date, "Time": time.split(".")[0], "Command": "exit"}
113 | )
114 | self.db.close()
115 | get_app().exit()
116 |
117 | def exit(self):
118 | """Graceful shutdown of the prompt_toolkit application"""
119 | if self._mode == "term_ui" and self.project_name == "default":
120 | yes_no_dialog(
121 | title="Warning",
122 | text="Exit without saving project?",
123 | yes_func=self._log_and_exit,
124 | )
125 | else:
126 | self._log_and_exit()
127 |
--------------------------------------------------------------------------------
/src/ctui/base.py:
--------------------------------------------------------------------------------
1 | """
2 | Control Things User Interface, aka ctui.py
3 |
4 | # Copyright (C) 2019 Justin Searle
5 | #
6 | # This program is free software: you can redistribute it and/or modify it under
7 | # the terms of the GNU General Public License as published by the Free Software
8 | # Foundation, either version 3 of the License, or any later version.
9 | #
10 | # This program is distributed in the hope that it will be useful, but WITHOUT
11 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 | # details at .
14 | """
15 | from __future__ import unicode_literals
16 |
17 | from functools import partial
18 |
19 | import six
20 | from prompt_toolkit.application.current import get_app
21 | from prompt_toolkit.auto_suggest import DynamicAutoSuggest
22 | from prompt_toolkit.buffer import Buffer
23 | from prompt_toolkit.document import Document
24 | from prompt_toolkit.filters import Condition, has_focus, is_done, is_true, to_filter
25 | from prompt_toolkit.formatted_text import Template, is_formatted_text, to_formatted_text
26 | from prompt_toolkit.formatted_text.utils import fragment_list_to_text
27 | from prompt_toolkit.key_binding.key_bindings import KeyBindings
28 | from prompt_toolkit.keys import Keys
29 | from prompt_toolkit.layout.containers import (
30 | ConditionalContainer,
31 | DynamicContainer,
32 | Float,
33 | FloatContainer,
34 | HSplit,
35 | VSplit,
36 | Window,
37 | WindowAlign,
38 | is_container,
39 | )
40 | from prompt_toolkit.layout.controls import BufferControl, FormattedTextControl
41 | from prompt_toolkit.layout.dimension import Dimension as D
42 | from prompt_toolkit.layout.dimension import is_dimension, to_dimension
43 | from prompt_toolkit.layout.margins import NumberedMargin, ScrollbarMargin
44 | from prompt_toolkit.layout.processors import (
45 | AppendAutoSuggestion,
46 | BeforeInput,
47 | ConditionalProcessor,
48 | PasswordProcessor,
49 | )
50 | from prompt_toolkit.lexers import DynamicLexer
51 | from prompt_toolkit.mouse_events import MouseEventType
52 | from prompt_toolkit.utils import get_cwidth
53 | from prompt_toolkit.widgets.toolbars import SearchToolbar
54 |
55 |
56 | class Button(object):
57 | """
58 | Clickable button, copied from prompt_toolkit/widgets/base.py, fixed width bug.
59 |
60 | :param text: The caption for the button.
61 | :param handler: `None` or callable. Called when the button is clicked.
62 | :param width: Width of the button.
63 | """
64 |
65 | def __init__(self, text, handler=None, width=12):
66 | assert isinstance(text, six.text_type)
67 | assert handler is None or callable(handler)
68 | assert isinstance(width, int)
69 |
70 | self.text = text
71 | self.handler = handler
72 | self.width = max(width, len(text) + 2)
73 | self.control = FormattedTextControl(
74 | self._get_text_fragments,
75 | key_bindings=self._get_key_bindings(),
76 | focusable=True,
77 | )
78 |
79 | def get_style():
80 | if get_app().layout.has_focus(self):
81 | return "class:button.focused"
82 | else:
83 | return "class:button"
84 |
85 | self.window = Window(
86 | self.control,
87 | align=WindowAlign.CENTER,
88 | height=1,
89 | width=self.width,
90 | style=get_style,
91 | dont_extend_width=True,
92 | dont_extend_height=True,
93 | )
94 |
95 | def _get_text_fragments(self):
96 | text = ("{:^%s}" % (self.width - 2)).format(self.text)
97 |
98 | def handler(mouse_event):
99 | if mouse_event.event_type == MouseEventType.MOUSE_UP:
100 | self.handler()
101 |
102 | return [
103 | ("class:button.arrow", "<", handler),
104 | ("[SetCursorPosition]", ""),
105 | ("class:button.text", text, handler),
106 | ("class:button.arrow", ">", handler),
107 | ]
108 |
109 | def _get_key_bindings(self):
110 | "Key bindings for the Button."
111 | kb = KeyBindings()
112 |
113 | @kb.add(" ")
114 | @kb.add("enter")
115 | def _(event):
116 | if self.handler is not None:
117 | self.handler()
118 |
119 | return kb
120 |
121 | def __pt_container__(self):
122 | return self.window
123 |
--------------------------------------------------------------------------------
/src/ctui/commands.py:
--------------------------------------------------------------------------------
1 | """
2 | Control Things User Interface, aka ctui.py
3 |
4 | # Copyright (C) 2019 Justin Searle
5 | #
6 | # This program is free software: you can redistribute it and/or modify it under
7 | # the terms of the GNU General Public License as published by the Free Software
8 | # Foundation, either version 3 of the License, or any later version.
9 | #
10 | # This program is distributed in the hope that it will be useful, but WITHOUT
11 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 | # details at .
14 | """
15 | import shlex
16 | from inspect import getfullargspec
17 | from pathlib import Path
18 |
19 | from tabulate import tabulate
20 | from tinydb import Query
21 |
22 | from ctui.dialogs import message_dialog, yes_no_dialog
23 | from ctui.functions import show_help
24 | from ctui.types import is_greedy, to_type
25 |
26 |
27 | class KwArgs(object):
28 | """Defines the elements of each command argument"""
29 |
30 | def __init__(self, kwarg, argtype, argdesc):
31 | self.name = kwarg
32 | self.type = argtype
33 | self.desc = argdesc
34 |
35 | def to_type(self, value: str):
36 | assert isinstance(value, str)
37 | return to_type(value, self)
38 |
39 | def __repr__(self):
40 | return str({"name": self.name, "type": self.type, "desc": self.desc})
41 |
42 | def __str__(self):
43 | return f"{self.name}: {self.desc}"
44 |
45 |
46 | class Command(object):
47 | """Defines the elements of each command"""
48 |
49 | def __init__(self, func):
50 | """Called by @commands property, registers passed function as a ctui command"""
51 | self.func_name = func.__name__ # used to track original function name
52 | if self.func_name.startswith(
53 | "do_"
54 | ): # allow users to use do_ prefix to avoid keywords
55 | self.string = self.func_name[3:].replace(
56 | "_", " "
57 | ) # used to match multi-word commands
58 | else:
59 | self.string = self.func_name.replace(
60 | "_", " "
61 | ) # used to match multi-word commands
62 | self.string_parts = self.string.split()
63 | self.func = func # used to call the function
64 | doc_lines = func.__doc__.split("\n")
65 | if doc_lines[0] == "":
66 | self.desc = doc_lines[1].strip() # used for completion description
67 | else:
68 | self.desc = doc_lines[0].strip() # used for completion description
69 | self.kwargs = self.register_args(getfullargspec(func), doc_lines)
70 | # Determine if command supports infinite arguments (greedy final arg)
71 | if self.kwargs and is_greedy(self.kwargs[-1].type):
72 | self.greedy = True
73 | else:
74 | self.greedy = False
75 |
76 | @property
77 | def kwarg_descriptions(self):
78 | descriptions = {}
79 | for key, kwarg in self.kwargs:
80 | descriptions[key] = kwarg.desc
81 | return descriptions
82 |
83 | @property
84 | def help(self):
85 | output = f'Help for command "{self.string}"\n'
86 | output += f" {self.desc}\n\nArguments\n"
87 | if self.kwargs:
88 | output += "\n".join([f" {kwarg}" for kwarg in self.kwargs])
89 | else:
90 | output += " None"
91 | return output
92 |
93 | def register_args(self, argspec, doc_lines):
94 | kwargs = [] # used to track args to function
95 | argdesc = ""
96 | self.req_args = len(argspec.args or []) - len(argspec.defaults or [])
97 | for kwarg in argspec.args:
98 | if kwarg in argspec.annotations:
99 | argtype = argspec.annotations[kwarg]
100 | else:
101 | argtype = None
102 | for line in doc_lines[1:]:
103 | kwarg_offset = line.find(kwarg)
104 | if kwarg_offset >= 0:
105 | argdesc = line[kwarg_offset + len(kwarg) + 1 :].strip()
106 | break
107 | kwargs.append(KwArgs(kwarg, argtype, argdesc))
108 | return kwargs
109 |
110 | def parse_args(self, arg_string):
111 | args = shlex.split(arg_string)
112 | # assert False, f'{self.req_args}, {len(args)}, {len(self.kwargs)}'
113 | assert (
114 | self.req_args <= len(args)
115 | and len(self.kwargs) >= len(args)
116 | or self.req_args <= len(args)
117 | and self.greedy
118 | ), f"Wrong number of arguments\n\n{self.help}"
119 | kwargs = {}
120 | pairs = min(len(self.kwargs), len(args))
121 | for argnum in range(pairs):
122 | kwarg = self.kwargs[argnum]
123 | if argnum < pairs - 1:
124 | kwargs[kwarg.name] = kwarg.to_type(args[argnum])
125 | elif argnum == pairs - 1:
126 | if self.req_args > len(args):
127 | greedy_str = " ".join(
128 | args[argnum:]
129 | ) # Minor bug, will loose mupti-spaces
130 | kwargs[kwarg.name] = kwarg.to_type(greedy_str)
131 | else:
132 | kwargs[kwarg.name] = kwarg.to_type(args[argnum])
133 | return kwargs
134 |
135 | def execute(self, **kwargs):
136 | return self.func(**kwargs)
137 |
138 |
139 | class Commands(object):
140 | """Registers and assembles all the commands"""
141 |
142 | def __init__(self):
143 | self.commands = {}
144 |
145 | def register(self, func):
146 | command = Command(func)
147 | self.commands[command.string] = command
148 |
149 | @property
150 | def strings(self):
151 | command_strings = []
152 | for command_string in sorted(self.commands.keys()):
153 | command_strings.append(command_string)
154 | return command_strings
155 |
156 | @property
157 | def descriptions(self):
158 | command_descriptions = {}
159 | for key, command in self.commands.items():
160 | command_descriptions[key] = command.desc
161 | return command_descriptions
162 |
163 | @property
164 | def func_names(self):
165 | command_func_names = {}
166 | for key, command in self.commands.items():
167 | command_func_names[key] = command.func_name
168 | return command_func_names
169 |
170 | @property
171 | def functions(self):
172 | command_functions = {}
173 | for key, command in self.commands.items():
174 | command_functions[key] = command.func
175 | return command_functions
176 |
177 | def extract(self, input_text):
178 | """Extract command arguments from user text."""
179 | parts = input_text.split()
180 | # try the the longest combination of parts to the smallest combination
181 | for i in range(len(parts), 0, -1):
182 | for command in self:
183 | # if command exists, parse and type-convert command arguments
184 | if command.string == " ".join(parts[:i]):
185 | if i == len(parts):
186 | return command, {}
187 | kwargs = command.parse_args(input_text.split(maxsplit=i)[i])
188 | return command, kwargs
189 | return None, None
190 |
191 | def __getitem__(self, key):
192 | return self.commands[key]
193 |
194 | def __iter__(self):
195 | for command in self.commands.values():
196 | yield command
197 |
198 | def __str__(self):
199 | return str(self.descriptions)
200 |
201 | def __repr__(self):
202 | return str(self.commands)
203 |
204 |
205 | def register_default_commands(ctui):
206 | @ctui.command
207 | def do_clear():
208 | """Clear the screen"""
209 | return ""
210 |
211 | @ctui.command
212 | def do_help():
213 | """Print application help"""
214 | show_help(ctui)
215 |
216 | @ctui.command
217 | def do_history(count: int = 0):
218 | """
219 | Print history of commands entered
220 |
221 | :PARAM count: Optional number of last histories to print
222 | """
223 | message = tabulate(
224 | ctui.history.all()[-count:], headers="keys", tablefmt="simple"
225 | )
226 | message_dialog(title="History", text=message)
227 |
228 | @ctui.command
229 | def do_history_clear():
230 | """Clear history of commands entered"""
231 | ctui.db.purge_table("history")
232 | ctui.history = ctui.db.table("history")
233 |
234 | @ctui.command
235 | def do_history_search(query: str):
236 | """
237 | Search history of commands ...
238 |
239 | :PARAM query: Regex string to search in history
240 | """
241 | History = Query()
242 | search_results = ctui.history.search(History.Command.matches(".*" + query))
243 | message = tabulate(search_results, headers="keys", tablefmt="simple")
244 | message_dialog(title="History Search Results", text=message)
245 |
246 | # @ctui.command
247 | # def do_macro_set(name: str, command: GreedyStr):
248 | # """
249 | # Create a new macro
250 |
251 | # :PARAM name: Name of new macro
252 | # :PARAM command: Command to run and its arguments
253 | # """
254 | # ctui.settings.insert({name: date})
255 |
256 | @ctui.command
257 | def do_project():
258 | """Information about the current project"""
259 | message = f" Project Name: {ctui.project_name}\n"
260 | message += f" Project Path: {ctui._project_path}\n"
261 | message += f" File Size: {Path(ctui._project_path).stat().st_size} KB\n"
262 | message += f" History Count: {len(ctui.history)} records\n"
263 | message += f"Settings Count: {len(ctui.settings)} records\n"
264 | message += f" Storage Count: {len(ctui.storage)} records"
265 | message_dialog(title="Project Information", text=message)
266 |
267 | @ctui.command
268 | def do_project_delete(name: str):
269 | """
270 | Delete saved project ...
271 |
272 | :PARAM name: Name of project to deleted
273 | """
274 | assert name != ctui.project_name, "Cannot delete current project"
275 | project_to_delete = f"{name}.{ctui.name}"
276 | project_to_delete_path = Path(
277 | ctui.project_folder + project_to_delete
278 | ).expanduser()
279 | assert project_to_delete_path.is_file(), "Project does not exist"
280 |
281 | yes_no_dialog(
282 | title="Confirmation",
283 | text=f"Delete {name} project?",
284 | yes_func=lambda: Path.unlink(Path(project_to_delete_path)),
285 | )
286 |
287 | @ctui.command
288 | def do_project_export(filename: str):
289 | """
290 | Export the current project to ...
291 |
292 | :PARAM filename: Filename of file to export current project
293 | """
294 | export_file = Path(f"{filename}.{ctui.name}").expanduser()
295 |
296 | def project_export():
297 | export_file.write_bytes(Path(ctui._project_path).read_bytes())
298 |
299 | if export_file.is_file():
300 | yes_no_dialog(
301 | title="File Already Exists",
302 | text="Overwrite file?",
303 | yes_func=project_export,
304 | )
305 | else:
306 | project_export()
307 | message_dialog(
308 | title="Success", text=f'Project exported as:\n"{export_file}"'
309 | )
310 |
311 | # TODO: Fix, seems broken, good files say invalid or currupt
312 | @ctui.command
313 | def do_project_import(filename: str):
314 | """
315 | Import exported project from ...
316 |
317 | :PARAM filename: Exported filename to import
318 | """
319 | project_to_import_path = Path(filename).expanduser()
320 | if project_to_import_path.is_file() is False:
321 | project_to_import_path = Path(str(project_to_import_path) + f".{ctui.name}")
322 | assert project_to_import_path.is_file(), "File does not exist"
323 | with open(project_to_import_path) as f:
324 | assert f.read(14) == '{"_default": {', "Invald or corrupted project file"
325 |
326 | # build new project name and path
327 | if project_to_import_path.suffix[1:] == ctui.name:
328 | ctui.project_name = project_to_import_path.stem
329 | else:
330 | ctui.project_name = project_to_import_path.name
331 |
332 | def project_import():
333 | ctui.db.close()
334 | Path(ctui._project_path).write_bytes(project_to_import_path.read_bytes())
335 | ctui._init_db()
336 |
337 | if Path(ctui._project_path).is_file():
338 | yes_no_dialog(
339 | title="WARNING",
340 | text="Project already exists.\nOverwrite project?",
341 | yes_func=project_import,
342 | )
343 | # TODO: use input_dialog to request new project name
344 | else:
345 | project_import()
346 | message_dialog(
347 | title="Success", text=f'Project imported as "{ctui.project_name}"'
348 | )
349 |
350 | @ctui.command
351 | def do_project_list():
352 | """List saved projects"""
353 | lines = []
354 | for file in list(Path(ctui.project_folder).glob(f"*.{ctui.name}")):
355 | lines.append({"Project": file.stem, "Size (KB)": file.stat().st_size})
356 | message = tabulate(lines, headers="keys", tablefmt="simple")
357 | message_dialog(title="Saved Projects", text=message, scrollbar=True)
358 |
359 | @ctui.command
360 | def do_project_load(name: str):
361 | """
362 | Load saved project ...
363 |
364 | :PARAM name: Name of project to load
365 | """
366 | project_to_load_path = f"{ctui.project_folder}{name}.{ctui.name}"
367 | assert Path(project_to_load_path).is_file(), f'"{name}" is not a valid project'
368 |
369 | ctui.db.close()
370 | ctui.project_name = name
371 | ctui._init_db()
372 |
373 | message_dialog(title="Success", text=f"{name} project loaded.")
374 |
375 | @ctui.command
376 | def do_project_reset():
377 | """Reset the current project file"""
378 |
379 | def project_reset():
380 | ctui.db.close()
381 | Path.unlink(Path(ctui._project_path))
382 | ctui._init_db()
383 |
384 | yes_no_dialog(
385 | title="Warning",
386 | text="Current project history and data will be deleted!",
387 | yes_text="Ok",
388 | yes_func=project_reset,
389 | no_text="Cancel",
390 | )
391 |
392 | @ctui.command
393 | def do_project_saveas(name: str):
394 | """
395 | Save current project as ...
396 |
397 | :PARAM name: New name of project you are saving
398 | """
399 | project_to_save_path = f"{ctui.project_folder}{name}.{ctui.name}"
400 |
401 | def project_saveas():
402 | ctui.db.close()
403 | old_project = Path(ctui._project_path)
404 | ctui.project_name = name
405 | Path(ctui._project_path).write_bytes(old_project.read_bytes())
406 | ctui._init_db()
407 |
408 | if Path(project_to_save_path).is_file():
409 | yes_no_dialog(
410 | title="Warning",
411 | text=f'Project "{name}" already exists! Overwrite?',
412 | yes_func=project_saveas,
413 | )
414 | else:
415 | project_saveas()
416 | message_dialog(text=f'Project saved as "{name}".')
417 |
418 | @ctui.command
419 | def do_exit():
420 | """Exit the application"""
421 | ctui.exit()
422 | # Return False to prevent history write since db is already closed
423 | return False
424 |
--------------------------------------------------------------------------------
/src/ctui/completion.py:
--------------------------------------------------------------------------------
1 | """
2 | Control Things User Interface, aka ctui.py
3 |
4 | # Copyright (C) 2019 Justin Searle
5 | #
6 | # This program is free software: you can redistribute it and/or modify it under
7 | # the terms of the GNU General Public License as published by the Free Software
8 | # Foundation, either version 3 of the License, or any later version.
9 | #
10 | # This program is distributed in the hope that it will be useful, but WITHOUT
11 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 | # details at .
14 | """
15 | from __future__ import unicode_literals
16 |
17 | from prompt_toolkit.completion import Completer, Completion
18 | from six import string_types
19 |
20 | from ctui.commands import Commands
21 |
22 | __all__ = [
23 | "CommandCompleter",
24 | ]
25 |
26 |
27 | class CommandCompleter(Completer):
28 | """
29 | Simple autocompletion on a list of ctui commands.
30 |
31 | :param commands: A ctui Commands object
32 | """
33 |
34 | def __init__(self, commands):
35 | assert isinstance(commands, Commands)
36 | self.commands = commands
37 |
38 | def get_completions(self, document, complete_event):
39 | parts_before_cursor = document.text_before_cursor.split() # clean up spaces
40 | text_before_cursor = " ".join(parts_before_cursor)
41 | current_part = len(parts_before_cursor) - 1
42 | next_part = False
43 | if document.text_before_cursor[-1] == " ": # re-add trailing space if present
44 | next_part = True
45 |
46 | def previous_parts_match(command_parts):
47 | if current_part == 0:
48 | return True
49 | if len(command_parts) == len(parts_before_cursor):
50 | for i in range(current_part):
51 | if command_parts[i] == parts_before_cursor[i]:
52 | return True
53 |
54 | def last_part_full_match(command_parts):
55 | if next_part and len(command_parts) >= current_part + 2:
56 | if command_parts[current_part] == parts_before_cursor[current_part]:
57 | return True
58 |
59 | def last_part_partial_match(command_parts):
60 | if len(command_parts) == current_part + 1:
61 | if command_parts[current_part] != (parts_before_cursor[current_part]):
62 | return command_parts[current_part].startswith(
63 | parts_before_cursor[current_part]
64 | )
65 |
66 | # Check all commands for matches
67 | for command in self.commands:
68 | # If all command parts exactly match, suggest the user can hit enter
69 | if command.string_parts == parts_before_cursor:
70 | yield Completion("", 0, display="", display_meta=command.desc)
71 |
72 | elif previous_parts_match(command.string_parts):
73 | # Suggest next parts (words) for commands that match so far
74 | if last_part_full_match(command.string_parts):
75 | yield Completion(
76 | command.string_parts[current_part + 1],
77 | 0,
78 | display_meta=command.desc,
79 | )
80 |
81 | # Keep suggesting the parts (words) for commands that still match
82 | elif last_part_partial_match(command.string_parts):
83 | yield Completion(
84 | command.string_parts[current_part],
85 | -len(parts_before_cursor[current_part]),
86 | display_meta=command.desc,
87 | )
88 |
--------------------------------------------------------------------------------
/src/ctui/dialogs.py:
--------------------------------------------------------------------------------
1 | """
2 | Control Things User Interface, aka ctui.py
3 |
4 | # Copyright (C) 2019 Justin Searle
5 | #
6 | # This program is free software: you can redistribute it and/or modify it under
7 | # the terms of the GNU General Public License as published by the Free Software
8 | # Foundation, either version 3 of the License, or any later version.
9 | #
10 | # This program is distributed in the hope that it will be useful, but WITHOUT
11 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 | # details at .
14 | """
15 | from asyncio import Future, ensure_future
16 |
17 | from prompt_toolkit.application.current import get_app
18 | from prompt_toolkit.formatted_text import to_formatted_text
19 | from prompt_toolkit.formatted_text.utils import fragment_list_to_text
20 | from prompt_toolkit.layout.containers import Float, HSplit
21 | from prompt_toolkit.layout.dimension import D
22 | from prompt_toolkit.utils import get_cwidth
23 | from prompt_toolkit.widgets import Dialog, Label, TextArea
24 |
25 | from .base import Button
26 |
27 |
28 | class YesNoDialog(object):
29 | def __init__(
30 | self,
31 | title="",
32 | text="",
33 | yes_text="Yes",
34 | no_text="No",
35 | width=None,
36 | wrap_lines=True,
37 | scrollbar=False,
38 | ):
39 | self.future = Future()
40 |
41 | def yes_handler():
42 | self.future.set_result(True)
43 |
44 | def no_handler():
45 | self.future.set_result(False)
46 |
47 | text_width = len(max(text.split("\n"), key=len)) + 2
48 |
49 | self.text_area = TextArea(
50 | text=text,
51 | read_only=True,
52 | # focus_on_click = True,
53 | focusable=False,
54 | width=D(preferred=text_width),
55 | wrap_lines=wrap_lines,
56 | scrollbar=scrollbar,
57 | )
58 |
59 | self.dialog = Dialog(
60 | title=title,
61 | body=self.text_area,
62 | buttons=[
63 | Button(text=yes_text, width=1, handler=yes_handler),
64 | Button(text=no_text, width=1, handler=no_handler),
65 | ],
66 | with_background=True,
67 | modal=True,
68 | )
69 |
70 | def __pt_container__(self):
71 | return self.dialog
72 |
73 |
74 | class TextInputDialog(object):
75 | def __init__(
76 | self,
77 | title="",
78 | text="",
79 | ok_text="Ok",
80 | width=None,
81 | wrap_lines=True,
82 | scrollbar=False,
83 | ):
84 | self.future = Future()
85 |
86 | def accept_text(buf):
87 | get_app().layout.focus(ok_button)
88 | buf.complete_state = None
89 | return True
90 |
91 | def accept():
92 | self.future.set_result(self.text_area.text)
93 |
94 | def cancel():
95 | self.future.set_result(None)
96 |
97 | text_width = len(max(text.split("\n"), key=len)) + 2
98 |
99 | self.text_area = TextArea(
100 | # completer=completer,
101 | multiline=False,
102 | width=D(preferred=text_width),
103 | accept_handler=accept_text,
104 | )
105 |
106 | ok_button = Button(text="OK", handler=accept)
107 | cancel_button = Button(text="Cancel", handler=cancel)
108 |
109 | self.dialog = Dialog(
110 | title=title,
111 | body=HSplit([Label(text=text), self.text_area]),
112 | buttons=[ok_button, cancel_button],
113 | width=width,
114 | modal=True,
115 | )
116 |
117 | def __pt_container__(self):
118 | return self.dialog
119 |
120 |
121 | class MessageDialog(object):
122 | def __init__(
123 | self,
124 | title="",
125 | text="",
126 | ok_text="Ok",
127 | lexer=None,
128 | width=None,
129 | wrap_lines=True,
130 | scrollbar=False,
131 | ):
132 | self.future = Future()
133 | self.text = text
134 |
135 | def set_done():
136 | self.future.set_result(None)
137 |
138 | def get_text_width():
139 | if width is None:
140 | text_fragments = to_formatted_text(self.text)
141 | text = fragment_list_to_text(text_fragments)
142 | if text:
143 | longest_line = max(get_cwidth(line) for line in text.splitlines())
144 | else:
145 | return D(preferred=0)
146 | return D(preferred=longest_line)
147 | else:
148 | return width
149 |
150 | # text_width = len(max(self.text.split('\n'), key=len)) + 2
151 | # text_height = len(text.split('\n'))
152 |
153 | # TODO: Add dynamic_h_scrollbar to TextArea and this Dialog
154 | # def dynamic_horizontal_scrollbar():
155 | # max_text_width = get_app().renderer.output.get_size().columns - 2
156 |
157 | def dynamic_virtical_scrollbar():
158 | text_fragments = to_formatted_text(self.text)
159 | text = fragment_list_to_text(text_fragments)
160 | if text:
161 | text_height = len(self.text.splitlines())
162 | max_text_height = get_app().renderer.output.get_size().rows - 6
163 | if text_height > max_text_height:
164 | return True
165 |
166 | self.text_area = TextArea(
167 | text=text,
168 | lexer=lexer,
169 | read_only=True,
170 | focusable=False,
171 | width=get_text_width(),
172 | wrap_lines=wrap_lines,
173 | scrollbar=dynamic_virtical_scrollbar(),
174 | )
175 |
176 | ok_button = Button(text="OK", handler=(lambda: set_done()))
177 |
178 | self.dialog = Dialog(
179 | title=title,
180 | body=self.text_area,
181 | buttons=[ok_button],
182 | width=width,
183 | modal=True,
184 | )
185 |
186 | def __pt_container__(self):
187 | return self.dialog
188 |
189 |
190 | async def show_dialog(dialog):
191 | "Coroutine."
192 | app = get_app()
193 | float_ = Float(content=dialog)
194 | app.layout.container.floats.insert(0, float_)
195 | focused_before = app.layout.current_window
196 | app.layout.focus(dialog)
197 | result = await dialog.future
198 | app.layout.focus(focused_before)
199 |
200 | if float_ in app.layout.container.floats:
201 | app.layout.container.floats.remove(float_)
202 |
203 | return result
204 |
205 |
206 | # Functions that use dialog classes and return results
207 |
208 |
209 | def func_pass():
210 | pass
211 |
212 |
213 | def yes_no_dialog(
214 | title="",
215 | text="",
216 | yes_text="Yes",
217 | yes_func=func_pass,
218 | no_text="No",
219 | no_func=func_pass,
220 | ):
221 | """
222 | Display a Yes/No dialog.
223 | Execute a passed function.
224 | """
225 |
226 | async def coroutine():
227 | dialog = YesNoDialog(title=title, text=text, yes_text=yes_text, no_text=no_text)
228 | result = await show_dialog(dialog)
229 | if result == True:
230 | yes_func()
231 | else:
232 | no_func()
233 |
234 | ensure_future(coroutine())
235 |
236 |
237 | # def button_dialog(title='', text='', buttons=[], style=None):
238 | # """
239 | # Display a dialog with button choices (given as a list of tuples).
240 | # Return the value associated with button.
241 | # """
242 |
243 |
244 | def input_dialog(
245 | title="",
246 | text="",
247 | ok_text="OK",
248 | cancel_text="Cancel",
249 | completer=None,
250 | password=False,
251 | ):
252 | """
253 | Display a text input box.
254 | Return the given text, or None when cancelled.
255 | """
256 | output_text = ""
257 |
258 | async def coroutine():
259 | global output_text
260 | open_dialog = TextInputDialog(title, text, completer)
261 |
262 | output_text = await show_dialog(open_dialog)
263 |
264 | ensure_future(coroutine())
265 | return output_text
266 |
267 |
268 | def message_dialog(
269 | title="",
270 | text="",
271 | ok_text="Ok",
272 | lexer=None,
273 | width=None,
274 | wrap_lines=True,
275 | scrollbar=None,
276 | ):
277 | """
278 | Display a simple message box and wait until the user presses enter.
279 | """
280 |
281 | async def coroutine():
282 | dialog = MessageDialog(
283 | title=title,
284 | text=text,
285 | ok_text=ok_text,
286 | width=width,
287 | wrap_lines=wrap_lines,
288 | scrollbar=scrollbar,
289 | )
290 | await show_dialog(dialog)
291 |
292 | ensure_future(coroutine())
293 |
294 |
295 | # def radiolist_dialog(title='', text='', ok_text='Ok', cancel_text='Cancel',
296 | # values=None, style=None):
297 | # """
298 | # Display a simple list of element the user can choose amongst.
299 | #
300 | # Only one element can be selected at a time using Arrow keys and Enter.
301 | # The focus can be moved between the list and the Ok/Cancel button with tab.
302 | # """
303 |
304 |
305 | # def progress_dialog(title='', text='', run_callback=None, style=None):
306 | # """
307 | # :param run_callback: A function that receives as input a `set_percentage`
308 | # function and it does the work.
309 | # """
310 |
--------------------------------------------------------------------------------
/src/ctui/functions.py:
--------------------------------------------------------------------------------
1 | """
2 | Control Things User Interface, aka ctui.py
3 |
4 | # Copyright (C) 2019 Justin Searle
5 | #
6 | # This program is free software: you can redistribute it and/or modify it under
7 | # the terms of the GNU General Public License as published by the Free Software
8 | # Foundation, either version 3 of the License, or any later version.
9 | #
10 | # This program is distributed in the hope that it will be useful, but WITHOUT
11 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 | # details at .
14 | """
15 | import datetime
16 | import time
17 |
18 | from prompt_toolkit.document import Document
19 | from prompt_toolkit.filters import has_focus
20 | from prompt_toolkit.key_binding import KeyBindings
21 | from prompt_toolkit.search import SearchDirection, start_search
22 | from tabulate import tabulate
23 |
24 | from .dialogs import message_dialog
25 |
26 |
27 | def scroll_line_down(event):
28 | """Scroll output_field down one line, leaving cursor at bottom"""
29 | event.app.layout.focus(event.app.output_field)
30 | w = event.app.layout.current_window
31 | b = event.app.current_buffer
32 | if w and w.render_info:
33 | line_index = w.render_info.last_visible_line() + 1
34 | b.cursor_position = b.document.translate_row_col_to_index(line_index, 0)
35 | b.cursor_position += b.document.get_start_of_line_position(
36 | after_whitespace=True
37 | )
38 | w.vertical_scroll = 0
39 | event.app.layout.focus(event.app.input_field)
40 |
41 |
42 | def scroll_line_up(event):
43 | """Scroll output_field up one line, leaving cursor at bottom"""
44 | event.app.layout.focus(event.app.output_field)
45 | w = event.app.layout.current_window
46 | b = event.app.current_buffer
47 | if w and w.render_info:
48 | if w.render_info.first_visible_line() != 0:
49 | line_index = w.render_info.last_visible_line() - 1
50 | b.cursor_position = b.document.translate_row_col_to_index(line_index, 0)
51 | b.cursor_position += b.document.get_start_of_line_position(
52 | after_whitespace=True
53 | )
54 | w.vertical_scroll = 0
55 | event.app.layout.focus(event.app.input_field)
56 |
57 |
58 | def scroll_page_down(event):
59 | """Scroll output_field down one page, leaving cursor at bottom"""
60 | event.app.layout.focus(event.app.output_field)
61 | w = event.app.layout.current_window
62 | b = event.app.current_buffer
63 | if w and w.render_info:
64 | line_index = w.render_info.last_visible_line() + w.render_info.window_height
65 | b.cursor_position = b.document.translate_row_col_to_index(line_index, 0)
66 | b.cursor_position += b.document.get_start_of_line_position(
67 | after_whitespace=True
68 | )
69 | w.vertical_scroll = 0
70 | event.app.layout.focus(event.app.input_field)
71 |
72 |
73 | def scroll_page_up(event):
74 | """Scroll output_field up one page, leaving cursor at bottom"""
75 | event.app.layout.focus(event.app.output_field)
76 | w = event.app.layout.current_window
77 | b = event.app.current_buffer
78 | if w and w.render_info:
79 | if w.render_info.first_visible_line() != 0:
80 | line_index = max(
81 | w.render_info.first_visible_line() - 1, w.render_info.window_height - 1
82 | )
83 | b.cursor_position = b.document.translate_row_col_to_index(line_index, 0)
84 | b.cursor_position += b.document.get_start_of_line_position(
85 | after_whitespace=True
86 | )
87 | w.vertical_scroll = 0
88 | event.app.layout.focus(event.app.input_field)
89 |
90 |
91 | def scroll_end(event):
92 | """Scroll output_field to first page, leaving cursor at bottom"""
93 | event.app.layout.focus(event.app.output_field)
94 | w = event.app.layout.current_window
95 | b = event.app.current_buffer
96 | if w and w.render_info:
97 | line_index = w.render_info.ui_content.line_count - 1
98 | b.cursor_position = b.document.translate_row_col_to_index(line_index, 0)
99 | b.cursor_position += b.document.get_start_of_line_position(
100 | after_whitespace=True
101 | )
102 | w.vertical_scroll = 0
103 | event.app.layout.focus(event.app.input_field)
104 |
105 |
106 | def scroll_home(event):
107 | """Scroll output_field to last page, leaving cursor at bottom"""
108 | event.app.layout.focus(event.app.output_field)
109 | w = event.app.layout.current_window
110 | b = event.app.current_buffer
111 | if w and w.render_info:
112 | line_index = 0
113 | b.cursor_position = b.document.translate_row_col_to_index(line_index, 0)
114 | b.cursor_position += b.document.get_start_of_line_position(
115 | after_whitespace=True
116 | )
117 | w.vertical_scroll = 0
118 | event.app.layout.focus(event.app.input_field)
119 |
120 |
121 | def show_help(ctui):
122 | dialog = "{}\n\n{}\n\nAvaiable commands are:\n\n".format(
123 | ctui.welcome, ctui.help_message
124 | )
125 | table = []
126 | for command in ctui.commands:
127 | if len(command.string.split()) == 1:
128 | table.append((command.string, command.desc))
129 | dialog += tabulate(sorted(table), tablefmt="plain")
130 | message_dialog("Help", dialog)
131 |
--------------------------------------------------------------------------------
/src/ctui/kaitai/velocio.ksy:
--------------------------------------------------------------------------------
1 | meta:
2 | id: velocio
3 | title: Velocio Protocol
4 | license: CCO-1.0
5 | doc: The Velocio protocol is a propritary protcol used by Velocio vBuilder and vFactory to program the Velocio Ace and Branch PLCs.
6 | seq:
7 | - id: prot_id
8 | size: 3
9 | doc: Magic number for Velocio protocol (56FFFF)
10 | - id: f_len
11 | size: 2
12 | doc: Length of full serial frame
13 | - id: func
14 | size: 1
15 | type: u1be
16 | enum: func_types
17 | - id: func_data
18 | enums:
19 | func_types:
20 | 0xF0: change_debug_state
21 | 0xF1: change_execution_state
22 | 0xF3: request_status
23 | 0xF4: set_breakpoint
24 | 0xF5: Stopped Object Request
25 | 0x14: Get Device Properties
26 | 0x10: enumerate_tags
27 | 0x40: ??? (no changes)
28 | 0x91: set_sime
29 | 0x92: read_time
30 | 0xAA: erase_program
31 |
32 |
--------------------------------------------------------------------------------
/src/ctui/keybindings.py:
--------------------------------------------------------------------------------
1 | """
2 | Control Things User Interface, aka ctui.py
3 |
4 | # Copyright (C) 2019 Justin Searle
5 | #
6 | # This program is free software: you can redistribute it and/or modify it under
7 | # the terms of the GNU General Public License as published by the Free Software
8 | # Foundation, either version 3 of the License, or any later version.
9 | #
10 | # This program is distributed in the hope that it will be useful, but WITHOUT
11 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 | # details at .
14 | """
15 | import time
16 | import traceback
17 | from datetime import datetime
18 |
19 | from prompt_toolkit.document import Document
20 | from prompt_toolkit.filters import has_focus
21 | from prompt_toolkit.formatted_text import HTML, to_formatted_text
22 | from prompt_toolkit.key_binding import KeyBindings
23 | from prompt_toolkit.search import SearchDirection, start_search
24 |
25 | from .dialogs import message_dialog
26 | from .functions import (
27 | scroll_end,
28 | scroll_home,
29 | scroll_line_down,
30 | scroll_line_up,
31 | scroll_page_down,
32 | scroll_page_up,
33 | )
34 |
35 |
36 | def get_key_bindings(ctui):
37 | """Return keybinding object for application shortcut keys"""
38 | input_field = ctui.layout.input_field
39 | output_field = ctui.layout.output_field
40 | kb = KeyBindings()
41 |
42 | #######################
43 | # Global key bindings #
44 | #######################
45 |
46 | @kb.add("c-q") # None-graceful shutdown, ctui.exit() is graceful
47 | def _(event):
48 | "Pressing Ctrl-Q will force quit the user interface."
49 | # ctui.do_exit(input_field.text, output_field.text, event)
50 | ctui.app.exit()
51 |
52 | @kb.add("c-d")
53 | def _(event):
54 | """Press Ctrl-D to start the python debugger"""
55 | import pdb
56 |
57 | pdb.set_trace()
58 |
59 | #################################
60 | # Input Field ONLY key bindings #
61 | #################################
62 |
63 | @kb.add("enter", filter=has_focus(input_field))
64 | def _(event):
65 | if len(input_field.text) == 0:
66 | return
67 | # Process commands on prompt after hitting enter key
68 | # do_function, args = ctui._extract_do_function(input_field.text)
69 | #
70 | # if do_function:
71 | # try:
72 | # output_text = ctui._execute(do_function, args, output_field.text)
73 | # except AssertionError as error:
74 | # message_dialog(title='Error', text=str(error))
75 | # except:
76 | # message_dialog(title='Error', text=traceback.format_exc(),
77 | # scrollbar=True)
78 |
79 | try:
80 | command, kwargs = ctui.commands.extract(input_field.text)
81 | if command:
82 | ctui.output_text = output_field.text
83 | output_text = command.execute(**kwargs)
84 | except AssertionError as error:
85 | message_dialog(title="Error", text=str(error))
86 | except:
87 | message_dialog(title="Error", text=traceback.format_exc(), scrollbar=True)
88 |
89 | # For invalid commands forcing users to correct them
90 | if "output_text" not in locals() or output_text == False:
91 | return
92 |
93 | date, time = str(datetime.today()).split()
94 | ctui.history.insert(
95 | {"Date": date, "Time": time.split(".")[0], "Command": input_field.text}
96 | )
97 | input_field.buffer.reset(append_to_history=True)
98 |
99 | # For commands that do not have output_text
100 | if output_text == None:
101 | input_field.text = ""
102 | return
103 | else:
104 | output_field.buffer.document = Document(
105 | text=output_text, cursor_position=len(output_text)
106 | )
107 | input_field.text = ""
108 |
109 | @kb.add("c-c", filter=has_focus(input_field))
110 | def _(event):
111 | """Pressing Control-C will copy highlighted text to clipboard"""
112 | data = input_field.buffer.copy_selection()
113 | ctui.app.clipboard.set_data(data)
114 |
115 | @kb.add("c-p", filter=has_focus(input_field))
116 | def _(event):
117 | """Pressing Control-P will paste text from clipboard"""
118 | input_field.buffer.paste_clipboard_data(ctui.app.clipboard.get_data())
119 |
120 | #############################################
121 | # Key bindings that affect the output_field #
122 | #############################################
123 |
124 | @kb.add("pagedown", filter=has_focus(input_field))
125 | def _(event):
126 | """Scroll output_field down one page"""
127 | scroll_page_down(event)
128 |
129 | @kb.add("pageup", filter=has_focus(input_field))
130 | def _(event):
131 | """Scroll output_field up one page"""
132 | scroll_page_up(event)
133 |
134 | @kb.add("c-j", filter=has_focus(input_field))
135 | @kb.add("c-down", filter=has_focus(input_field))
136 | def _(event):
137 | """Scroll output_field down one line"""
138 | scroll_line_down(event)
139 |
140 | @kb.add("c-k", filter=has_focus(input_field))
141 | @kb.add("c-up", filter=has_focus(input_field))
142 | def _(event):
143 | """Scroll output_field down one line"""
144 | scroll_line_up(event)
145 |
146 | @kb.add("end", filter=has_focus(input_field))
147 | def _(event):
148 | """Scroll output_field down one line"""
149 | scroll_end(event)
150 |
151 | @kb.add("home", filter=has_focus(input_field))
152 | def _(event):
153 | """Scroll output_field down one line"""
154 | scroll_home(event)
155 |
156 | # kb.add('pagedown', filter=has_focus(output_field))(scroll_page_down)
157 | # kb.add('space', filter=has_focus(output_field))(scroll_page_down)
158 | # kb.add('f', filter=has_focus(output_field))(scroll_page_down)
159 | # kb.add('pageup')(scroll_page_up)
160 | # kb.add('b')(scroll_page_up)
161 | #
162 | # @kb.add('q', filter=has_focus(output_field))
163 | # def _(event):
164 | # """Quit navigation back to input_field"""
165 | # ctui.app.layout.focus_previous()
166 | #
167 | # @kb.add('/', filter=has_focus(output_field))
168 | # def _(event):
169 | # """Search and highlight strigs in output_field"""
170 | # start_search(output_field.control)
171 | #
172 | # @kb.add('g', filter=has_focus(output_field))
173 | # def _(event):
174 | # """Goto beginning of output_field"""
175 | # output_field.buffer.document = Document(
176 | # text=output_field.text, cursor_position=0)
177 | #
178 | # @kb.add('G', filter=has_focus(output_field))
179 | # def _(event):
180 | # """Goto end of output_field"""
181 | # output_field.buffer.document = Document(
182 | # text=output_field.text, cursor_position=len(output_field.text))
183 | #
184 | # @kb.add('n', filter=has_focus(output_field))
185 | # def _(event):
186 | # """Goto next item in output_field search"""
187 | # search_state = ctui.app.current_search_state
188 | # cursor_position = output_field.buffer.get_search_position(
189 | # search_state, include_current_position=False)
190 | # output_field.buffer.cursor_position = cursor_position
191 | #
192 | # @kb.add('N', filter=has_focus(output_field))
193 | # def _(event):
194 | # """Goto previous item in output_field search"""
195 | # search_state = ctui.app.current_search_state
196 | # cursor_position = output_field.buffer.get_search_position(
197 | # ~search_state, include_current_position=True)
198 | # output_field.buffer.cursor_position = cursor_position
199 | #
200 | # @kb.add('c-c', filter=has_focus(output_field))
201 | # def _(event):
202 | # """Pressing Control-C will copy highlighted text to clipboard"""
203 | # data = output_field.buffer.copy_selection()
204 | # ctui.app.clipboard.set_data(data)
205 | #
206 | # @kb.add('', filter=has_focus(output_field))
207 | # @kb.add('enter', filter=has_focus(output_field))
208 | # @kb.add('c-c', filter=has_focus(output_field))
209 | # def _(event):
210 | # """Prevent user from editing output_field"""
211 | # pass
212 |
213 | return kb
214 |
--------------------------------------------------------------------------------
/src/ctui/layout.py:
--------------------------------------------------------------------------------
1 | """
2 | Control Things User Interface, aka ctui.py
3 |
4 | # Copyright (C) 2019 Justin Searle
5 | #
6 | # This program is free software: you can redistribute it and/or modify it under
7 | # the terms of the GNU General Public License as published by the Free Software
8 | # Foundation, either version 3 of the License, or any later version.
9 | #
10 | # This program is distributed in the hope that it will be useful, but WITHOUT
11 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 | # details at .
14 | """
15 | from pathlib import Path
16 |
17 | from prompt_toolkit.history import FileHistory
18 | from prompt_toolkit.layout.containers import (
19 | Float,
20 | FloatContainer,
21 | HSplit,
22 | VSplit,
23 | Window,
24 | )
25 | from prompt_toolkit.layout.controls import FormattedTextControl
26 | from prompt_toolkit.layout.menus import CompletionsMenu
27 | from prompt_toolkit.lexers import Lexer
28 | from prompt_toolkit.widgets import MenuContainer, MenuItem, SearchToolbar, TextArea
29 |
30 | from ctui.completion import CommandCompleter
31 | from ctui.functions import show_help
32 |
33 |
34 | class CtuiLayout(object):
35 | """Class to facilitate editing and accessing different layout elements"""
36 |
37 | def __init__(
38 | self,
39 | ctui=None,
40 | input_field=None,
41 | output_field=None,
42 | statusbar=None,
43 | root_container=None,
44 | ):
45 | self.ctui = ctui
46 |
47 | self._completer = CommandCompleter(ctui.commands)
48 |
49 | self._history = FileHistory(
50 | "{}/.{}_history".format(Path.home(), self.ctui.name)
51 | )
52 |
53 | self._input_field = TextArea(
54 | height=1,
55 | prompt=self.ctui.prompt,
56 | style="class:input_field",
57 | completer=self.completer,
58 | history=self.history,
59 | )
60 |
61 | self._header_field = Window(height=1, char="-", style="class:line")
62 |
63 | self._output_field = TextArea(
64 | text="",
65 | style="class:output_field",
66 | wrap_lines=self.ctui.wrap_lines,
67 | scrollbar=True,
68 | )
69 |
70 | self._statusbar = Window(
71 | content=FormattedTextControl(self.statusbar_text),
72 | height=1,
73 | style="class:statusbar",
74 | )
75 |
76 | self._body = FloatContainer(
77 | HSplit(
78 | [self.input_field, self.header_field, self.output_field, self.statusbar]
79 | ),
80 | floats=[
81 | Float(
82 | xcursor=True,
83 | ycursor=True,
84 | content=CompletionsMenu(max_height=16, scroll_offset=1),
85 | )
86 | ],
87 | )
88 |
89 | self._root_container = MenuContainer(
90 | body=self.body,
91 | menu_items=[
92 | MenuItem(
93 | "Session ",
94 | children=[
95 | MenuItem("Connect"),
96 | MenuItem("Disconnect"),
97 | # MenuItem('Save'),
98 | # MenuItem('Save as...'),
99 | # MenuItem('-', disabled=True),
100 | MenuItem("Exit"),
101 | ],
102 | ),
103 | MenuItem(
104 | "Edit ",
105 | children=[
106 | MenuItem("Copy"),
107 | MenuItem("Paste"),
108 | ],
109 | ),
110 | MenuItem(
111 | "Help ",
112 | children=[
113 | MenuItem("Help", handler=show_help),
114 | MenuItem("About"),
115 | ],
116 | ),
117 | ],
118 | floats=[
119 | Float(
120 | xcursor=True,
121 | ycursor=True,
122 | content=CompletionsMenu(max_height=16, scroll_offset=1),
123 | ),
124 | ],
125 | )
126 |
127 | @property
128 | def completer(self):
129 | return self._completer
130 |
131 | @property
132 | def history(self):
133 | return self._history
134 |
135 | @property
136 | def input_field(self):
137 | return self._input_field
138 |
139 | @property
140 | def header_field(self):
141 | return self._header_field
142 |
143 | @property
144 | def output_field(self):
145 | return self._output_field
146 |
147 | @property
148 | def statusbar_text(self):
149 | return self.ctui._statusbar
150 |
151 | @property
152 | def statusbar(self):
153 | return self._statusbar
154 |
155 | # Organization of windows
156 | @property
157 | def body(self):
158 | return self._body
159 |
160 | # Adding menus
161 | @property
162 | def root_container(self):
163 | return self._body
164 | # return self._root_container
165 |
--------------------------------------------------------------------------------
/src/ctui/style.py:
--------------------------------------------------------------------------------
1 | """
2 | Control Things User Interface, aka ctui.py
3 |
4 | # Copyright (C) 2019 Justin Searle
5 | #
6 | # This program is free software: you can redistribute it and/or modify it under
7 | # the terms of the GNU General Public License as published by the Free Software
8 | # Foundation, either version 3 of the License, or any later version.
9 | #
10 | # This program is distributed in the hope that it will be useful, but WITHOUT
11 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 | # details at .
14 | """
15 | from prompt_toolkit.styles import Style
16 |
17 |
18 | class CtuiStyle(object):
19 | """Class to expose individual style values to ctui"""
20 |
21 | def __init__(self):
22 | self._theme = self.dark_theme
23 |
24 | @property
25 | def theme(self):
26 | return self._theme
27 |
28 | @theme.setter
29 | def theme(self, value):
30 | if value == "dark":
31 | self._theme = self.dark_theme
32 | elif value == "light":
33 | self._theme = self.light_theme
34 | else:
35 | raise ValueError('Must be "dark" or "light"')
36 |
37 | dark_theme = Style.from_dict(
38 | {
39 | # Main windows.
40 | "input_field": "bg:#101010 #e0e0e0",
41 | "input_field last-line": "nounderline",
42 | "line": "bg:#202020 ansibrightcyan",
43 | "output_field": "bg:#202020 ansicyan",
44 | "output_field scrollbar.background": "",
45 | "output_field scrollbar.button": "bg:#000000",
46 | "output_field scrollbar.arrow": "",
47 | "output_field scrollbar.start": "nounderline",
48 | "output_field scrollbar.end": "nounderline",
49 | "line last-line": "nounderline",
50 | "statusbar": "bg:#AAAAAA",
51 | # Dialog windows.
52 | "dialog": "bg:#4444ff",
53 | "dialog frame.label": "#ansibrightyellow bold",
54 | "dialog.body": "bg:#111111 ansiyellow",
55 | "dialog.body text-area": "bg:#111111 ansiyellow",
56 | "dialog.body text-area last-line": "nounderline",
57 | "dialog.body scrollbar.background": "",
58 | "dialog.body scrollbar.button": "bg:#000000",
59 | "dialog.body scrollbar.arrow": "",
60 | "dialog.body scrollbar.start": "nounderline",
61 | "dialog.body scrollbar.end": "nounderline",
62 | "button": "",
63 | "button.arrow": "bold",
64 | "button.focused": "bg:ansibrightyellow #101010",
65 | # Menu bars.
66 | "menu-bar": "bg:#aaaaaa #000000",
67 | "menu-bar.selected-item": "bg:#ffffff #000000",
68 | "menu": "bg:#888888 #ffffff",
69 | "menu.border": "#aaaaaa",
70 | "menu.border shadow": "#444444",
71 | # Shadows.
72 | "dialog shadow": "bg:#000088",
73 | "dialog.body shadow": "bg:#aaaaaa",
74 | # Progress-bars.
75 | "progress-bar": "bg:#000088",
76 | "progress-bar.used": "bg:#ff0000",
77 | }
78 | )
79 |
80 | light_theme = Style.from_dict(
81 | {
82 | # Main windows.
83 | "input_field": "bg:#101010 #e0e0e0",
84 | "input_field last-line": "nounderline",
85 | "line": "bg:#202020 ansibrightcyan",
86 | "output_field": "bg:#202020 ansicyan",
87 | "output_field scrollbar.background": "",
88 | "output_field scrollbar.button": "bg:#000000",
89 | "output_field scrollbar.arrow": "",
90 | "output_field scrollbar.start": "nounderline",
91 | "output_field scrollbar.end": "nounderline",
92 | "line last-line": "nounderline",
93 | "statusbar": "bg:#AAAAAA",
94 | # Dialog windows.
95 | "dialog": "bg:#4444ff",
96 | "dialog frame.label": "#ansibrightyellow bold",
97 | "dialog.body": "bg:#111111 ansiyellow",
98 | "dialog.body text-area": "bg:#111111 ansiyellow",
99 | "dialog.body text-area last-line": "nounderline",
100 | "dialog.body scrollbar.background": "",
101 | "dialog.body scrollbar.button": "bg:#000000",
102 | "dialog.body scrollbar.arrow": "",
103 | "dialog.body scrollbar.start": "nounderline",
104 | "dialog.body scrollbar.end": "nounderline",
105 | "button": "",
106 | "button.arrow": "bold",
107 | "button.focused": "bg:ansibrightyellow #101010",
108 | # Menu bars.
109 | "menu-bar": "bg:#aaaaaa #000000",
110 | "menu-bar.selected-item": "bg:#ffffff #000000",
111 | "menu": "bg:#888888 #ffffff",
112 | "menu.border": "#aaaaaa",
113 | "menu.border shadow": "#444444",
114 | # Shadows.
115 | "dialog shadow": "bg:#000088",
116 | "dialog.body shadow": "bg:#aaaaaa",
117 | # Progress-bars.
118 | "progress-bar": "bg:#000088",
119 | "progress-bar.used": "bg:#ff0000",
120 | }
121 | )
122 |
--------------------------------------------------------------------------------
/src/ctui/types.py:
--------------------------------------------------------------------------------
1 | """
2 | Control Things User Interface, aka ctui.py
3 |
4 | # Copyright (C) 2019 Justin Searle
5 | #
6 | # This program is free software: you can redistribute it and/or modify it under
7 | # the terms of the GNU General Public License as published by the Free Software
8 | # Foundation, either version 3 of the License, or any later version.
9 | #
10 | # This program is distributed in the hope that it will be useful, but WITHOUT
11 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 | # details at .
14 | """
15 | import re
16 | from typing import List, NewType
17 |
18 | Hex = NewType("Hex", bytes)
19 | Bin = NewType("Bin", bool)
20 | # These Greedy types can only be used on the last argument of functions
21 | GreedyStr = NewType("GreedyStr", str)
22 | GreedyBytes = NewType("GreedyBytes", bytes)
23 | GreedyHex = NewType("GreedyHex", bytes)
24 | GreedyBin = NewType("GreedyBin", List[bool])
25 | GreedyInt = NewType("GreedyInt", List[int])
26 | GreedyFloat = NewType("GreedyFloat", List[float])
27 |
28 |
29 | def is_greedy(argtype):
30 | return argtype in [
31 | GreedyStr,
32 | GreedyBytes,
33 | GreedyHex,
34 | GreedyBin,
35 | GreedyInt,
36 | GreedyFloat,
37 | ]
38 |
39 |
40 | def to_type(value, kwarg):
41 | if kwarg.type == str:
42 | return value
43 |
44 | elif kwarg.type == int:
45 | assert value.isdigit, f"{kwarg.name} must be an digit"
46 | return int(value)
47 |
48 | elif kwarg.type == float:
49 | assert value.isdecimal, f"{kwarg.name} must be an decimal"
50 | return float(value)
51 |
52 | elif kwarg.type == GreedyStr:
53 | return value
54 |
55 | elif kwarg.type == GreedyBytes:
56 | return value
57 |
58 | elif kwarg.type == GreedyHex or kwarg.type == Hex:
59 | data = value.lower().replace("0x", "")
60 | if re.match("^[0123456789abcdef\\\\x ]+$", data):
61 | raw_hex = re.sub("[\\\\x ]", "", data)
62 | if len(raw_hex) % 2 == 0:
63 | return bytes.fromhex(raw_hex)
64 | else:
65 | raise AssertionError(f"{kwarg.name} must be hex characters")
66 |
67 | elif kwarg.type == GreedyInt or kwarg.type == List[int]:
68 | list_int = []
69 | for digit in value.split():
70 | assert digit.isdigit, f"{kwarg.name} must a sequence of digits"
71 | list_int.append(int(digit))
72 | return list_int
73 |
74 | elif kwarg.type == GreedyFloat or kwarg.type == List[float]:
75 | list_float = []
76 | for decimal in value.split():
77 | assert decimal.isdecimal, f"{kwarg.name} must a sequence of decimals"
78 | list_float.append(float(decimal))
79 | return list_float
80 |
81 | elif kwarg.type == GreedyBin or kwarg.type == List[Bin]:
82 | data = value.lower().replace("0b", "")
83 | if re.match("^[01\\\\b ]+$", data):
84 | raw_bin = re.sub("[\\\\b ]", "", data)
85 | return [False if bit == "0" else True for bit in raw_bin]
86 | else:
87 | raise AssertionError(f"{kwarg.name} must be sequence of 1s and 0s")
88 |
89 | else:
90 | raise AssertionError("type not implimented yet")
91 |
--------------------------------------------------------------------------------