├── .gitignore
├── LICENSE
├── README.md
├── composer.json
├── examples
├── checklist.php
├── confirm.php
├── inputbox.php
├── menu.php
├── msgbox.php
└── notice.php
└── src
└── NcursesWidget
├── NcursesBase.php
├── NcursesChecklist.php
├── NcursesConfirm.php
├── NcursesInputBox.php
├── NcursesMenu.php
├── NcursesMsgbox.php
└── NcursesNotice.php
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .ignore support plugin (hsz.mobi)
2 | .idea
3 | composer.lock
4 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # PHP Ncurses Widget Library
2 |
3 | Ncurses based terminal ui library for PHP applications. Works with PHP 5.4 or newer.
4 |
5 | ### Widget List
6 |
7 | - Checklist [one column of checkboxes]
8 | ---
9 | 
10 |
11 | - Confirm [a basic yes/no prompt]
12 | ---
13 | 
14 |
15 | - Inputbox [supports multiple fields]
16 | ---
17 | 
18 |
19 | - Menu [a select box with up to two columns of descriptive information]
20 | ---
21 | 
22 |
23 | - Messagebox [transition screen on a timer]
24 | ---
25 | 
26 |
27 | - Notice [an alert with an "ok" button]
28 | ---
29 | 
30 |
31 | ### Prerequisites
32 |
33 | - You'll need to install PHP-CLI 5.4+
34 | - You'll need to install the ncurses extension for PHP. See [here](https://stackoverflow.com/a/47542051/3751385) for how to do that in PHP 7+.
35 |
36 | To see if you have the ncurses extension installed:
37 |
38 | ```
39 | $ php -m
40 | ```
41 |
42 | If not listed, you'll need to:
43 |
44 | ```
45 | pecl install ncurses
46 | ```
47 |
48 | ### Composer
49 |
50 | - I didn't upload this to Packagist, because you can install directly from Github by adding the following to your composer.json:
51 |
52 | ```
53 | "require": {
54 | "tecfu/php_ncurses": "*"
55 | },
56 | "repositories": [
57 | {
58 | "url":"https://github.com/tecfu/php_ncurses.git",
59 | "type":"git"
60 | }
61 | ]
62 | ```
63 |
64 | ## License
65 |
66 | GNU General Public License v3.0
67 |
68 | Copyright (c) 2007 - 2017. J Randolph Smith, jesuschristsuperstar, tecfu, et. al.
69 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "tecfu/php_ncurses",
3 | "license": "GPLv3",
4 | "type": "project",
5 | "authors": [
6 | {
7 | "name": "J Randolph Smith",
8 | "email": "johns@servangle.net"
9 | },
10 | {
11 | "name": "jesuschristsuperstar",
12 | "email": "donotreply@github.com"
13 | }
14 | ],
15 | "description": "PHP ncurses widget library",
16 | "autoload": {
17 | "psr-4": {
18 | "": "src/"
19 | }
20 | },
21 | "require": {
22 | "php": ">=5.4",
23 | "ext-ncurses": ">=1.0.0"
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/examples/checklist.php:
--------------------------------------------------------------------------------
1 | setWindowDimensions(18, 52);
11 | $dialog->setTitlePageHeader('PHP ncurses Checklist Example v.1.0.0 - Jesus Christ Superstar ');
12 | $dialog->setText("This is a checkbox selection.\nWe are testing the checkboxes.");
13 | $dialog->setTitleDialogHeader(' Food List ');
14 |
15 | $dialog->addChecklist("field-a", "Apples", "A", "Red & Green Apples", 1, true);
16 | $dialog->addChecklist("field-b", "Meats", "M", "Beef, Pork", 2, false);
17 | $dialog->addChecklist("field-c", "Seafood", "f", "Fish, Shrimp", 3, true);
18 | $dialog->addChecklist("field-d", "Vegi", "V", "Garden Greens", 4, true);
19 | $dialog->addChecklist("field-e", "Grains", "G", "Flour, Nuts", 5, false);
20 |
21 | // Show dialog box & get user input
22 | $result = $dialog->display();
23 |
24 | // Properly cleanup the screen
25 | $dialog->destroy();
26 |
27 | // Show what results we got back
28 | print "Return value:\n";
29 | var_dump($result);
30 |
--------------------------------------------------------------------------------
/examples/confirm.php:
--------------------------------------------------------------------------------
1 | setWindowDimensions(7, 35);
9 | $dialog->setTitlePageHeader('PHP ncurses Confirm Box Example v.1.0.0 - Jesus Christ Superstar ');
10 | $dialog->setText("\nContinue?");
11 | $dialog->setTitleDialogHeader('');
12 | // Show dialog box & get user input
13 | $result = $dialog->display();
14 | // Properly cleanup the screen
15 | $dialog->destroy();
16 |
17 | // Show what results we got back
18 | print "Return value:\n";
19 | var_dump($result);
20 |
--------------------------------------------------------------------------------
/examples/inputbox.php:
--------------------------------------------------------------------------------
1 | setWindowDimensions(20, 60);
11 | $dialog->setTitlePageHeader('PHP ncurses Input Box Example v.1.0.0 - Jesus Christ Superstar ');
12 | $dialog->setTitleDialogHeader(' Customer Profile ');
13 | $dialog->setText("\nInput Box Title"); //title
14 | $dialog->setInputIndentation(4);
15 | $dialog->setFields([
16 | [
17 | 'label' => 'First Name',
18 | 'name' => 'first_name',
19 | 'value' => '',
20 | 'length' => 20
21 | ],
22 | [
23 | 'label' => 'Last Name',
24 | 'name' => 'last_name',
25 | 'value' => '',
26 | 'length' => 20
27 | ]
28 | ]);
29 |
30 | // Show dialog box & get user input
31 | $result = $dialog->display();
32 |
33 | // Properly cleanup the screen
34 | $dialog->destroy();
35 |
36 | // Show what results we got back
37 | print "Return value:\n";
38 | var_dump($result);
39 |
--------------------------------------------------------------------------------
/examples/menu.php:
--------------------------------------------------------------------------------
1 | setWindowDimensions(18, 62);
11 | $dialog->setTitlePageHeader('PHP ncurses Menu Example v.1.0.0 - Jesus Christ Superstar ');
12 | $dialog->setText("\nThis is a menu test.\nPearl Jam is still good.\n");
13 | $dialog->setTitleDialogHeader(' Main Menu ');
14 |
15 | $dialog->addMenu('Standard', 'S', 'Begin standard installation', 1);
16 | $dialog->addMenu('Express', 'E', 'Express installation', 2);
17 | $dialog->addMenu('Keymap', 'K', 'Define Keymaps', 3);
18 | $dialog->addMenu('Options', 'O', 'View/Set Options', 4);
19 | $dialog->addMenu('Run', 'R', 'Start the process', 5);
20 |
21 | // Show dialog box & get user input
22 | $result = $dialog->display();
23 | // Properly cleanup the screen
24 | $dialog->destroy();
25 | // Show what results we got back
26 | print"Return value:\n";
27 |
28 | var_dump($result);
29 |
--------------------------------------------------------------------------------
/examples/msgbox.php:
--------------------------------------------------------------------------------
1 | setWindowDimensions(8, 40);
9 | $dialog->setTitlePageHeader('PHP ncurses Message Box Example v.1.0.0 - Jesus Christ Superstar ');
10 | $dialog->setText("This is a simple message box. Please press to continue.");
11 |
12 | // Show dialog box & get user input
13 | $result = $dialog->display();
14 | // Properly cleanup the screen
15 | $dialog->destroy();
16 |
17 | // Show what results we got back
18 | print "Return value:\n";
19 | var_dump($result);
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/examples/notice.php:
--------------------------------------------------------------------------------
1 | setTitlePageHeader('PHP ncurses Notice Example v.1.0.0 - Jesus Christ Superstar ');
9 | $dialog->setTitleDialogHeader(' Please Wait ');
10 |
11 | // Show dialog box & get user input
12 | for ($i = 0; $i < 5; $i++) {
13 | $dialog->setText(
14 | sprintf(
15 | "\nA notice box is great\nfor informing people while\na proccess continues.%s\n",
16 | str_repeat('.', $i)
17 | )
18 | );
19 |
20 | $dialog->display();
21 | sleep(1);
22 | }
23 |
24 | $dialog->destroy(); // Properly cleanup the screen
25 |
--------------------------------------------------------------------------------
/src/NcursesWidget/NcursesBase.php:
--------------------------------------------------------------------------------
1 | titlePageHeader = '';
187 | $this->reset();
188 | }
189 |
190 | public function configureButtons()
191 | {
192 | $button_padding = '2';
193 | $offset = 0;
194 | $count = count($this->buttons);
195 |
196 | $combined_length = 0;
197 |
198 | //GET COMBINED LENGTH OF ALL BUTTONS SO CAN TIGHTLY CENTER THEM
199 | foreach ($this->buttons as $key => $val) {
200 | //ENCLOSE BUTTONS WITH BRACKETS AND ADD TRAILING SPACE(S)
201 | $this->buttons[$key]['text'] = '[ ' . $val['text'] . ' ]';
202 | $combined_length += strlen($this->buttons[$key]['text']);
203 | }
204 |
205 | $left = round($this->width / 2) - round($combined_length / 2);
206 |
207 | foreach ($this->buttons as $key => $val) {
208 |
209 | $val['hotkey'] = (!isset($val['hotkey'])) ? '' : $val['hotkey'];
210 |
211 | //EQUIDISTANT CENTER EACH BUTTON
212 | $this->addButton($val['text'], $val['hotkey'], $val['return'], $this->height - 2, $left);
213 | $left = $left + strlen($val['text']) + 2; //+2 to leave 2 spaces between buttons
214 | }
215 | }
216 |
217 | /**
218 | * @param $height
219 | * @param $width
220 | */
221 | public function setWindowDimensions($height, $width)
222 | {
223 | $this->reset();
224 |
225 | // set hieght/width
226 | $this->setHeight((int) $height);
227 | $this->setWidth((int) $width);
228 | }
229 |
230 | protected function reset()
231 | {
232 | $this->test = '';
233 | $this->size = '';
234 | $this->height = 0;
235 | $this->width = 0;
236 |
237 | $this->buttonList = [];
238 | $this->buttonTotal = 0;
239 | $this->buttonCursor = 0;
240 |
241 | $this->inputBoxList = [];
242 | $this->inputBoxTotal = 0;
243 |
244 | $this->menuList = [];
245 | $this->menuTotal = 0;
246 | $this->menuCursor = 0;
247 | $this->menuLabelWidth = 0;
248 | $this->menuDescWidth = 0;
249 | $this->nwin = $this->swin = null;
250 | $this->textBoxChar = null;
251 | $this->textBoxLen = $textbox_max = 0;
252 |
253 | $this->focusList = [];
254 | $this->focusTotal = 0;
255 | $this->focusCursor = 0;
256 | }
257 |
258 | public function destroy()
259 | {
260 | ncurses_clear();
261 | ncurses_echo();
262 | ncurses_refresh();
263 | ncurses_end();
264 | }
265 |
266 | protected function initScreen()
267 | {
268 | ncurses_curs_set(0);
269 | ncurses_noecho();
270 | $fullscreen = ncurses_newwin(0, 0, 0, 0);
271 | ncurses_getmaxyx($fullscreen, $this->screenMaxHeight, $this->screenMaxWidth);
272 | ncurses_delwin($fullscreen);
273 |
274 | //COLOR SCHEMES
275 | ncurses_start_color();
276 | // text color, background color
277 | /*
278 | COLOR_BLACK 0
279 | COLOR_RED 1
280 | COLOR_GREEN 2
281 | COLOR_YELLOW 3
282 | COLOR_BLUE 4
283 | COLOR_MAGENTA 5
284 | COLOR_CYAN 6
285 | COLOR_WHITE 7
286 | */
287 | ncurses_init_pair(1, NCURSES_COLOR_WHITE, NCURSES_COLOR_RED);
288 | ncurses_init_pair(2, NCURSES_COLOR_BLACK, NCURSES_COLOR_WHITE);
289 | ncurses_init_pair(3, NCURSES_COLOR_WHITE, NCURSES_COLOR_WHITE);
290 | ncurses_init_pair(4, NCURSES_COLOR_BLACK, NCURSES_COLOR_RED);
291 | ncurses_init_pair(5, NCURSES_COLOR_WHITE, NCURSES_COLOR_BLUE);
292 | ncurses_init_pair(6, NCURSES_COLOR_YELLOW, NCURSES_COLOR_BLUE);
293 | ncurses_init_pair(7, NCURSES_COLOR_BLUE, NCURSES_COLOR_WHITE);
294 |
295 | ncurses_color_set(5);
296 | ncurses_erase();
297 | ncurses_mvhline(0, 0, 0, $this->screenMaxWidth);
298 | ncurses_attron(NCURSES_A_BOLD);
299 | ncurses_mvaddstr(0, 1, $this->titlePageHeader);
300 | ncurses_attroff(NCURSES_A_BOLD);
301 | for ($y = 1; $y < $this->screenMaxHeight; $y++) {
302 | ncurses_mvhline($y, 0, 32, $this->screenMaxWidth);
303 | }
304 | ncurses_refresh();
305 | }
306 |
307 | protected function drawDialogBorders(&$win, $y, $x)
308 | {
309 | // Draw boarders
310 | // ============
311 | // || ||
312 | // || ||
313 | // || ||
314 | // ------------
315 | // || ||
316 | // ============
317 | ncurses_wattron($win, NCURSES_A_BOLD);
318 | ncurses_wcolor_set($win, 3);
319 | ncurses_wmove($win, 0, 1);
320 | ncurses_whline($win, 205, $x - 2); // top line
321 |
322 | ncurses_wmove($win, $y - 3, 1);
323 | ncurses_whline($win, 0, $x - 2); // middle line
324 |
325 | ncurses_wmove($win, 1, 0);
326 | ncurses_wvline($win, 186, $y - 2); // left line
327 |
328 | ncurses_wmove($win, 0, 0);
329 | ncurses_waddch($win, 201); // top left
330 |
331 | ncurses_wmove($win, $y - 1, 0);
332 | ncurses_waddch($win, 200); // bottom left
333 |
334 | ncurses_wmove($win, $y - 3, 0);
335 | ncurses_waddch($win, 199); // middle left
336 |
337 | ncurses_wcolor_set($win, 2);
338 |
339 | //ncurses_wmove ( $win, $y-1, 1 ); ncurses_whline ( $win, 203, $x-2 ); // bottom line
340 | ncurses_wmove($win, $y - 1, 1);
341 | ncurses_wborder($win, 0, 0, 0, 0, 0, 0, 0, 0); // bottom line
342 |
343 |
344 | ncurses_wattroff($win, NCURSES_A_BOLD);
345 | }
346 |
347 | /**
348 | * Returns the Category of the current focus cursor
349 | * @return mixed
350 | */
351 | protected function focusCat()
352 | {
353 | // get current focus category
354 | list($cat, $index) = explode('-', $this->focusList[$this->focusCursor]);
355 |
356 | return $cat;
357 | }
358 |
359 | /**
360 | * Returns the Sub-index of the current focus cursor
361 | * @return mixed
362 | */
363 | protected function focusSubindex()
364 | {
365 | // get current focus index
366 | list($cat, $index) = explode('-', $this->focusList[$this->focusCursor]);
367 |
368 | return $index;
369 | }
370 |
371 | /**
372 | * Returns the top right x,y coordinates based on desired window size and alignment.
373 | * @param $height
374 | * @param $width
375 | * @param string $horizontalJust
376 | * @param string $verticalJust
377 | * @return array
378 | */
379 | protected function getCoordinates(
380 | $height,
381 | $width,
382 | $horizontalJust = self::COORD_X_CENTER,
383 | $verticalJust = self::COORD_Y_MIDDLE
384 | ) {
385 | $result = ['x' => 0, 'y' => 0];
386 |
387 | switch ($horizontalJust) {
388 | case self::COORD_X_CENTER:
389 | // Calculate offsets to center window based on window size
390 | $result['x'] = round(($this->screenMaxWidth - $width) / 2);
391 | break;
392 |
393 | case self::COORD_X_RIGHT:
394 | $result['x'] = $this->screenMaxWidth - $width;
395 | break;
396 |
397 | case self::COORD_X_LEFT:
398 | default:
399 | break;
400 | }
401 |
402 | switch ($verticalJust) {
403 | case self::COORD_Y_MIDDLE:
404 | // Calculate offsets to center window based on window size
405 | $result['y'] = round(($this->screenMaxHeight - $height) / 2);
406 | break;
407 |
408 | case self::COORD_Y_BOTTOM:
409 | $result['y'] = $this->screenMaxHeight - $height;
410 | break;
411 |
412 | case self::COORD_Y_TOP:
413 | default:
414 | break;
415 | }
416 |
417 | return ($result);
418 | }
419 |
420 | /**
421 | * @param $cord_y
422 | * @param $cord_x
423 | * @param $height
424 | * @param $width
425 | * @param bool $shadow
426 | * @param int $bordertype
427 | * @return resource
428 | */
429 | protected function createDialogWindow($cord_y, $cord_x, $height, $width, $shadow = false, $bordertype = 1)
430 | {
431 |
432 | $win = ncurses_newwin($height, $width, $cord_y, $cord_x);
433 |
434 | // shadow (optional)
435 | if ($shadow) {
436 | $this->swin = ncurses_newwin($height, $width, $cord_y + 1, $cord_x + 1);
437 | ncurses_wrefresh($this->swin);
438 | }
439 |
440 | // fill window
441 | ncurses_wcolor_set($win, 3);
442 | for ($row = 0; $row < $height; $row++) {
443 | ncurses_wmove($win, $row, 0);
444 | ncurses_whline($win, 32, $width);
445 | }
446 |
447 | // Draw the borders
448 | if ($bordertype == 1) {
449 | $this->drawDialogBorders($win, $height, $width);
450 | } else {
451 | $this->drawThinBorders($win, 0, 0, $height, $width);
452 | }
453 |
454 | // Draw dialog box title -- (optional)
455 | if ($this->titleDialogHeader != "") {
456 |
457 | $len = strlen($this->titleDialogHeader);
458 | $x = round(($width - $len) / 2);
459 | ncurses_wcolor_set($win, 1);
460 | ncurses_wattron($win, NCURSES_A_BOLD);
461 | ncurses_mvwaddstr($win, 0, $x, $this->titleDialogHeader);
462 | ncurses_wattroff($win, NCURSES_A_BOLD);
463 | ncurses_wcolor_set($win, 2);
464 | }
465 |
466 |
467 | return ($win);
468 | }
469 |
470 | /**
471 | * @param $win
472 | * @param $y
473 | * @param $x
474 | * @param $height
475 | * @param $width
476 | */
477 | protected function drawThinTopLeft(&$win, $y, $x, $height, $width)
478 | {
479 |
480 | ncurses_wmove($win, $y, $x + 1);
481 | ncurses_whline($win, 42, $width - 2); // top line
482 |
483 | ncurses_wmove($win, $y + 1, $x);
484 | ncurses_wvline($win, 42, $height - 2); // left line
485 |
486 | ncurses_wmove($win, $y, $x);
487 | ncurses_waddch($win, 42); // top left
488 |
489 | ncurses_wmove($win, $y + $height - 1, $x);
490 | ncurses_waddch($win, 42); // bottom left
491 | }
492 |
493 | /**
494 | * @param $win
495 | * @param $y
496 | * @param $x
497 | * @param $height
498 | * @param $width
499 | */
500 | protected function drawThinBotRight(&$win, $y, $x, $height, $width)
501 | {
502 |
503 | ncurses_wmove($win, $y + $height - 1, $x + 1);
504 | ncurses_whline($win, 42, $width - 2); // bottom line
505 |
506 | ncurses_wmove($win, $y + 1, $x + $width - 1);
507 | ncurses_wvline($win, 42, $height - 2); // right line
508 |
509 | ncurses_wmove($win, $y, $x + $width - 1);
510 | ncurses_waddch($win, 42);
511 |
512 | // top right
513 | ncurses_wmove($win, $y + $height - 1, $x + $width - 1);
514 | ncurses_waddch($win, 42); // bottom right
515 | }
516 |
517 | /**
518 | * @param $win
519 | * @param $y
520 | * @param $x
521 | * @param $height
522 | * @param $width
523 | * @param string $type
524 | */
525 | protected function drawThinBorders(&$win, $y, $x, $height, $width, $type = "out")
526 | {
527 | // Draw boarders
528 | // ------------
529 | // | |
530 | // | |
531 | // | |
532 | // | |
533 | // ------------
534 | ncurses_wattron($win, NCURSES_A_BOLD);
535 | if ($type === 'out') {
536 | $this->drawThinTopLeft($win, $y, $x, $height, $width);
537 | } else {
538 | $this->drawThinBotRight($win, $y, $x, $height, $width);
539 | }
540 |
541 | //BOTTOM COLOR - REMOVED / LOOKS LIKE SHIT
542 | //ncurses_wcolor_set($win,1);
543 |
544 | if ($type === 'out') {
545 | $this->drawThinBotRight($win, $y, $x, $height, $width);
546 | } else {
547 | $this->drawThinTopLeft($win, $y, $x, $height, $width);
548 | }
549 | ncurses_wattroff($win, NCURSES_A_BOLD);
550 | ncurses_wborder($win, 0, 0, 0, 0, 0, 0, 0, 0); // bottom line
551 | }
552 |
553 | /**
554 | * outputs a paragraph text and returns offset lines taken up.
555 | * @param $win
556 | * @param $text
557 | * @param $y
558 | * @param $x
559 | * @param string $align
560 | * @param bool $wrap
561 | * @return int
562 | */
563 | protected function strokePara(&$win, $text, $y, $x, $align = 'center', $wrap = true)
564 | {
565 | if ($wrap) {
566 | $text = wordwrap($text, ($x - 2), "|");
567 | }
568 | $text = str_replace("\n", "|", $text); // decode linebreaks
569 |
570 | $lines = explode("|", $text);
571 |
572 | $curs_y = 1;
573 | foreach ($lines as $line) {
574 | $len = strlen($line) + 1;
575 | if ($align === 'center') { // text alignment
576 | $text_offset_x = round(($x - $len) / 2);
577 | } else {
578 | $text_offset_x = 1;
579 | }
580 | ncurses_mvwaddstr($win, $curs_y, $text_offset_x, $line);
581 | $curs_y++;
582 | }
583 |
584 | return ($curs_y - 1); // return lines taken up
585 | }
586 |
587 | /**
588 | * initializes a button input type.
589 | * @param $name
590 | * @param $hot
591 | * @param $value
592 | * @param $y
593 | * @param $x
594 | */
595 | protected function addButton($name, $hot, $value, $y, $x)
596 | {
597 | $this->buttonList[$this->buttonTotal]['name'] = $name;
598 | $this->buttonList[$this->buttonTotal]['hot'] = $hot;
599 | $this->buttonList[$this->buttonTotal]['value'] = $value;
600 | $this->buttonList[$this->buttonTotal]['y'] = $y;
601 | $this->buttonList[$this->buttonTotal]['x'] = $x;
602 |
603 | // add to master focus list
604 | $this->focusList[$this->focusTotal] = "B-" . $this->buttonTotal;
605 |
606 | $this->buttonTotal++;
607 | $this->focusTotal++;
608 | }
609 |
610 | /**
611 | * Check if any user key input matches button hotkey designations
612 | * @param $key
613 | * @return null | mixed the value assigned to that button.
614 | */
615 | protected function checkHotButtons($key)
616 | {
617 | for ($n = 0; $n < $this->buttonTotal; $n++) {
618 | $thischar = strtolower(chr($key));
619 | $hotchar = strtolower($this->buttonList[$n]['hot']);
620 |
621 | if ($thischar == $hotchar) {
622 | return ($this->buttonList[$n]['value']);
623 | }
624 | }
625 |
626 | return (null);
627 | }
628 |
629 | /**
630 | * Check if any user key input matches Menu item hotkey designations
631 | * @param $key
632 | * @return null | mixed - the value assigned to that Menu item.
633 | */
634 | protected function checkHotMenuItems($key)
635 | {
636 | for ($n = 0; $n < $this->menuTotal; $n++) {
637 | $thischar = strtolower(chr($key));
638 | $hotchar = strtolower($this->menuList[$n]['hot']);
639 |
640 | if ($thischar == $hotchar) {
641 | if ($this instanceof NcursesChecklist) { // checklists support
642 | $this->menuList[$n]['selected'] = !$this->menuList[$n]['selected'];
643 |
644 | return (null);
645 | } else {
646 | $this->menuCursor = $n;
647 |
648 | return ($this->menuList[$n]['value']);
649 | }
650 | }
651 | }
652 |
653 | return (null);
654 | }
655 |
656 | /**
657 | * @return array name/value of all defined input boxes
658 | */
659 | protected function returnInputboxVals()
660 | {
661 | $results = array();
662 |
663 | for ($n = 0; $n < $this->inputBoxTotal; $n++) {
664 | $name = $this->inputBoxList[$n]['name'];
665 | $value = implode('', $this->inputBoxList[$n]['val']); // merge value array to string
666 | $results[$name] = $value;
667 | }
668 |
669 | return ($results);
670 | }
671 |
672 | /**
673 | * Displays all defined button types
674 | * @param $win
675 | */
676 | protected function strokeAllButtons(&$win)
677 | {
678 | for ($i = 0; $i < $this->buttonTotal; $i++) {
679 | ncurses_mvwaddstr($win, $this->buttonList[$i]['y'], $this->buttonList[$i]['x'], "");
680 | $len = strlen($this->buttonList[$i]['name']);
681 |
682 | for ($n = 0; $n < $len; $n++) {
683 | $char = substr($this->buttonList[$i]['name'], $n, 1);
684 | $ord = ord($char);
685 | if ($char == $this->buttonList[$i]['hot']) { // highlight char that is the hotkey
686 | if (($this->focusCat() === 'B') && ($i == $this->focusSubindex())) {
687 | ncurses_wcolor_set($win, 6);
688 | } else {
689 | ncurses_wcolor_set($win, 7);
690 | }
691 | ncurses_wattron($win, NCURSES_A_BOLD);
692 | ncurses_waddch($win, $ord);
693 | ncurses_wattroff($win, NCURSES_A_BOLD);
694 | } else {
695 | if (($this->focusCat() === 'B') && ($i == $this->focusSubindex())) {
696 | ncurses_wcolor_set($win, 5);
697 | } else {
698 | ncurses_wcolor_set($win, 2);
699 | }
700 | ncurses_waddch($win, $ord);
701 | }
702 | }
703 | }
704 | }
705 |
706 | /**
707 | * Gets user input and acts based on button navigation style
708 | * @param $win
709 | * @return array|mixed|null|string
710 | */
711 | protected function getButtonInput(&$win)
712 | {
713 | $exit = null;
714 | $keyPressed = ncurses_getch();
715 | //print" {".$keyPressed."} ";
716 |
717 | switch ($keyPressed) {
718 | case NCURSES_KEY_RIGHT:
719 | case NCURSES_KEY_DOWN:
720 | case 9: // tab
721 | $this->focusCursor++;
722 | if ($this->focusCursor >= $this->focusTotal) {
723 | $this->focusCursor = 0;
724 | }
725 | break;
726 |
727 |
728 | case NCURSES_KEY_LEFT:
729 | case NCURSES_KEY_UP:
730 | case 353: // shift-tab
731 | $this->focusCursor--;
732 | if ($this->focusCursor < 0) {
733 | $this->focusCursor = $this->focusTotal - 1;
734 | }
735 | break;
736 |
737 | case 32: //space
738 | case 13: //enter
739 | // get current focus
740 | list($ftype, $fnum) = explode("-", $this->focusList[$this->focusCursor]);
741 | // send the button value we are focused on
742 | $exit = $this->buttonList[$fnum]['value'];
743 |
744 | if ($exit === '#FORM#') {// Support for inputbox
745 | $exit = $this->returnInputboxVals();
746 | }
747 |
748 | break;
749 |
750 | default:
751 | // check if any button hotkeys were pressed - return 'null' if no match
752 | $exit = $this->checkHotButtons($keyPressed);
753 | break;
754 | }
755 |
756 | return ($exit);
757 | }
758 |
759 | /**
760 | * Gets user input and acts based on textbox navigation style
761 | * @param $win
762 | * @return null
763 | */
764 | protected function getTextboxInput(&$win)
765 | {
766 | $exit = null;
767 | $char = null;
768 | $keyPressed = ncurses_getch();
769 | if ($keyPressed < 256) { // is this an ascii code/
770 | $char = chr($keyPressed);
771 | }
772 | //print" {".$keyPressed."} ";
773 |
774 | switch ($keyPressed) {
775 | case NCURSES_KEY_DOWN:
776 | case 9: // tab
777 | case 13: // enter
778 | $this->focusCursor++;
779 | if ($this->focusCursor >= $this->focusTotal) {
780 | $this->focusCursor = 0;
781 | }
782 | break;
783 |
784 |
785 | case NCURSES_KEY_UP:
786 | case 353: // shift-tab
787 | $this->focusCursor--;
788 | if ($this->focusCursor < 0) {
789 | $this->focusCursor = $this->focusTotal - 1;
790 | }
791 | break;
792 |
793 |
794 | case NCURSES_KEY_RIGHT:
795 | $ii = $this->focusSubindex(); // get selected inputbox
796 | $val_len = &$this->inputBoxList[$ii]['val_len'];
797 | $cursor = &$this->inputBoxList[$ii]['val_cursor'];
798 | if ($cursor < $val_len) {
799 | $cursor++;
800 | } else {
801 | $crap = ncurses_beep();
802 | }
803 | break;
804 |
805 |
806 | case NCURSES_KEY_LEFT:
807 | $ii = $this->focusSubindex(); // get selected inputbox
808 | $cursor = &$this->inputBoxList[$ii]['val_cursor'];
809 | if ($cursor > 0) {
810 | $cursor--;
811 | } else {
812 | $crap = ncurses_beep();
813 | }
814 | break;
815 |
816 |
817 | case 263: // backspace
818 | $ii = $this->focusSubindex(); // get selected inputbox
819 |
820 | $cursor = &$this->inputBoxList[$ii]['val_cursor'];
821 | $value = &$this->inputBoxList[$ii]['val'];
822 | $value_len = &$this->inputBoxList[$ii]['val_len'];
823 |
824 | if ($cursor > 0) {
825 | $sub1 = array_slice($value, 0, $cursor - 1);
826 | $sub2 = array_slice($value, $cursor);
827 | $value = array_merge($sub1, $sub2);
828 | $cursor--;
829 | $value_len = count($value);
830 | } else {
831 | $crap = ncurses_beep();
832 | }
833 |
834 |
835 | // Refresh current input box
836 | $this->drawInputBoxContents($ii);
837 | break;
838 |
839 | case 330: // del key
840 | $ii = $this->focusSubindex(); // get selected inputbox
841 |
842 | $cursor = &$this->inputBoxList[$ii]['val_cursor'];
843 | $value = &$this->inputBoxList[$ii]['val'];
844 | $value_len = &$this->inputBoxList[$ii]['val_len'];
845 |
846 | $sub1 = array_slice($value, 0, $cursor);
847 | $sub2 = array_slice($value, $cursor + 1);
848 | $value = array_merge($sub1, $sub2);
849 |
850 | $value_len = count($value);
851 |
852 | // Refresh current input box
853 | $this->drawInputBoxContents($ii);
854 | break;
855 |
856 | default:
857 | $ii = $this->focusSubindex(); // get selected inputbox
858 |
859 | $value = &$this->inputBoxList[$ii]['val'];
860 | $value_len = &$this->inputBoxList[$ii]['val_len'];
861 | $value_max = &$this->inputBoxList[$ii]['max_length'];
862 | $cursor = &$this->inputBoxList[$ii]['val_cursor'];
863 |
864 | if (($keyPressed >= 32) && ($keyPressed <= 126)) {
865 | if ($value_len < $value_max) {
866 | $sub1 = array_slice($value, 0, $cursor);
867 | $sub2 = array_slice($value, $cursor);
868 | $new = array($char);
869 | $value = array_merge($sub1, $new, $sub2);
870 |
871 | //$value[$cursor] = $char;
872 | $cursor++;
873 | $value_len++;
874 | } else {
875 | $crap = ncurses_beep();
876 | }
877 | }
878 |
879 | // Refresh current input box
880 | $this->drawInputBoxContents($ii);
881 | break;
882 | }
883 |
884 | return ($exit);
885 | }
886 |
887 | /**
888 | * Gets user input and acts based on Menu/Checklist navigation style
889 | * @param $win
890 | * @return array|bool|mixed|null
891 | */
892 | protected function getMenuInput(&$win)
893 | {
894 | $exit = null;
895 | $keyPressed = ncurses_getch();
896 | //print" {".$keyPressed."} ";
897 |
898 | switch ($keyPressed) {
899 | case NCURSES_KEY_DOWN:
900 | $this->menuCursor++;
901 | if ($this->menuCursor >= $this->menuTotal) {
902 | $this->menuCursor = 0;
903 | }
904 | break;
905 |
906 | case NCURSES_KEY_UP:
907 | $this->menuCursor--;
908 | if ($this->menuCursor < 0) {
909 | $this->menuCursor = $this->menuTotal - 1;
910 | }
911 | break;
912 |
913 | case NCURSES_KEY_RIGHT:
914 | case 9: // tab
915 | $this->focusCursor++;
916 | if ($this->focusCursor >= $this->focusTotal) {
917 | $this->focusCursor = 0;
918 | }
919 | break;
920 |
921 | case NCURSES_KEY_LEFT :
922 | case 353: // shift-tab
923 | $this->focusCursor--;
924 | if ($this->focusCursor < 0) {
925 | $this->focusCursor = $this->focusTotal - 1;
926 | }
927 | break;
928 |
929 | case 32: // space
930 | if ($this instanceof NcursesChecklist) {
931 | // toggle item selection
932 | $this->menuList[$this->menuCursor]['selected'] = !$this->menuList[$this->menuCursor]['selected'];
933 | }
934 | break;
935 |
936 | case 13: //enter
937 | $ii = $this->focusSubindex(); // get selected inputbox
938 | if ($this instanceof NcursesChecklist) {
939 | if ($this->buttonList[$ii]['value'] === true) {
940 | return $this->getAllCheckboxVals();
941 | } else {
942 | return $this->buttonList[$ii]['value'];
943 | }
944 | }
945 |
946 | if ($this instanceof NcursesMenu) {
947 | if ($this->buttonList[$ii]['value'] === true) {
948 | return $this->menuList[$this->menuCursor]['value'];
949 | } else {
950 | return $this->buttonList[$ii]['value'];
951 | }
952 | }
953 |
954 | return $this->buttonList[$ii]['value'];
955 |
956 | default:
957 | // check if any button hotkeys were pressed - return 'null' if no match
958 | $hot = $this->checkHotButtons($keyPressed); // try trap for hot buttons 1st.
959 |
960 | if ($hot === true) { // was hot button pressed?
961 | if ($this instanceof NcursesChecklist) { // checklist support -- (optional)
962 | $exit = $this->getAllCheckboxVals();
963 | } else { // menu selection
964 | // return the menu value we are focused on
965 | $exit = $this->menuList[$this->menuCursor]['value'];
966 | }
967 | } elseif ($hot === false) {
968 | $exit = false;
969 | } else { // $hot == null , so let see if there is a hot-checkbox match
970 | $exit = $this->checkHotMenuItems($keyPressed);
971 | }
972 |
973 | break;
974 | }
975 |
976 | return ($exit);
977 | }
978 |
979 | /**
980 | * Returns array name/value of selected check boxes
981 | * @return array|bool|null
982 | */
983 | protected function getAllCheckboxVals()
984 | {
985 | $exit = null;
986 | for ($n = 0; $n < $this->menuTotal; $n++) {
987 | // return all items selected
988 | if ($this->menuList[$n]['selected']) {
989 | $name = &$this->menuList[$n]['name'];
990 | $value = &$this->menuList[$n]['value'];
991 | $exit[$name] = $value;
992 | }
993 | }
994 | if (!is_array($exit)) { // if nothing was selected we still need to return something
995 | $exit = true;
996 | }
997 |
998 | return ($exit);
999 | }
1000 |
1001 | /**
1002 | * Initializes Menu Items (or Checklist) types
1003 | * @param $type
1004 | * @param $name
1005 | * @param $label
1006 | * @param $hotkey
1007 | * @param $desc
1008 | * @param null $value
1009 | * @param bool $selected
1010 | */
1011 | protected function addMenuItem($type, $name, $label, $hotkey, $desc, $value = null, $selected = false)
1012 | {
1013 | $this->menuList[$this->menuTotal]['name'] = $name;
1014 | $this->menuList[$this->menuTotal]['type'] = $type;
1015 | $this->menuList[$this->menuTotal]['selected'] = $selected;
1016 | $this->menuList[$this->menuTotal]['label'] = $label;
1017 | $this->menuList[$this->menuTotal]['desc'] = $desc;
1018 | $this->menuList[$this->menuTotal]['hot'] = $hotkey;
1019 | //default value if non given
1020 | $this->menuList[$this->menuTotal]['value'] = ($value === null ? $this->menuTotal : $value);
1021 | $this->menuList[$this->menuTotal]['y'] = $this->menuTotal;
1022 | $this->menuList[$this->menuTotal]['x'] = 0;
1023 | $this->menuTotal++;
1024 |
1025 | $len = strlen($label);
1026 | if ($len > $this->menuLabelWidth) {
1027 | $this->menuLabelWidth = $len;
1028 | } // track largest label width
1029 |
1030 | $len = strlen($desc);
1031 | if ($len > $this->menuDescWidth) {
1032 | $this->menuDescWidth = $len;
1033 | } // track largest description width
1034 | }
1035 |
1036 | /**
1037 | * Displays all Menu Items (or Checklist) to screen
1038 | * @param $win
1039 | */
1040 | protected function strokeAllMenuItems(&$win)
1041 | {
1042 | for ($i = 0; $i < $this->menuTotal; $i++) {
1043 | if ($this->menuCursor == $i) {
1044 | ncurses_wcolor_set($win, 5);
1045 | } else {
1046 | ncurses_wcolor_set($win, 2);
1047 | }
1048 |
1049 | // output Checkbox -- (optional)
1050 | if ($this instanceof NcursesChecklist) { // for checklist type menus
1051 | $sel = ($this->menuList[$i]['selected'] == true ? 'X' : ' ');
1052 | ncurses_mvwaddstr($win, $this->menuList[$i]['y'], $this->menuList[$i]['x'], '[' . $sel . ']');
1053 | ncurses_mvwaddstr($win, $this->menuList[$i]['y'], $this->menuList[$i]['x'] + 4, '');
1054 | $desc_offset = 5;
1055 | } else {
1056 | ncurses_mvwaddstr($win, $this->menuList[$i]['y'], $this->menuList[$i]['x'], '');
1057 | $desc_offset = 2;
1058 | }
1059 |
1060 | // output menu item label
1061 | $len = strlen($this->menuList[$i]['label']);
1062 | for ($n = 0; $n < $len; $n++) {
1063 | $char = substr($this->menuList[$i]['label'], $n, 1);
1064 | $ord = ord($char);
1065 | if ($char == $this->menuList[$i]['hot']) { // highlight char that is the hotkey
1066 | //SET HOTKEY COLOR ON SELECTED ITEM
1067 | if ($this->menuCursor == $i) {
1068 | ncurses_wcolor_set($win, 5);
1069 | } //SET HOTKEY COLOR ON UNSELECTED ITEM
1070 | else {
1071 | ncurses_wcolor_set($win, 7);
1072 | }
1073 |
1074 | ncurses_wattron($win, NCURSES_A_BOLD);
1075 | ncurses_waddch($win, $ord);
1076 | ncurses_wattroff($win, NCURSES_A_BOLD);
1077 | } else {
1078 | if ($this->menuCursor == $i) {
1079 | ncurses_wcolor_set($win, 5);
1080 | } else {
1081 | ncurses_wcolor_set($win, 2);
1082 | }
1083 | ncurses_waddch($win, $ord);
1084 | }
1085 | }
1086 | // output menu item description
1087 | if ($this->menuCursor == $i) {
1088 | ncurses_wcolor_set($win, 5);
1089 | } else {
1090 | ncurses_wcolor_set($win, 2);
1091 | }
1092 | ncurses_mvwaddstr($win, $this->menuList[$i]['y'],
1093 | $this->menuList[$i]['x'] + $this->menuLabelWidth + $desc_offset, $this->menuList[$i]['desc']);
1094 | }
1095 | }
1096 |
1097 | /**
1098 | * Displays and creates a sub-window to contain the Menu Items
1099 | * @param $win
1100 | * @param $parentHeight
1101 | * @param $parentWidth
1102 | * @param $paraOffsetY
1103 | * @param int $border
1104 | * @return resource - ID of the sub-window
1105 | */
1106 | protected function createMenuSubWindow(&$win, $parentHeight, $parentWidth, $paraOffsetY, $border = 0)
1107 | {
1108 | // auto-detect window width based on menu contents
1109 | if ($this instanceof NcursesChecklist) {
1110 | $menuWidth = 1 + 4 + $this->menuLabelWidth + 2 + $this->menuDescWidth + 1;
1111 | } else {
1112 | $menuWidth = 1 + $this->menuLabelWidth + 2 + $this->menuDescWidth + 1;
1113 | }
1114 |
1115 | // Draw borders
1116 | $cord['y'] = 1 + $paraOffsetY;
1117 | $cord['x'] = round(($parentWidth - $menuWidth) / 2);
1118 | //$cord = $this->getCoordinates($parent_height,$menu_width,"center","middle");
1119 | $y = $this->menuTotal + 2;
1120 | $x = $menuWidth;
1121 |
1122 | if ($border != 0) {
1123 | $this->drawThinBorders($win, $cord['y'], $cord['x'], $y, $x);
1124 | }
1125 |
1126 | // draw window inside borders
1127 | $cord = $this->getCoordinates($parentHeight, $menuWidth, self::COORD_X_CENTER, self::COORD_Y_MIDDLE);
1128 | $swin = ncurses_newwin($y - 2, $x - 2, $cord['y'] + $paraOffsetY + 2, $cord['x'] + 1);
1129 |
1130 | // fill window
1131 | ncurses_wcolor_set($swin, 2);
1132 | for ($row = 0; $row < $y - 2; $row++) {
1133 | ncurses_wmove($swin, $row, 0);
1134 | ncurses_whline($swin, 32, $x - 2);
1135 | }
1136 |
1137 | return $swin;
1138 | }
1139 |
1140 | /**
1141 | * @return string
1142 | */
1143 | public function getTitlePageHeader()
1144 | {
1145 | return $this->titlePageHeader;
1146 | }
1147 |
1148 | /**
1149 | * @param string $titlePageHeader
1150 | * @return $this
1151 | */
1152 | public function setTitlePageHeader($titlePageHeader)
1153 | {
1154 | $this->titlePageHeader = $titlePageHeader;
1155 |
1156 | return $this;
1157 | }
1158 |
1159 | /**
1160 | * @return mixed
1161 | */
1162 | public function getTitleDialogHeader()
1163 | {
1164 | return $this->titleDialogHeader;
1165 | }
1166 |
1167 | /**
1168 | * @param mixed $titleDialogHeader
1169 | * @return $this
1170 | */
1171 | public function setTitleDialogHeader($titleDialogHeader)
1172 | {
1173 | $this->titleDialogHeader = $titleDialogHeader;
1174 |
1175 | return $this;
1176 | }
1177 |
1178 | /**
1179 | * @return mixed
1180 | */
1181 | public function getText()
1182 | {
1183 | return $this->text;
1184 | }
1185 |
1186 | /**
1187 | * @param mixed $text
1188 | * @return $this
1189 | */
1190 | public function setText($text)
1191 | {
1192 | $this->text = $text;
1193 |
1194 | return $this;
1195 | }
1196 |
1197 | /**
1198 | * @return mixed
1199 | */
1200 | public function getHeight()
1201 | {
1202 | return $this->height;
1203 | }
1204 |
1205 | /**
1206 | * @param mixed $height
1207 | * @return $this
1208 | */
1209 | public function setHeight($height)
1210 | {
1211 | $this->height = $height;
1212 |
1213 | return $this;
1214 | }
1215 |
1216 | /**
1217 | * @return mixed
1218 | */
1219 | public function getWidth()
1220 | {
1221 | return $this->width;
1222 | }
1223 |
1224 | /**
1225 | * @param mixed $width
1226 | * @return $this
1227 | */
1228 | public function setWidth($width)
1229 | {
1230 | $this->width = $width;
1231 |
1232 | return $this;
1233 | }
1234 |
1235 | /**
1236 | * @return mixed
1237 | */
1238 | public function getLength()
1239 | {
1240 | return $this->length;
1241 | }
1242 |
1243 | /**
1244 | * @param mixed $length
1245 | * @return $this
1246 | */
1247 | public function setLength($length)
1248 | {
1249 | $this->length = $length;
1250 |
1251 | return $this;
1252 | }
1253 |
1254 | /**
1255 | * @return mixed
1256 | */
1257 | public function getDefaultVal()
1258 | {
1259 | return $this->defaultVal;
1260 | }
1261 |
1262 | /**
1263 | * @param mixed $defaultVal
1264 | * @return $this
1265 | */
1266 | public function setDefaultVal($defaultVal)
1267 | {
1268 | $this->defaultVal = $defaultVal;
1269 |
1270 | return $this;
1271 | }
1272 |
1273 | /**
1274 | * @return mixed
1275 | */
1276 | public function getScreenMaxWidth()
1277 | {
1278 | return $this->screenMaxWidth;
1279 | }
1280 |
1281 | /**
1282 | * @param mixed $screenMaxWidth
1283 | * @return $this
1284 | */
1285 | public function setScreenMaxWidth($screenMaxWidth)
1286 | {
1287 | $this->screenMaxWidth = $screenMaxWidth;
1288 |
1289 | return $this;
1290 | }
1291 |
1292 | /**
1293 | * @return mixed
1294 | */
1295 | public function getScreenMaxHeight()
1296 | {
1297 | return $this->screenMaxHeight;
1298 | }
1299 |
1300 | /**
1301 | * @param mixed $screenMaxHeight
1302 | * @return $this
1303 | */
1304 | public function setScreenMaxHeight($screenMaxHeight)
1305 | {
1306 | $this->screenMaxHeight = $screenMaxHeight;
1307 |
1308 | return $this;
1309 | }
1310 |
1311 | /**
1312 | * @return mixed
1313 | */
1314 | public function getButtonList()
1315 | {
1316 | return $this->buttonList;
1317 | }
1318 |
1319 | /**
1320 | * @param mixed $buttonList
1321 | * @return $this
1322 | */
1323 | public function setButtonList($buttonList)
1324 | {
1325 | $this->buttonList = $buttonList;
1326 |
1327 | return $this;
1328 | }
1329 |
1330 | /**
1331 | * @return mixed
1332 | */
1333 | public function getButtonTotal()
1334 | {
1335 | return $this->buttonTotal;
1336 | }
1337 |
1338 | /**
1339 | * @param mixed $buttonTotal
1340 | * @return $this
1341 | */
1342 | public function setButtonTotal($buttonTotal)
1343 | {
1344 | $this->buttonTotal = $buttonTotal;
1345 |
1346 | return $this;
1347 | }
1348 |
1349 | /**
1350 | * @return mixed
1351 | */
1352 | public function getButtonCursor()
1353 | {
1354 | return $this->buttonCursor;
1355 | }
1356 |
1357 | /**
1358 | * @param mixed $buttonCursor
1359 | * @return $this
1360 | */
1361 | public function setButtonCursor($buttonCursor)
1362 | {
1363 | $this->buttonCursor = $buttonCursor;
1364 |
1365 | return $this;
1366 | }
1367 |
1368 | /**
1369 | * @return mixed
1370 | */
1371 | public function getInputBoxList()
1372 | {
1373 | return $this->inputBoxList;
1374 | }
1375 |
1376 | /**
1377 | * @param mixed $inputBoxList
1378 | * @return $this
1379 | */
1380 | public function setInputBoxList($inputBoxList)
1381 | {
1382 | $this->inputBoxList = $inputBoxList;
1383 |
1384 | return $this;
1385 | }
1386 |
1387 | /**
1388 | * @return mixed
1389 | */
1390 | public function getInputBoxTotal()
1391 | {
1392 | return $this->inputBoxTotal;
1393 | }
1394 |
1395 | /**
1396 | * @param mixed $inputBoxTotal
1397 | * @return $this
1398 | */
1399 | public function setInputBoxTotal($inputBoxTotal)
1400 | {
1401 | $this->inputBoxTotal = $inputBoxTotal;
1402 |
1403 | return $this;
1404 | }
1405 |
1406 | /**
1407 | * @return mixed
1408 | */
1409 | public function getMenuList()
1410 | {
1411 | return $this->menuList;
1412 | }
1413 |
1414 | /**
1415 | * @param mixed $menuList
1416 | * @return $this
1417 | */
1418 | public function setMenuList($menuList)
1419 | {
1420 | $this->menuList = $menuList;
1421 |
1422 | return $this;
1423 | }
1424 |
1425 | /**
1426 | * @return mixed
1427 | */
1428 | public function getMenuTotal()
1429 | {
1430 | return $this->menuTotal;
1431 | }
1432 |
1433 | /**
1434 | * @param mixed $menuTotal
1435 | * @return $this
1436 | */
1437 | public function setMenuTotal($menuTotal)
1438 | {
1439 | $this->menuTotal = $menuTotal;
1440 |
1441 | return $this;
1442 | }
1443 |
1444 | /**
1445 | * @return mixed
1446 | */
1447 | public function getMenuCursor()
1448 | {
1449 | return $this->menuCursor;
1450 | }
1451 |
1452 | /**
1453 | * @param mixed $menuCursor
1454 | * @return $this
1455 | */
1456 | public function setMenuCursor($menuCursor)
1457 | {
1458 | $this->menuCursor = $menuCursor;
1459 |
1460 | return $this;
1461 | }
1462 |
1463 | /**
1464 | * @return mixed
1465 | */
1466 | public function getMenuLabelWidth()
1467 | {
1468 | return $this->menuLabelWidth;
1469 | }
1470 |
1471 | /**
1472 | * @param mixed $menuLabelWidth
1473 | * @return $this
1474 | */
1475 | public function setMenuLabelWidth($menuLabelWidth)
1476 | {
1477 | $this->menuLabelWidth = $menuLabelWidth;
1478 |
1479 | return $this;
1480 | }
1481 |
1482 | /**
1483 | * @return mixed
1484 | */
1485 | public function getMenuDescWidth()
1486 | {
1487 | return $this->menuDescWidth;
1488 | }
1489 |
1490 | /**
1491 | * @param mixed $menuDescWidth
1492 | * @return $this
1493 | */
1494 | public function setMenuDescWidth($menuDescWidth)
1495 | {
1496 | $this->menuDescWidth = $menuDescWidth;
1497 |
1498 | return $this;
1499 | }
1500 |
1501 | /**
1502 | * @return mixed
1503 | */
1504 | public function getNwin()
1505 | {
1506 | return $this->nwin;
1507 | }
1508 |
1509 | /**
1510 | * @param mixed $nwin
1511 | * @return $this
1512 | */
1513 | public function setNwin($nwin)
1514 | {
1515 | $this->nwin = $nwin;
1516 |
1517 | return $this;
1518 | }
1519 |
1520 | /**
1521 | * @return mixed
1522 | */
1523 | public function getSwin()
1524 | {
1525 | return $this->swin;
1526 | }
1527 |
1528 | /**
1529 | * @param mixed $swin
1530 | * @return $this
1531 | */
1532 | public function setSwin($swin)
1533 | {
1534 | $this->swin = $swin;
1535 |
1536 | return $this;
1537 | }
1538 |
1539 | /**
1540 | * @return mixed
1541 | */
1542 | public function getTextBoxChar()
1543 | {
1544 | return $this->textBoxChar;
1545 | }
1546 |
1547 | /**
1548 | * @param mixed $textBoxChar
1549 | * @return $this
1550 | */
1551 | public function setTextBoxChar($textBoxChar)
1552 | {
1553 | $this->textBoxChar = $textBoxChar;
1554 |
1555 | return $this;
1556 | }
1557 |
1558 | /**
1559 | * @return mixed
1560 | */
1561 | public function getTextBoxLen()
1562 | {
1563 | return $this->textBoxLen;
1564 | }
1565 |
1566 | /**
1567 | * @param mixed $textBoxLen
1568 | * @return $this
1569 | */
1570 | public function setTextBoxLen($textBoxLen)
1571 | {
1572 | $this->textBoxLen = $textBoxLen;
1573 |
1574 | return $this;
1575 | }
1576 |
1577 | /**
1578 | * @return mixed
1579 | */
1580 | public function getTextBoxMax()
1581 | {
1582 | return $this->textBoxMax;
1583 | }
1584 |
1585 | /**
1586 | * @param mixed $textBoxMax
1587 | * @return $this
1588 | */
1589 | public function setTextBoxMax($textBoxMax)
1590 | {
1591 | $this->textBoxMax = $textBoxMax;
1592 |
1593 | return $this;
1594 | }
1595 |
1596 | /**
1597 | * @return mixed
1598 | */
1599 | public function getFocusList()
1600 | {
1601 | return $this->focusList;
1602 | }
1603 |
1604 | /**
1605 | * @param mixed $focusList
1606 | * @return $this
1607 | */
1608 | public function setFocusList($focusList)
1609 | {
1610 | $this->focusList = $focusList;
1611 |
1612 | return $this;
1613 | }
1614 |
1615 | /**
1616 | * @return mixed
1617 | */
1618 | public function getFocusTotal()
1619 | {
1620 | return $this->focusTotal;
1621 | }
1622 |
1623 | /**
1624 | * @param mixed $focusTotal
1625 | * @return $this
1626 | */
1627 | public function setFocusTotal($focusTotal)
1628 | {
1629 | $this->focusTotal = $focusTotal;
1630 |
1631 | return $this;
1632 | }
1633 |
1634 | /**
1635 | * @return mixed
1636 | */
1637 | public function getFocusCursor()
1638 | {
1639 | return $this->focusCursor;
1640 | }
1641 |
1642 | /**
1643 | * @param mixed $focusCursor
1644 | * @return $this
1645 | */
1646 | public function setFocusCursor($focusCursor)
1647 | {
1648 | $this->focusCursor = $focusCursor;
1649 |
1650 | return $this;
1651 | }
1652 | }
1653 |
--------------------------------------------------------------------------------
/src/NcursesWidget/NcursesChecklist.php:
--------------------------------------------------------------------------------
1 | 'OK',
17 | 'hotkey' => 'O',
18 | 'return' => true
19 | ],
20 | [
21 | 'text' => 'Cancel',
22 | 'hotkey' => 'C',
23 | 'return' => false
24 | ]
25 | ];
26 |
27 |
28 | /**
29 | * Wrapper method to initialize Checkbox items
30 | * @param $name
31 | * @param $label
32 | * @param $hotkey
33 | * @param $desc
34 | * @param null $value
35 | * @param bool $selected
36 | */
37 | public function addChecklist($name, $label, $hotkey, $desc, $value = null, $selected = false)
38 | {
39 | $this->addMenuItem('check', $name, $label, $hotkey, $desc, $value, $selected);
40 | }
41 |
42 | /**
43 | * @return array
44 | */
45 | public function getButtons()
46 | {
47 | return $this->buttons;
48 | }
49 |
50 | /**
51 | * @param array $buttons
52 | * @return $this
53 | */
54 | public function setButtons($buttons)
55 | {
56 | $this->buttons = $buttons;
57 |
58 | return $this;
59 | }
60 |
61 | /**
62 | * @return mixed
63 | */
64 | public function display()
65 | {
66 | ncurses_init();
67 | $this->initScreen();
68 |
69 | // open a dialog box window
70 | $cord = $this->getCoordinates(
71 | $this->getHeight(),
72 | $this->getWidth(),
73 | self::COORD_X_CENTER,
74 | self::COORD_Y_MIDDLE
75 | );
76 |
77 | $mainWindow = $this->createDialogWindow($cord['y'], $cord['x'], $this->getHeight(), $this->getWidth(), true);
78 |
79 | // output dialog text
80 | $paraOffsetY = $this->strokePara(
81 | $mainWindow,
82 | $this->getText(),
83 | $this->getHeight(),
84 | $this->getWidth(),
85 | 'center',
86 | true
87 | );
88 |
89 | // Create menu sub-window
90 | $menuSubWindow = $this->createMenuSubWindow($mainWindow, $this->getHeight(), $this->getWidth(), $paraOffsetY);
91 |
92 | $this->configureButtons();
93 |
94 | // wait for input
95 | do {
96 | $this->strokeAllButtons($mainWindow);
97 | $this->strokeAllMenuItems($menuSubWindow);
98 | ncurses_wrefresh($mainWindow);
99 | ncurses_wrefresh($menuSubWindow);
100 | //get keyboard input
101 | $status = $this->getMenuInput($mainWindow);
102 | } while ($status === null);
103 |
104 | return $status;
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/src/NcursesWidget/NcursesConfirm.php:
--------------------------------------------------------------------------------
1 | 'Yes',
17 | 'hotkey' => 'Y',
18 | 'return' => true
19 | ],
20 | [
21 | 'text' => 'No',
22 | 'hotkey' => 'N',
23 | 'return' => false
24 | ]
25 | ];
26 |
27 | /**
28 | * @return mixed
29 | */
30 | public function display()
31 | {
32 | ncurses_init();
33 | $this->initScreen();
34 |
35 | // open a dialog box window
36 | $cord = $this->getCoordinates($this->height, $this->width, self::COORD_X_CENTER, self::COORD_Y_MIDDLE);
37 | $win = $this->createDialogWindow($cord['y'], $cord['x'], $this->height, $this->width, true);
38 |
39 | // output dialog text
40 | $this->strokePara($win, $this->text, $this->height, $this->width, 'center', true);
41 |
42 | // configure buttons
43 | $this->configureButtons();
44 |
45 | // wait for input
46 | do {
47 | $this->strokeAllButtons($win);
48 | ncurses_wrefresh($win);
49 | //get keyboard input
50 | $status = $this->getButtonInput($win);
51 | } while ($status === null);
52 |
53 | return ($status);
54 | }
55 |
56 | /**
57 | * @return array
58 | */
59 | public function getButtons()
60 | {
61 | return $this->buttons;
62 | }
63 |
64 | /**
65 | * @param array $buttons
66 | * @return $this
67 | */
68 | public function setButtons($buttons)
69 | {
70 | $this->buttons = $buttons;
71 |
72 | return $this;
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/NcursesWidget/NcursesInputBox.php:
--------------------------------------------------------------------------------
1 | 'Accept',
16 | 'hotkey' => 'A',
17 | 'return' => '#FORM#'
18 | ],
19 | [
20 | 'text' => 'Cancel',
21 | 'hotkey' => 'C',
22 | 'return' => false
23 | ]
24 | ];
25 |
26 | /**
27 | * indentation of text fields from left of box
28 | * @var int
29 | */
30 | protected $inputIndentation = 0;
31 |
32 | /**
33 | * @var array
34 | */
35 | protected $fields = [];
36 |
37 | /**
38 | * @return array
39 | */
40 | public function getButtons()
41 | {
42 | return $this->buttons;
43 | }
44 |
45 | /**
46 | * @param array $buttons
47 | * @return $this
48 | */
49 | public function setButtons($buttons)
50 | {
51 | $this->buttons = $buttons;
52 |
53 | return $this;
54 | }
55 |
56 | /**
57 | * @return int
58 | */
59 | public function getInputIndentation()
60 | {
61 | return $this->inputIndentation;
62 | }
63 |
64 | /**
65 | * @param int $inputIndentation
66 | * @return $this
67 | */
68 | public function setInputIndentation($inputIndentation)
69 | {
70 | $this->inputIndentation = $inputIndentation;
71 |
72 | return $this;
73 | }
74 |
75 | /**
76 | * @return array
77 | */
78 | public function getFields()
79 | {
80 | return $this->fields;
81 | }
82 |
83 | /**
84 | * @param array $fields
85 | * @return $this
86 | */
87 | public function setFields($fields)
88 | {
89 | $this->fields = $fields;
90 |
91 | return $this;
92 | }
93 |
94 | /**
95 | * @return mixed
96 | */
97 | public function display()
98 | {
99 | ncurses_init();
100 | $this->initScreen();
101 |
102 | // open a dialog box window
103 | $cord = $this->getCoordinates($this->height, $this->width, self::COORD_X_CENTER, self::COORD_Y_MIDDLE);
104 | $win = $this->createDialogWindow($cord['y'], $cord['x'], $this->height, $this->width, true);
105 |
106 | // Create menu sub-window
107 | // Controls alignment of menu title
108 | $para_offset_y = $this->strokePara($win, $this->text, $this->height, $this->width, 'center', true);
109 | $cord_x = $this->inputIndentation;
110 |
111 | //ORIGINAL CODE CENTERED INPUT FIELDS.
112 | //$para_offset_y = $this->_stroke_para($win,$this->text,$this->height,$this->width,"center",true);
113 | //$cord_x = round(($this->width/2) - ($this->length/2) );
114 |
115 | foreach ($this->fields as $key => $val) {
116 | $cord_y = $para_offset_y + ($key * 2);
117 | // output dialog text
118 | $this->addInputBox(
119 | $win,
120 | $this->fields[$key]['name'],
121 | $this->fields[$key]['label'],
122 | $cord_y,
123 | $cord_x,
124 | $this->fields[$key]['length'],
125 | $this->fields[$key]['value']
126 | );
127 | }
128 |
129 | // configure buttons
130 | $this->configureButtons();
131 |
132 | // wait for input
133 | do {
134 | $this->strokeAllButtons($win);
135 |
136 | //THIS IS WHERE THE INPUT BOXES ARE POSITIONED
137 | $this->strokeInputBoxes($win);
138 | ncurses_wrefresh($win);
139 |
140 | // get keyboard input
141 | if ($this->focusCat() === 'B') {
142 | $status = $this->getButtonInput($win);
143 | } else {
144 | $status = $this->getTextboxInput($win);
145 | }
146 | } while ($status === null);
147 |
148 | if (isset($status['val'])) {
149 | $status = $status['val'];
150 | }
151 |
152 | return $status;
153 | }
154 |
155 | /**
156 | * Defines an Input text box input type.
157 | * @param $win
158 | * @param $name
159 | * @param $label
160 | * @param $cord_y
161 | * @param $cord_x
162 | * @param $max_length
163 | * @param $init_val
164 | */
165 | protected function addInputBox($win, $name, $label, $cord_y, $cord_x, $max_length, $init_val)
166 | {
167 | $this->inputBoxList[$this->inputBoxTotal]['win'] = $win; // resource window
168 | $this->inputBoxList[$this->inputBoxTotal]['name'] = $name;
169 | $this->inputBoxList[$this->inputBoxTotal]['label'] = $label;
170 |
171 | //DROP INPUT BOX TO ONE LINE BELOW LABEL
172 | $this->inputBoxList[$this->inputBoxTotal]['y'] = $cord_y + 1;
173 | $this->inputBoxList[$this->inputBoxTotal]['x'] = $cord_x;
174 | $this->inputBoxList[$this->inputBoxTotal]['max_length'] = $max_length; // max allowed input size
175 |
176 | // set a default value - if given.
177 | if ($init_val != "") {
178 | $len = strlen($init_val);
179 | for ($c = 0; $c < $len; $c++) {
180 | $char = substr($init_val, $c, 1);
181 | $this->inputBoxList[$this->inputBoxTotal]['val'][$c] = $char;
182 | }
183 | $this->inputBoxList[$this->inputBoxTotal]['val_cursor'] = $c;
184 | $this->inputBoxList[$this->inputBoxTotal]['val_len'] = $c;
185 | } else {
186 | $this->inputBoxList[$this->inputBoxTotal]['val'] = array();
187 | $this->inputBoxList[$this->inputBoxTotal]['val_cursor'] = 0;
188 | $this->inputBoxList[$this->inputBoxTotal]['val_len'] = 0;
189 | }
190 |
191 | // add to master focus list
192 | $this->focusList[$this->focusTotal] = 'I-' . $this->inputBoxTotal;
193 |
194 | $this->inputBoxTotal++;
195 | $this->focusTotal++;
196 | }
197 |
198 | /**
199 | * Displays all input text boxes defined
200 | */
201 | protected function strokeInputBoxes()
202 | {
203 | for ($i = 0; $i < $this->inputBoxTotal; $i++) {
204 | $this->drawInputBox($i);
205 | }
206 | }
207 |
208 | /**
209 | * Displays specified input text box
210 | * @param $index
211 | */
212 | protected function drawInputBox($index)
213 | {
214 | $label_offset = 0;
215 |
216 | $win = &$this->inputBoxList[$index]['win'];
217 | $label = &$this->inputBoxList[$index]['label'];
218 | $hotkey = &$this->inputBoxList[$index]['hot'];
219 | $cord_y = &$this->inputBoxList[$index]['y'];
220 | $cord_x = &$this->inputBoxList[$index]['x'];
221 | $max_length = &$this->inputBoxList[$index]['max_length'];
222 |
223 | ncurses_wcolor_set($win, 2);
224 |
225 | // draws the label
226 | if ($label != "") {
227 | ncurses_mvwaddstr($win, $cord_y, $cord_x, $label);
228 | $label_offset = strlen($label); // overide offset due to label length
229 | }
230 |
231 | // draws border for input field
232 | //$this->_drawThinBorders($win,$cord_y-1,($cord_x+$label_offset),3,$max_length+2,"out");
233 | //ncurses_wmove ( $win, $y+$height-1, $x+1 );
234 |
235 | // draws input box contents
236 | $this->drawInputBoxContents($index);
237 |
238 | // draws bottom border
239 | ncurses_wcolor_set($win, 2);
240 | ncurses_wmove($win, $cord_y + 1, $cord_x + $label_offset + 1);
241 | ncurses_whline($win, 175, 20); // bottom line
242 | }
243 |
244 | /**
245 | * Displays specified input text box value contents
246 | * @param $index
247 | */
248 | protected function drawInputBoxContents($index)
249 | {
250 | $win = &$this->inputBoxList[$index]['win'];
251 | $val = &$this->inputBoxList[$index]['val'];
252 | $cord_y = &$this->inputBoxList[$index]['y'];
253 | $cord_x = &$this->inputBoxList[$index]['x'];
254 | $label = &$this->inputBoxList[$index]['label'];
255 |
256 | // label offset
257 | $label_offset = 0;
258 | if ($label !== '') {
259 | $label_offset = strlen($label); // overide offset due to label length
260 | }
261 |
262 | // output the value
263 | for ($n = 0; $n < $this->inputBoxList[$index]['max_length']; $n++) {
264 | // Set content color based on has focus or not.
265 | if (($this->focusCat() === 'I') && ($this->focusSubindex() == $index)) {
266 | if ($n == $this->inputBoxList[$index]['val_cursor']) {
267 | //CURSOR COLOR - RED
268 | ncurses_wcolor_set($win, 1);
269 | } else {
270 | ncurses_wcolor_set($win, 5);
271 | }
272 | } else {
273 | ncurses_wcolor_set($win, 2);
274 | }
275 |
276 | // print chars that exist
277 | if (isset($val[$n])) {
278 | $char = $val[$n];
279 | } else {
280 | $char = ' ';
281 | }
282 | ncurses_mvwaddstr($win, $cord_y, ($cord_x + $label_offset + 1 + $n), $char);
283 | }
284 | }
285 | }
286 |
--------------------------------------------------------------------------------
/src/NcursesWidget/NcursesMenu.php:
--------------------------------------------------------------------------------
1 | 'Select',
17 | 'hotkey' => 'S',
18 | 'return' => true
19 | ],
20 | [
21 | 'text' => 'Cancel',
22 | 'hotkey' => 'C',
23 | 'return' => false
24 | ]
25 | ];
26 |
27 | /**
28 | * @var int 1 to show border
29 | */
30 | protected $border = 0;
31 |
32 | /**
33 | * Wrapper method to initialize Menu items
34 | * @param $label
35 | * @param $hotkey
36 | * @param $desc
37 | * @param null $value
38 | */
39 | public function addMenu($label, $hotkey, $desc, $value = null)
40 | {
41 | $name = '';
42 | $this->addMenuItem('menu', $name, $label, $hotkey, $desc, $value, false);
43 | }
44 |
45 | /**
46 | * @return array
47 | */
48 | public function getButtons()
49 | {
50 | return $this->buttons;
51 | }
52 |
53 | /**
54 | * @param array $buttons
55 | * @return $this
56 | */
57 | public function setButtons($buttons)
58 | {
59 | $this->buttons = $buttons;
60 |
61 | return $this;
62 | }
63 |
64 | /**
65 | * @return int
66 | */
67 | public function getBorder()
68 | {
69 | return $this->border;
70 | }
71 |
72 | /**
73 | * @param int $border
74 | * @return $this
75 | */
76 | public function setBorder($border)
77 | {
78 | $this->border = $border;
79 |
80 | return $this;
81 | }
82 |
83 | /**
84 | * @return mixed
85 | */
86 | public function display()
87 | {
88 | ncurses_init();
89 | $this->initScreen();
90 |
91 | // open a dialog box window
92 | $cord = $this->getCoordinates($this->height, $this->width, self::COORD_X_CENTER, self::COORD_Y_MIDDLE);
93 | $win = $this->createDialogWindow($cord['y'], $cord['x'], $this->height, $this->width, true);
94 |
95 | // output dialog text
96 | $para_offset_y = $this->strokePara($win, $this->text, $this->height, $this->width, 'center', true);
97 |
98 | // Create menu sub-window
99 | $mwin = $this->createMenuSubWindow($win, $this->height, $this->width, $para_offset_y, $this->border);
100 |
101 | // configure buttons
102 | $this->configureButtons();
103 |
104 | // wait for input
105 | do {
106 | $this->strokeAllButtons($win);
107 | $this->strokeAllMenuItems($mwin);
108 | ncurses_wrefresh($win);
109 | ncurses_wrefresh($mwin);
110 | //get keyboard input
111 | $status = $this->getMenuInput($win);
112 | } while ($status === null);
113 |
114 | return ($status);
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/src/NcursesWidget/NcursesMsgbox.php:
--------------------------------------------------------------------------------
1 | 'OK',
17 | 'hotkey' => 'O',
18 | 'return' => true
19 | ]
20 | ];
21 |
22 | /**
23 | * @return array
24 | */
25 | public function getButtons()
26 | {
27 | return $this->buttons;
28 | }
29 |
30 | /**
31 | * @param array $buttons
32 | * @return $this
33 | */
34 | public function setButtons($buttons)
35 | {
36 | $this->buttons = $buttons;
37 |
38 | return $this;
39 | }
40 |
41 | /**
42 | * @return bool
43 | */
44 | public function display()
45 | {
46 | ncurses_init();
47 | $this->initScreen();
48 |
49 | //open a dialog box window
50 | $cord = $this->getCoordinates($this->height, $this->width, self::COORD_X_CENTER, self::COORD_Y_MIDDLE);
51 | $win = $this->createDialogWindow($cord['y'], $cord['x'], $this->height, $this->width, true);
52 |
53 | //output dialog text
54 | $this->strokePara($win, $this->text, $this->height, $this->width, 'center', true);
55 |
56 | //ok button
57 | $this->configureButtons();
58 |
59 | //wait for input
60 | do {
61 | $this->strokeAllButtons($win);
62 | ncurses_wrefresh($win);
63 | //get keyboard input
64 | $status = $this->getButtonInput($win);
65 | } while ($status === null);
66 |
67 | return true;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/NcursesWidget/NcursesNotice.php:
--------------------------------------------------------------------------------
1 | minWidth;
19 | }
20 |
21 | /**
22 | * @param int $minWidth
23 | * @return $this
24 | */
25 | public function setMinWidth($minWidth)
26 | {
27 | $this->minWidth = $minWidth;
28 |
29 | return $this;
30 | }
31 |
32 | public function display()
33 | {
34 | ncurses_init();
35 | $this->initScreen();
36 |
37 | if ((int) $this->width === 0 || (int) $this->height === 0) {
38 | // auto-detect required height & width based on text
39 | $this->width = $this->height = 0;
40 | $text = str_replace("\n", "|", $this->text); // decode any linebreaks
41 | $lines = explode("|", $text);
42 | foreach ($lines as $line) {
43 | $len = strlen($line);
44 | if ($len > $this->width) {
45 | $this->width = $len;
46 | }
47 | $this->height++;
48 | }
49 | }
50 |
51 | // open a dialog box window
52 | $width = max([$this->width, $this->minWidth]);
53 |
54 | $cord = $this->getCoordinates($this->height, $width, self::COORD_X_CENTER, self::COORD_Y_MIDDLE);
55 |
56 | $this->nwin = $this->createDialogWindow($cord['y'], $cord['x'], $this->height + 2, $width, true, 2);
57 |
58 | $this->strokePara($this->nwin, $this->text, $this->height, $width, 'center', false);
59 |
60 | ncurses_wrefresh($this->nwin);
61 | }
62 | }
63 |
--------------------------------------------------------------------------------