Vendored Dependencies
Also removed some commented out code
This commit is contained in:
22
vendor/github.com/br0xen/termbox-util/.gitignore
generated
vendored
Executable file
22
vendor/github.com/br0xen/termbox-util/.gitignore
generated
vendored
Executable file
@@ -0,0 +1,22 @@
|
||||
# Compiled Object files, Static and Dynamic libs (Shared Objects)
|
||||
*.o
|
||||
*.a
|
||||
*.so
|
||||
|
||||
# Folders
|
||||
_obj
|
||||
_test
|
||||
|
||||
# Architecture specific extensions/prefixes
|
||||
*.[568vq]
|
||||
[568vq].out
|
||||
|
||||
*.cgo1.go
|
||||
*.cgo2.c
|
||||
_cgo_defun.c
|
||||
_cgo_gotypes.go
|
||||
_cgo_export.*
|
||||
|
||||
_testmain.go
|
||||
|
||||
*.exe
|
674
vendor/github.com/br0xen/termbox-util/LICENSE
generated
vendored
Normal file
674
vendor/github.com/br0xen/termbox-util/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
{one line to give the program's name and a brief idea of what it does.}
|
||||
Copyright (C) {year} {name of author}
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
{project} Copyright (C) {year} {fullname}
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
4
vendor/github.com/br0xen/termbox-util/README.md
generated
vendored
Normal file
4
vendor/github.com/br0xen/termbox-util/README.md
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
termbox-util
|
||||
============
|
||||
|
||||
Utility Library for Termbox
|
212
vendor/github.com/br0xen/termbox-util/termbox_alertmodal.go
generated
vendored
Normal file
212
vendor/github.com/br0xen/termbox-util/termbox_alertmodal.go
generated
vendored
Normal file
@@ -0,0 +1,212 @@
|
||||
package termboxUtil
|
||||
|
||||
import (
|
||||
"github.com/nsf/termbox-go"
|
||||
)
|
||||
|
||||
// AlertModal is a modal with yes/no (or similar) buttons
|
||||
type AlertModal struct {
|
||||
id string
|
||||
title string
|
||||
text string
|
||||
x, y, width, height int
|
||||
showHelp bool
|
||||
cursor int
|
||||
bg, fg termbox.Attribute
|
||||
isDone bool
|
||||
accepted bool
|
||||
value string
|
||||
isVisible bool
|
||||
bordered bool
|
||||
tabSkip bool
|
||||
}
|
||||
|
||||
// CreateAlertModal Creates a confirmation modal with the specified attributes
|
||||
func CreateAlertModal(title string, x, y, width, height int, fg, bg termbox.Attribute) *AlertModal {
|
||||
i := AlertModal{title: title, x: x, y: y, width: width, height: height, fg: fg, bg: bg, bordered: true}
|
||||
if i.title == "" {
|
||||
i.title = "Alert!"
|
||||
}
|
||||
i.showHelp = true
|
||||
return &i
|
||||
}
|
||||
|
||||
// GetID returns this control's ID
|
||||
func (i *AlertModal) GetID() string { return i.id }
|
||||
|
||||
// SetID sets this control's ID
|
||||
func (i *AlertModal) SetID(newID string) {
|
||||
i.id = newID
|
||||
}
|
||||
|
||||
// GetTitle returns the current title of the modal
|
||||
func (i *AlertModal) GetTitle() string { return i.title }
|
||||
|
||||
// SetTitle sets the current title of the modal to s
|
||||
func (i *AlertModal) SetTitle(s string) {
|
||||
i.title = s
|
||||
}
|
||||
|
||||
// GetText returns the current text of the modal
|
||||
func (i *AlertModal) GetText() string { return i.text }
|
||||
|
||||
// SetText sets the text of the modal to s
|
||||
func (i *AlertModal) SetText(s string) {
|
||||
i.text = s
|
||||
}
|
||||
|
||||
// GetX returns the current x coordinate of the control
|
||||
func (i *AlertModal) GetX() int { return i.x }
|
||||
|
||||
// SetX sets the current x coordinate of the control to x
|
||||
func (i *AlertModal) SetX(x int) {
|
||||
i.x = x
|
||||
}
|
||||
|
||||
// GetY returns the current y coordinate of the control
|
||||
func (i *AlertModal) GetY() int { return i.y }
|
||||
|
||||
// SetY sets the current y coordinate of the control to y
|
||||
func (i *AlertModal) SetY(y int) {
|
||||
i.y = y
|
||||
}
|
||||
|
||||
// GetWidth returns the current width of the control
|
||||
func (i *AlertModal) GetWidth() int { return i.width }
|
||||
|
||||
// SetWidth sets the current control width to width
|
||||
func (i *AlertModal) SetWidth(width int) {
|
||||
i.width = width
|
||||
}
|
||||
|
||||
// GetHeight returns the current height of the control
|
||||
func (i *AlertModal) GetHeight() int { return i.height }
|
||||
|
||||
// SetHeight set the height of the control to height
|
||||
func (i *AlertModal) SetHeight(height int) {
|
||||
i.height = height
|
||||
}
|
||||
|
||||
// GetFgColor returns the foreground color
|
||||
func (i *AlertModal) GetFgColor() termbox.Attribute { return i.fg }
|
||||
|
||||
// SetFgColor sets the foreground color
|
||||
func (i *AlertModal) SetFgColor(fg termbox.Attribute) {
|
||||
i.fg = fg
|
||||
}
|
||||
|
||||
// GetBgColor returns the background color
|
||||
func (i *AlertModal) GetBgColor() termbox.Attribute { return i.bg }
|
||||
|
||||
// SetBgColor sets the current background color
|
||||
func (i *AlertModal) SetBgColor(bg termbox.Attribute) {
|
||||
i.bg = bg
|
||||
}
|
||||
|
||||
// IsBordered returns whether this control is bordered or not
|
||||
func (i *AlertModal) IsBordered() bool {
|
||||
return i.bordered
|
||||
}
|
||||
|
||||
// SetBordered sets whether we render a border around the frame
|
||||
func (i *AlertModal) SetBordered(b bool) {
|
||||
i.bordered = b
|
||||
}
|
||||
|
||||
// IsTabSkipped returns whether this control has it's tabskip flag set
|
||||
func (i *AlertModal) IsTabSkipped() bool {
|
||||
return i.tabSkip
|
||||
}
|
||||
|
||||
// SetTabSkip sets the tabskip flag for this control
|
||||
func (i *AlertModal) SetTabSkip(b bool) {
|
||||
i.tabSkip = b
|
||||
}
|
||||
|
||||
// HelpIsShown returns true or false if the help is displayed
|
||||
func (i *AlertModal) HelpIsShown() bool { return i.showHelp }
|
||||
|
||||
// ShowHelp sets whether or not to display the help text
|
||||
func (i *AlertModal) ShowHelp(b bool) {
|
||||
i.showHelp = b
|
||||
}
|
||||
|
||||
// GetBackground returns the current background color
|
||||
func (i *AlertModal) GetBackground() termbox.Attribute { return i.bg }
|
||||
|
||||
// SetBackground sets the background color to bg
|
||||
func (i *AlertModal) SetBackground(bg termbox.Attribute) {
|
||||
i.bg = bg
|
||||
}
|
||||
|
||||
// GetForeground returns the current foreground color
|
||||
func (i *AlertModal) GetForeground() termbox.Attribute { return i.fg }
|
||||
|
||||
// SetForeground sets the current foreground color to fg
|
||||
func (i *AlertModal) SetForeground(fg termbox.Attribute) {
|
||||
i.fg = fg
|
||||
}
|
||||
|
||||
// IsDone returns whether the user has answered the modal
|
||||
func (i *AlertModal) IsDone() bool { return i.isDone }
|
||||
|
||||
// SetDone sets whether the modal has completed it's purpose
|
||||
func (i *AlertModal) SetDone(b bool) {
|
||||
i.isDone = b
|
||||
}
|
||||
|
||||
// Show sets the visibility flag of the modal to true
|
||||
func (i *AlertModal) Show() {
|
||||
i.isVisible = true
|
||||
}
|
||||
|
||||
// Hide sets the visibility flag of the modal to false
|
||||
func (i *AlertModal) Hide() {
|
||||
i.isVisible = false
|
||||
}
|
||||
|
||||
// IsAccepted returns whether the user accepted the modal
|
||||
func (i *AlertModal) IsAccepted() bool { return i.accepted }
|
||||
|
||||
// Clear clears all of the non-positional parameters of the modal
|
||||
func (i *AlertModal) Clear() {
|
||||
i.title = ""
|
||||
i.text = ""
|
||||
i.accepted = false
|
||||
i.isDone = false
|
||||
}
|
||||
|
||||
// HandleEvent handles the termbox event and returns whether it was consumed
|
||||
func (i *AlertModal) HandleEvent(event termbox.Event) bool {
|
||||
if event.Key == termbox.KeyEnter {
|
||||
i.isDone = true
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Draw draws the modal
|
||||
func (i *AlertModal) Draw() {
|
||||
// First blank out the area we'll be putting the modal
|
||||
FillWithChar(' ', i.x, i.y, i.x+i.width, i.y+i.height, i.fg, i.bg)
|
||||
// Now draw the border
|
||||
DrawBorder(i.x, i.y, i.x+i.width, i.y+i.height, i.fg, i.bg)
|
||||
|
||||
nextY := i.y + 1
|
||||
// The title
|
||||
if i.title != "" {
|
||||
DrawStringAtPoint(i.title, i.x+1, nextY, i.fg, i.bg)
|
||||
nextY++
|
||||
FillWithChar('-', i.x+1, nextY, i.x+i.width-1, nextY, i.fg, i.bg)
|
||||
nextY++
|
||||
}
|
||||
if i.text != "" {
|
||||
DrawStringAtPoint(i.text, i.x+1, nextY, i.fg, i.bg)
|
||||
}
|
||||
nextY += 2
|
||||
if i.showHelp {
|
||||
helpString := "Press Enter to Continue"
|
||||
helpX := (i.x + i.width) - len(helpString) - 1
|
||||
DrawStringAtPoint(helpString, helpX, nextY, i.fg, i.bg)
|
||||
}
|
||||
}
|
171
vendor/github.com/br0xen/termbox-util/termbox_asciiart.go
generated
vendored
Normal file
171
vendor/github.com/br0xen/termbox-util/termbox_asciiart.go
generated
vendored
Normal file
@@ -0,0 +1,171 @@
|
||||
package termboxUtil
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/nsf/termbox-go"
|
||||
)
|
||||
|
||||
// ASCIIArt is a []string with more functions
|
||||
type ASCIIArt struct {
|
||||
id string
|
||||
contents []string
|
||||
x, y int
|
||||
bg, fg termbox.Attribute
|
||||
bordered bool
|
||||
tabSkip bool
|
||||
}
|
||||
|
||||
// CreateASCIIArt Create an ASCII art object from a string slice
|
||||
func CreateASCIIArt(c []string, x, y int, fg, bg termbox.Attribute) *ASCIIArt {
|
||||
i := ASCIIArt{contents: c, x: x, y: y, fg: fg, bg: bg, bordered: false, tabSkip: true}
|
||||
return &i
|
||||
}
|
||||
|
||||
// GetID returns this control's ID
|
||||
func (i *ASCIIArt) GetID() string { return i.id }
|
||||
|
||||
// SetID sets this control's ID
|
||||
func (i *ASCIIArt) SetID(newID string) {
|
||||
i.id = newID
|
||||
}
|
||||
|
||||
// GetX Return the x position of the modal
|
||||
func (i *ASCIIArt) GetX() int { return i.x }
|
||||
|
||||
// SetX set the x position of the modal to x
|
||||
func (i *ASCIIArt) SetX(x int) {
|
||||
i.x = x
|
||||
}
|
||||
|
||||
// GetY Return the y position of the modal
|
||||
func (i *ASCIIArt) GetY() int { return i.y }
|
||||
|
||||
// SetY Set the y position of the modal to y
|
||||
func (i *ASCIIArt) SetY(y int) {
|
||||
i.y = y
|
||||
}
|
||||
|
||||
// GetHeight Returns the number of strings in the contents slice
|
||||
func (i *ASCIIArt) GetHeight() int {
|
||||
return len(i.contents)
|
||||
}
|
||||
|
||||
// SetHeight truncates lines from the bottom of the ascii art
|
||||
func (i *ASCIIArt) SetHeight(h int) {
|
||||
if len(i.contents) > h {
|
||||
i.contents = i.contents[:h]
|
||||
} else {
|
||||
for j := len(i.contents); j < h; j++ {
|
||||
i.contents = append(i.contents, "")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// GetWidth Returns the number of strings in the contents slice
|
||||
func (i *ASCIIArt) GetWidth() int {
|
||||
// Find the longest line
|
||||
var ret int
|
||||
for j := range i.contents {
|
||||
if len(i.contents[j]) > ret {
|
||||
ret = len(i.contents[j])
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
// SetWidth Sets all lines in the contents to width w
|
||||
func (i *ASCIIArt) SetWidth(w int) {
|
||||
// Find the longest line
|
||||
for j := range i.contents {
|
||||
mkUp := w - len(i.contents[j])
|
||||
if mkUp > 0 {
|
||||
i.contents[j] = i.contents[j] + strings.Repeat(" ", mkUp)
|
||||
} else {
|
||||
i.contents[j] = i.contents[j][:w]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// SetContents Sets the contents of i to c
|
||||
func (i *ASCIIArt) SetContents(c []string) {
|
||||
i.contents = c
|
||||
}
|
||||
|
||||
// GetContents returns the ascii art
|
||||
func (i *ASCIIArt) GetContents() []string {
|
||||
return i.contents
|
||||
}
|
||||
|
||||
// SetContentLine Sets a specific line of the contents to s
|
||||
func (i *ASCIIArt) SetContentLine(s string, idx int) {
|
||||
if idx >= 0 && idx < len(i.contents) {
|
||||
i.contents[idx] = s
|
||||
}
|
||||
}
|
||||
|
||||
// GetFgColor returns the foreground color
|
||||
func (i *ASCIIArt) GetFgColor() termbox.Attribute { return i.fg }
|
||||
|
||||
// SetFgColor sets the foreground color
|
||||
func (i *ASCIIArt) SetFgColor(fg termbox.Attribute) {
|
||||
i.fg = fg
|
||||
}
|
||||
|
||||
// GetBgColor returns the background color
|
||||
func (i *ASCIIArt) GetBgColor() termbox.Attribute { return i.bg }
|
||||
|
||||
// SetBgColor sets the current background color
|
||||
func (i *ASCIIArt) SetBgColor(bg termbox.Attribute) {
|
||||
i.bg = bg
|
||||
}
|
||||
|
||||
// Align Align the Ascii art over width width with alignment a
|
||||
func (i *ASCIIArt) Align(a TextAlignment, width int) {
|
||||
// First get the width of the longest string in the slice
|
||||
var newContents []string
|
||||
incomingLength := 0
|
||||
for _, line := range i.contents {
|
||||
if len(line) > incomingLength {
|
||||
incomingLength = len(line)
|
||||
}
|
||||
}
|
||||
for _, line := range i.contents {
|
||||
newContents = append(newContents, AlignText(AlignText(line, incomingLength, AlignLeft), width, a))
|
||||
}
|
||||
i.contents = newContents
|
||||
}
|
||||
|
||||
// IsBordered returns whether this modal is bordered or not
|
||||
func (i *ASCIIArt) IsBordered() bool {
|
||||
return i.bordered
|
||||
}
|
||||
|
||||
// SetBordered sets whether we render a border around the frame
|
||||
func (i *ASCIIArt) SetBordered(b bool) {
|
||||
i.bordered = b
|
||||
}
|
||||
|
||||
// IsTabSkipped returns whether this modal has it's tabskip flag set
|
||||
func (i *ASCIIArt) IsTabSkipped() bool {
|
||||
return i.tabSkip
|
||||
}
|
||||
|
||||
// SetTabSkip sets the tabskip flag for this control
|
||||
func (i *ASCIIArt) SetTabSkip(b bool) {
|
||||
i.tabSkip = b
|
||||
}
|
||||
|
||||
// HandleEvent accepts the termbox event and returns whether it was consumed
|
||||
func (i *ASCIIArt) HandleEvent(event termbox.Event) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// Draw outputs the input field on the screen
|
||||
func (i *ASCIIArt) Draw() {
|
||||
drawX, drawY := i.x, i.y
|
||||
for _, line := range i.contents {
|
||||
DrawStringAtPoint(line, drawX, drawY, i.fg, i.bg)
|
||||
drawY++
|
||||
}
|
||||
}
|
201
vendor/github.com/br0xen/termbox-util/termbox_confirmmodal.go
generated
vendored
Normal file
201
vendor/github.com/br0xen/termbox-util/termbox_confirmmodal.go
generated
vendored
Normal file
@@ -0,0 +1,201 @@
|
||||
package termboxUtil
|
||||
|
||||
import (
|
||||
"github.com/nsf/termbox-go"
|
||||
)
|
||||
|
||||
// ConfirmModal is a modal with yes/no (or similar) buttons
|
||||
type ConfirmModal struct {
|
||||
id string
|
||||
title string
|
||||
text string
|
||||
x, y, width, height int
|
||||
showHelp bool
|
||||
cursor int
|
||||
bg, fg termbox.Attribute
|
||||
isDone bool
|
||||
accepted bool
|
||||
value string
|
||||
isVisible bool
|
||||
bordered bool
|
||||
tabSkip bool
|
||||
}
|
||||
|
||||
// CreateConfirmModal Creates a confirmation modal with the specified attributes
|
||||
func CreateConfirmModal(title string, x, y, width, height int, fg, bg termbox.Attribute) *ConfirmModal {
|
||||
i := ConfirmModal{title: title, x: x, y: y, width: width, height: height, fg: fg, bg: bg}
|
||||
if i.title == "" && i.text == "" {
|
||||
i.title = "Confirm?"
|
||||
}
|
||||
i.showHelp = true
|
||||
return &i
|
||||
}
|
||||
|
||||
// GetID returns this control's ID
|
||||
func (i *ConfirmModal) GetID() string { return i.id }
|
||||
|
||||
// SetID sets this control's ID
|
||||
func (i *ConfirmModal) SetID(newID string) {
|
||||
i.id = newID
|
||||
}
|
||||
|
||||
// GetTitle returns the current title of the modal
|
||||
func (i *ConfirmModal) GetTitle() string { return i.title }
|
||||
|
||||
// SetTitle sets the current title of the modal to s
|
||||
func (i *ConfirmModal) SetTitle(s string) {
|
||||
i.title = s
|
||||
}
|
||||
|
||||
// GetText returns the current text of the modal
|
||||
func (i *ConfirmModal) GetText() string { return i.text }
|
||||
|
||||
// SetText sets the text of the modal to s
|
||||
func (i *ConfirmModal) SetText(s string) {
|
||||
i.text = s
|
||||
}
|
||||
|
||||
// GetX returns the current x coordinate of the modal
|
||||
func (i *ConfirmModal) GetX() int { return i.x }
|
||||
|
||||
// SetX sets the current x coordinate of the modal to x
|
||||
func (i *ConfirmModal) SetX(x int) {
|
||||
i.x = x
|
||||
}
|
||||
|
||||
// GetY returns the current y coordinate of the modal
|
||||
func (i *ConfirmModal) GetY() int { return i.y }
|
||||
|
||||
// SetY sets the current y coordinate of the modal to y
|
||||
func (i *ConfirmModal) SetY(y int) {
|
||||
i.y = y
|
||||
}
|
||||
|
||||
// GetWidth returns the current width of the modal
|
||||
func (i *ConfirmModal) GetWidth() int { return i.width }
|
||||
|
||||
// SetWidth sets the current modal width to width
|
||||
func (i *ConfirmModal) SetWidth(width int) {
|
||||
i.width = width
|
||||
}
|
||||
|
||||
// GetHeight returns the current height of the modal
|
||||
func (i *ConfirmModal) GetHeight() int { return i.height }
|
||||
|
||||
// SetHeight set the height of the modal to height
|
||||
func (i *ConfirmModal) SetHeight(height int) {
|
||||
i.height = height
|
||||
}
|
||||
|
||||
// HelpIsShown returns true or false if the help is displayed
|
||||
func (i *ConfirmModal) HelpIsShown() bool { return i.showHelp }
|
||||
|
||||
// ShowHelp sets whether or not to display the help text
|
||||
func (i *ConfirmModal) ShowHelp(b bool) {
|
||||
i.showHelp = b
|
||||
}
|
||||
|
||||
// GetFgColor returns the foreground color
|
||||
func (i *ConfirmModal) GetFgColor() termbox.Attribute { return i.fg }
|
||||
|
||||
// SetFgColor sets the foreground color
|
||||
func (i *ConfirmModal) SetFgColor(fg termbox.Attribute) {
|
||||
i.fg = fg
|
||||
}
|
||||
|
||||
// GetBgColor returns the background color
|
||||
func (i *ConfirmModal) GetBgColor() termbox.Attribute { return i.bg }
|
||||
|
||||
// SetBgColor sets the current background color
|
||||
func (i *ConfirmModal) SetBgColor(bg termbox.Attribute) {
|
||||
i.bg = bg
|
||||
}
|
||||
|
||||
// IsDone returns whether the user has answered the modal
|
||||
func (i *ConfirmModal) IsDone() bool { return i.isDone }
|
||||
|
||||
// SetDone sets whether the modal has completed it's purpose
|
||||
func (i *ConfirmModal) SetDone(b bool) {
|
||||
i.isDone = b
|
||||
}
|
||||
|
||||
// Show sets the visibility flag of the modal to true
|
||||
func (i *ConfirmModal) Show() {
|
||||
i.isVisible = true
|
||||
}
|
||||
|
||||
// Hide sets the visibility flag of the modal to false
|
||||
func (i *ConfirmModal) Hide() {
|
||||
i.isVisible = false
|
||||
}
|
||||
|
||||
// IsAccepted returns whether the user accepted the modal
|
||||
func (i *ConfirmModal) IsAccepted() bool { return i.accepted }
|
||||
|
||||
// Clear clears all of the non-positional parameters of the modal
|
||||
func (i *ConfirmModal) Clear() {
|
||||
i.title = ""
|
||||
i.text = ""
|
||||
i.accepted = false
|
||||
i.isDone = false
|
||||
}
|
||||
|
||||
// IsBordered returns whether this modal is bordered or not
|
||||
func (i *ConfirmModal) IsBordered() bool {
|
||||
return i.bordered
|
||||
}
|
||||
|
||||
// SetBordered sets whether we render a border around the frame
|
||||
func (i *ConfirmModal) SetBordered(b bool) {
|
||||
i.bordered = b
|
||||
}
|
||||
|
||||
// IsTabSkipped returns whether this modal has it's tabskip flag set
|
||||
func (i *ConfirmModal) IsTabSkipped() bool {
|
||||
return i.tabSkip
|
||||
}
|
||||
|
||||
// SetTabSkip sets the tabskip flag for this control
|
||||
func (i *ConfirmModal) SetTabSkip(b bool) {
|
||||
i.tabSkip = b
|
||||
}
|
||||
|
||||
// HandleEvent handles the termbox event and returns whether it was consumed
|
||||
func (i *ConfirmModal) HandleEvent(event termbox.Event) bool {
|
||||
if event.Ch == 'Y' || event.Ch == 'y' {
|
||||
i.accepted = true
|
||||
i.isDone = true
|
||||
return true
|
||||
} else if event.Ch == 'N' || event.Ch == 'n' {
|
||||
i.accepted = false
|
||||
i.isDone = true
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Draw draws the modal
|
||||
func (i *ConfirmModal) Draw() {
|
||||
// First blank out the area we'll be putting the modal
|
||||
FillWithChar(' ', i.x, i.y, i.x+i.width, i.y+i.height, i.fg, i.bg)
|
||||
// Now draw the border
|
||||
DrawBorder(i.x, i.y, i.x+i.width, i.y+i.height, i.fg, i.bg)
|
||||
|
||||
nextY := i.y + 1
|
||||
// The title
|
||||
if i.title != "" {
|
||||
DrawStringAtPoint(i.title, i.x+1, nextY, i.fg, i.bg)
|
||||
nextY++
|
||||
FillWithChar('-', i.x+1, nextY, i.x+i.width-1, nextY, i.fg, i.bg)
|
||||
nextY++
|
||||
}
|
||||
if i.text != "" {
|
||||
DrawStringAtPoint(i.text, i.x+1, nextY, i.fg, i.bg)
|
||||
}
|
||||
nextY += 2
|
||||
if i.showHelp {
|
||||
helpString := " (Y/y) Confirm. (N/n) Reject. "
|
||||
helpX := (i.x + i.width) - len(helpString) - 1
|
||||
DrawStringAtPoint(helpString, helpX, nextY, i.fg, i.bg)
|
||||
}
|
||||
}
|
177
vendor/github.com/br0xen/termbox-util/termbox_dropmenu.go
generated
vendored
Normal file
177
vendor/github.com/br0xen/termbox-util/termbox_dropmenu.go
generated
vendored
Normal file
@@ -0,0 +1,177 @@
|
||||
package termboxUtil
|
||||
|
||||
import "github.com/nsf/termbox-go"
|
||||
|
||||
// DropMenu is a title that, when active drops a menu down
|
||||
type DropMenu struct {
|
||||
id string
|
||||
title string
|
||||
x, y, width, height int
|
||||
bg, fg termbox.Attribute
|
||||
selectedBg, selectedFg termbox.Attribute
|
||||
menu *Menu
|
||||
menuSelected bool
|
||||
showMenu bool
|
||||
bordered bool
|
||||
tabSkip bool
|
||||
}
|
||||
|
||||
// CreateDropMenu Creates a menu with the specified attributes
|
||||
func CreateDropMenu(title string, options []string, x, y, width, height int, fg, bg, selectedFg, selectedBg termbox.Attribute) *DropMenu {
|
||||
i := DropMenu{
|
||||
title: title,
|
||||
x: x, y: y, width: width, height: height,
|
||||
fg: fg, bg: bg,
|
||||
selectedFg: fg, selectedBg: bg,
|
||||
}
|
||||
i.menu = CreateMenu("", options, x, y+2, width, height, fg, bg)
|
||||
return &i
|
||||
}
|
||||
|
||||
// GetID returns this control's ID
|
||||
func (i *DropMenu) GetID() string { return i.id }
|
||||
|
||||
// SetID sets this control's ID
|
||||
func (i *DropMenu) SetID(newID string) {
|
||||
i.id = newID
|
||||
}
|
||||
|
||||
// GetTitle returns the current title of the menu
|
||||
func (i *DropMenu) GetTitle() string { return i.title }
|
||||
|
||||
// SetTitle sets the current title of the menu to s
|
||||
func (i *DropMenu) SetTitle(s string) {
|
||||
i.title = s
|
||||
}
|
||||
|
||||
// GetMenu returns the menu for this dropmenu
|
||||
func (i *DropMenu) GetMenu() *Menu {
|
||||
return i.menu
|
||||
}
|
||||
|
||||
// GetX returns the current x coordinate of the menu
|
||||
func (i *DropMenu) GetX() int { return i.x }
|
||||
|
||||
// SetX sets the current x coordinate of the menu to x
|
||||
func (i *DropMenu) SetX(x int) {
|
||||
i.x = x
|
||||
}
|
||||
|
||||
// GetY returns the current y coordinate of the menu
|
||||
func (i *DropMenu) GetY() int { return i.y }
|
||||
|
||||
// SetY sets the current y coordinate of the menu to y
|
||||
func (i *DropMenu) SetY(y int) {
|
||||
i.y = y
|
||||
}
|
||||
|
||||
// GetWidth returns the current width of the menu
|
||||
func (i *DropMenu) GetWidth() int { return i.width }
|
||||
|
||||
// SetWidth sets the current menu width to width
|
||||
func (i *DropMenu) SetWidth(width int) {
|
||||
i.width = width
|
||||
}
|
||||
|
||||
// GetHeight returns the current height of the menu
|
||||
func (i *DropMenu) GetHeight() int { return i.height }
|
||||
|
||||
// SetHeight set the height of the menu to height
|
||||
func (i *DropMenu) SetHeight(height int) {
|
||||
i.height = height
|
||||
}
|
||||
|
||||
// GetFgColor returns the foreground color
|
||||
func (i *DropMenu) GetFgColor() termbox.Attribute { return i.fg }
|
||||
|
||||
// SetFgColor sets the foreground color
|
||||
func (i *DropMenu) SetFgColor(fg termbox.Attribute) {
|
||||
i.fg = fg
|
||||
}
|
||||
|
||||
// GetBgColor returns the background color
|
||||
func (i *DropMenu) GetBgColor() termbox.Attribute { return i.bg }
|
||||
|
||||
// SetBgColor sets the current background color
|
||||
func (i *DropMenu) SetBgColor(bg termbox.Attribute) {
|
||||
i.bg = bg
|
||||
}
|
||||
|
||||
// IsBordered returns the bordered flag
|
||||
func (i *DropMenu) IsBordered() bool { return i.bordered }
|
||||
|
||||
// SetBordered sets the bordered flag
|
||||
func (i *DropMenu) SetBordered(b bool) {
|
||||
i.bordered = b
|
||||
i.menu.SetBordered(b)
|
||||
}
|
||||
|
||||
// IsDone returns whether the user has answered the modal
|
||||
func (i *DropMenu) IsDone() bool { return i.menu.isDone }
|
||||
|
||||
// SetDone sets whether the modal has completed it's purpose
|
||||
func (i *DropMenu) SetDone(b bool) {
|
||||
i.menu.isDone = b
|
||||
}
|
||||
|
||||
// IsTabSkipped returns whether this modal has it's tabskip flag set
|
||||
func (i *DropMenu) IsTabSkipped() bool {
|
||||
return i.tabSkip
|
||||
}
|
||||
|
||||
// SetTabSkip sets the tabskip flag for this control
|
||||
func (i *DropMenu) SetTabSkip(b bool) {
|
||||
i.tabSkip = b
|
||||
}
|
||||
|
||||
// ShowMenu tells the menu to draw the options
|
||||
func (i *DropMenu) ShowMenu() {
|
||||
i.showMenu = true
|
||||
i.menuSelected = true
|
||||
}
|
||||
|
||||
// HideMenu tells the menu to hide the options
|
||||
func (i *DropMenu) HideMenu() {
|
||||
i.showMenu = false
|
||||
i.menuSelected = false
|
||||
}
|
||||
|
||||
// HandleEvent handles the termbox event and returns whether it was consumed
|
||||
func (i *DropMenu) HandleEvent(event termbox.Event) bool {
|
||||
moveUp := (event.Key == termbox.KeyArrowUp || (i.menu.vimMode && event.Ch == 'k'))
|
||||
moveDown := (event.Key == termbox.KeyArrowDown || (i.menu.vimMode && event.Ch == 'j'))
|
||||
if i.menuSelected {
|
||||
selIdx := i.menu.GetSelectedIndex()
|
||||
if (moveUp && selIdx == 0) || (moveDown && selIdx == (len(i.menu.options)-1)) {
|
||||
i.menuSelected = false
|
||||
} else {
|
||||
if i.menu.HandleEvent(event) {
|
||||
if i.menu.IsDone() {
|
||||
i.HideMenu()
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
} else {
|
||||
i.ShowMenu()
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Draw draws the menu
|
||||
func (i *DropMenu) Draw() {
|
||||
// The title
|
||||
ttlFg, ttlBg := i.fg, i.bg
|
||||
if !i.menuSelected {
|
||||
ttlFg, ttlBg = i.selectedFg, i.selectedBg
|
||||
}
|
||||
ttlTxt := i.title
|
||||
if i.showMenu {
|
||||
ttlTxt = ttlTxt + "-Showing Menu"
|
||||
}
|
||||
DrawStringAtPoint(AlignText(i.title, i.width, AlignLeft), i.x, i.y, ttlFg, ttlBg)
|
||||
if i.showMenu {
|
||||
i.menu.Draw()
|
||||
}
|
||||
}
|
198
vendor/github.com/br0xen/termbox-util/termbox_frame.go
generated
vendored
Normal file
198
vendor/github.com/br0xen/termbox-util/termbox_frame.go
generated
vendored
Normal file
@@ -0,0 +1,198 @@
|
||||
package termboxUtil
|
||||
|
||||
import "github.com/nsf/termbox-go"
|
||||
|
||||
// Frame is a frame for holding other elements
|
||||
// It manages it's own x/y, tab index
|
||||
type Frame struct {
|
||||
id string
|
||||
x, y, width, height int
|
||||
tabIdx int
|
||||
fg, bg termbox.Attribute
|
||||
bordered bool
|
||||
controls []termboxControl
|
||||
tabSkip bool
|
||||
}
|
||||
|
||||
// CreateFrame creates a Frame at x, y that is w by h
|
||||
func CreateFrame(x, y, w, h int, fg, bg termbox.Attribute) *Frame {
|
||||
s := Frame{x: x, y: y, width: w, height: h, fg: fg, bg: bg, bordered: true}
|
||||
return &s
|
||||
}
|
||||
|
||||
// GetID returns this control's ID
|
||||
func (i *Frame) GetID() string { return i.id }
|
||||
|
||||
// SetID sets this control's ID
|
||||
func (i *Frame) SetID(newID string) {
|
||||
i.id = newID
|
||||
}
|
||||
|
||||
// GetX returns the x position of the frame
|
||||
func (i *Frame) GetX() int { return i.x }
|
||||
|
||||
// SetX sets the x position of the frame
|
||||
func (i *Frame) SetX(x int) {
|
||||
i.x = x
|
||||
}
|
||||
|
||||
// GetY returns the y position of the frame
|
||||
func (i *Frame) GetY() int { return i.y }
|
||||
|
||||
// SetY sets the y position of the frame
|
||||
func (i *Frame) SetY(y int) {
|
||||
i.y = y
|
||||
}
|
||||
|
||||
// GetWidth returns the current width of the frame
|
||||
func (i *Frame) GetWidth() int { return i.width }
|
||||
|
||||
// SetWidth sets the current width of the frame
|
||||
func (i *Frame) SetWidth(w int) {
|
||||
i.width = w
|
||||
}
|
||||
|
||||
// GetHeight returns the current height of the frame
|
||||
func (i *Frame) GetHeight() int { return i.height }
|
||||
|
||||
// SetHeight sets the current height of the frame
|
||||
func (i *Frame) SetHeight(h int) {
|
||||
i.height = h
|
||||
}
|
||||
|
||||
// GetFgColor returns the foreground color
|
||||
func (i *Frame) GetFgColor() termbox.Attribute { return i.fg }
|
||||
|
||||
// SetFgColor sets the foreground color
|
||||
func (i *Frame) SetFgColor(fg termbox.Attribute) {
|
||||
i.fg = fg
|
||||
}
|
||||
|
||||
// GetBgColor returns the background color
|
||||
func (i *Frame) GetBgColor() termbox.Attribute { return i.bg }
|
||||
|
||||
// SetBgColor sets the current background color
|
||||
func (i *Frame) SetBgColor(bg termbox.Attribute) {
|
||||
i.bg = bg
|
||||
}
|
||||
|
||||
// IsBordered returns true or false if this frame has a border
|
||||
func (i *Frame) IsBordered() bool { return i.bordered }
|
||||
|
||||
// SetBordered sets whether we render a border around the frame
|
||||
func (i *Frame) SetBordered(b bool) {
|
||||
i.bordered = b
|
||||
}
|
||||
|
||||
// IsTabSkipped returns whether this modal has it's tabskip flag set
|
||||
func (i *Frame) IsTabSkipped() bool {
|
||||
return i.tabSkip
|
||||
}
|
||||
|
||||
// SetTabSkip sets the tabskip flag for this control
|
||||
func (i *Frame) SetTabSkip(b bool) {
|
||||
i.tabSkip = b
|
||||
}
|
||||
|
||||
// AddControl adds a control to the frame
|
||||
func (i *Frame) AddControl(t termboxControl) {
|
||||
i.controls = append(i.controls, t)
|
||||
}
|
||||
|
||||
// GetActiveControl returns the control at tabIdx
|
||||
func (i *Frame) GetActiveControl() termboxControl {
|
||||
if len(i.controls) >= i.tabIdx {
|
||||
return i.controls[i.tabIdx]
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetControls returns a slice of all controls
|
||||
func (i *Frame) GetControls() []termboxControl {
|
||||
return i.controls
|
||||
}
|
||||
|
||||
// GetControl returns the control at index i
|
||||
func (i *Frame) GetControl(idx int) termboxControl {
|
||||
if len(i.controls) >= idx {
|
||||
return i.controls[idx]
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetControlCount returns the number of controls contained
|
||||
func (i *Frame) GetControlCount() int {
|
||||
return len(i.controls)
|
||||
}
|
||||
|
||||
// GetLastControl returns the last control contained
|
||||
func (i *Frame) GetLastControl() termboxControl {
|
||||
return i.controls[len(i.controls)-1]
|
||||
}
|
||||
|
||||
// DrawControl figures out the relative position of the control,
|
||||
// sets it, draws it, then resets it.
|
||||
func (i *Frame) DrawControl(t termboxControl) {
|
||||
ctlX, ctlY := t.GetX(), t.GetY()
|
||||
t.SetX((i.GetX() + ctlX))
|
||||
t.SetY((i.GetY() + ctlY))
|
||||
t.Draw()
|
||||
t.SetX(ctlX)
|
||||
t.SetY(ctlY)
|
||||
}
|
||||
|
||||
// GetBottomY returns the y of the lowest control in the frame
|
||||
func (i *Frame) GetBottomY() int {
|
||||
var ret int
|
||||
for idx := range i.controls {
|
||||
if i.controls[idx].GetY()+i.controls[idx].GetHeight() > ret {
|
||||
ret = i.controls[idx].GetY() + i.controls[idx].GetHeight()
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
// HandleEvent accepts the termbox event and returns whether it was consumed
|
||||
func (i *Frame) HandleEvent(event termbox.Event) bool {
|
||||
if event.Key == termbox.KeyTab {
|
||||
i.FindNextTabStop()
|
||||
return true
|
||||
}
|
||||
return i.controls[i.tabIdx].HandleEvent(event)
|
||||
}
|
||||
|
||||
// FindNextTabStop finds the next control that can be tabbed to
|
||||
// A return of true means it found a different one than we started on.
|
||||
func (i *Frame) FindNextTabStop() bool {
|
||||
startTab := i.tabIdx
|
||||
i.tabIdx = (i.tabIdx + 1) % len(i.controls)
|
||||
for i.controls[i.tabIdx].IsTabSkipped() {
|
||||
i.tabIdx = (i.tabIdx + 1) % len(i.controls)
|
||||
if i.tabIdx == startTab {
|
||||
break
|
||||
}
|
||||
}
|
||||
return i.tabIdx != startTab
|
||||
}
|
||||
|
||||
// Draw outputs the Scoll Frame on the screen
|
||||
func (i *Frame) Draw() {
|
||||
maxWidth := i.width
|
||||
maxHeight := i.height
|
||||
x, y := i.x, i.y
|
||||
startX := i.x
|
||||
startY := i.y
|
||||
if i.bordered {
|
||||
FillWithChar(' ', i.x, i.y, i.x+i.width, i.y+i.height, i.fg, i.bg)
|
||||
DrawBorder(i.x, i.y, i.x+i.width, i.y+i.height, i.fg, i.bg)
|
||||
maxWidth--
|
||||
maxHeight--
|
||||
x++
|
||||
y++
|
||||
startX++
|
||||
startY++
|
||||
}
|
||||
for idx := range i.controls {
|
||||
i.DrawControl(i.controls[idx])
|
||||
}
|
||||
}
|
260
vendor/github.com/br0xen/termbox-util/termbox_inputfield.go
generated
vendored
Normal file
260
vendor/github.com/br0xen/termbox-util/termbox_inputfield.go
generated
vendored
Normal file
@@ -0,0 +1,260 @@
|
||||
package termboxUtil
|
||||
|
||||
import "github.com/nsf/termbox-go"
|
||||
|
||||
// InputField is a field for inputting text
|
||||
type InputField struct {
|
||||
id string
|
||||
value string
|
||||
x, y, width, height int
|
||||
cursor int
|
||||
fg, bg termbox.Attribute
|
||||
cursorFg, cursorBg termbox.Attribute
|
||||
bordered bool
|
||||
wrap bool
|
||||
multiline bool
|
||||
tabSkip bool
|
||||
}
|
||||
|
||||
// CreateInputField creates an input field at x, y that is w by h
|
||||
func CreateInputField(x, y, w, h int, fg, bg termbox.Attribute) *InputField {
|
||||
i := InputField{x: x, y: y, width: w, height: h, fg: fg, bg: bg, cursorFg: bg, cursorBg: fg}
|
||||
return &i
|
||||
}
|
||||
|
||||
// GetID returns this control's ID
|
||||
func (i *InputField) GetID() string { return i.id }
|
||||
|
||||
// SetID sets this control's ID
|
||||
func (i *InputField) SetID(newID string) {
|
||||
i.id = newID
|
||||
}
|
||||
|
||||
// GetValue gets the current text that is in the InputField
|
||||
func (i *InputField) GetValue() string { return i.value }
|
||||
|
||||
// SetValue sets the current text in the InputField to s
|
||||
func (i *InputField) SetValue(s string) {
|
||||
i.value = s
|
||||
}
|
||||
|
||||
// GetX returns the x position of the input field
|
||||
func (i *InputField) GetX() int { return i.x }
|
||||
|
||||
// SetX sets the x position of the input field
|
||||
func (i *InputField) SetX(x int) {
|
||||
i.x = x
|
||||
}
|
||||
|
||||
// GetY returns the y position of the input field
|
||||
func (i *InputField) GetY() int { return i.y }
|
||||
|
||||
// SetY sets the y position of the input field
|
||||
func (i *InputField) SetY(y int) {
|
||||
i.y = y
|
||||
}
|
||||
|
||||
// GetWidth returns the current width of the input field
|
||||
func (i *InputField) GetWidth() int { return i.width }
|
||||
|
||||
// SetWidth sets the current width of the input field
|
||||
func (i *InputField) SetWidth(w int) {
|
||||
i.width = w
|
||||
}
|
||||
|
||||
// GetHeight returns the current height of the input field
|
||||
func (i *InputField) GetHeight() int { return i.height }
|
||||
|
||||
// SetHeight sets the current height of the input field
|
||||
func (i *InputField) SetHeight(h int) {
|
||||
i.height = h
|
||||
}
|
||||
|
||||
// GetFgColor returns the foreground color
|
||||
func (i *InputField) GetFgColor() termbox.Attribute { return i.fg }
|
||||
|
||||
// SetFgColor sets the foreground color
|
||||
func (i *InputField) SetFgColor(fg termbox.Attribute) {
|
||||
i.fg = fg
|
||||
}
|
||||
|
||||
// GetBgColor returns the background color
|
||||
func (i *InputField) GetBgColor() termbox.Attribute { return i.bg }
|
||||
|
||||
// SetBgColor sets the current background color
|
||||
func (i *InputField) SetBgColor(bg termbox.Attribute) {
|
||||
i.bg = bg
|
||||
}
|
||||
|
||||
// IsBordered returns true or false if this input field has a border
|
||||
func (i *InputField) IsBordered() bool { return i.bordered }
|
||||
|
||||
// SetBordered sets whether we render a border around the input field
|
||||
func (i *InputField) SetBordered(b bool) {
|
||||
i.bordered = b
|
||||
}
|
||||
|
||||
// IsTabSkipped returns whether this modal has it's tabskip flag set
|
||||
func (i *InputField) IsTabSkipped() bool {
|
||||
return i.tabSkip
|
||||
}
|
||||
|
||||
// SetTabSkip sets the tabskip flag for this control
|
||||
func (i *InputField) SetTabSkip(b bool) {
|
||||
i.tabSkip = b
|
||||
}
|
||||
|
||||
// DoesWrap returns true or false if this input field wraps text
|
||||
func (i *InputField) DoesWrap() bool { return i.wrap }
|
||||
|
||||
// SetWrap sets whether we wrap the text at width.
|
||||
func (i *InputField) SetWrap(b bool) {
|
||||
i.wrap = b
|
||||
}
|
||||
|
||||
// IsMultiline returns true or false if this field can have multiple lines
|
||||
func (i *InputField) IsMultiline() bool { return i.multiline }
|
||||
|
||||
// SetMultiline sets whether the field can have multiple lines
|
||||
func (i *InputField) SetMultiline(b bool) {
|
||||
i.multiline = b
|
||||
}
|
||||
|
||||
// HandleEvent accepts the termbox event and returns whether it was consumed
|
||||
func (i *InputField) HandleEvent(event termbox.Event) bool {
|
||||
if event.Key == termbox.KeyBackspace || event.Key == termbox.KeyBackspace2 {
|
||||
if i.cursor+len(i.value) > 0 {
|
||||
crs := len(i.value)
|
||||
if i.cursor < 0 {
|
||||
crs = i.cursor + len(i.value)
|
||||
}
|
||||
i.value = i.value[:crs-1] + i.value[crs:]
|
||||
//i.value = i.value[:len(i.value)-1]
|
||||
}
|
||||
} else if event.Key == termbox.KeyArrowLeft {
|
||||
if i.cursor+len(i.value) > 0 {
|
||||
i.cursor--
|
||||
}
|
||||
} else if event.Key == termbox.KeyArrowRight {
|
||||
if i.cursor < 0 {
|
||||
i.cursor++
|
||||
}
|
||||
} else if event.Key == termbox.KeyCtrlU {
|
||||
// Ctrl+U Clears the Input (before the cursor)
|
||||
i.value = i.value[i.cursor:]
|
||||
} else {
|
||||
// Get the rune to add to our value. Space and Tab are special cases where
|
||||
// we can't use the event's rune directly
|
||||
var ch string
|
||||
switch event.Key {
|
||||
case termbox.KeySpace:
|
||||
ch = " "
|
||||
case termbox.KeyTab:
|
||||
ch = "\t"
|
||||
case termbox.KeyEnter:
|
||||
if i.multiline {
|
||||
ch = "\n"
|
||||
}
|
||||
default:
|
||||
if KeyIsAlphaNumeric(event) || KeyIsSymbol(event) {
|
||||
ch = string(event.Ch)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Handle newlines
|
||||
if i.cursor+len(i.value) == 0 {
|
||||
i.value = string(ch) + i.value
|
||||
} else if i.cursor == 0 {
|
||||
i.value = i.value + string(ch)
|
||||
} else {
|
||||
strPt1 := i.value[:(len(i.value) + i.cursor)]
|
||||
strPt2 := i.value[(len(i.value) + i.cursor):]
|
||||
i.value = strPt1 + string(ch) + strPt2
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Draw outputs the input field on the screen
|
||||
func (i *InputField) Draw() {
|
||||
maxWidth := i.width
|
||||
maxHeight := i.height
|
||||
x, y := i.x, i.y
|
||||
startX := i.x
|
||||
startY := i.y
|
||||
if i.bordered {
|
||||
DrawBorder(i.x, i.y, i.x+i.width, i.y+i.height, i.fg, i.bg)
|
||||
maxWidth--
|
||||
maxHeight--
|
||||
x++
|
||||
y++
|
||||
startX++
|
||||
startY++
|
||||
}
|
||||
|
||||
var strPt1, strPt2 string
|
||||
var cursorRune rune
|
||||
if len(i.value) > 0 {
|
||||
if i.cursor+len(i.value) == 0 {
|
||||
strPt1 = ""
|
||||
strPt2 = i.value[1:]
|
||||
cursorRune = rune(i.value[0])
|
||||
} else if i.cursor == 0 {
|
||||
strPt1 = i.value
|
||||
strPt2 = ""
|
||||
cursorRune = ' '
|
||||
} else {
|
||||
strPt1 = i.value[:(len(i.value) + i.cursor)]
|
||||
strPt2 = i.value[(len(i.value)+i.cursor)+1:]
|
||||
cursorRune = rune(i.value[len(i.value)+i.cursor])
|
||||
}
|
||||
} else {
|
||||
strPt1, strPt2, cursorRune = "", "", ' '
|
||||
}
|
||||
if i.wrap {
|
||||
// Split the text into maxWidth chunks
|
||||
for len(strPt1) > maxWidth {
|
||||
breakAt := maxWidth
|
||||
DrawStringAtPoint(strPt1[:breakAt], x, y, i.fg, i.bg)
|
||||
x = startX
|
||||
y++
|
||||
strPt1 = strPt1[breakAt:]
|
||||
}
|
||||
x, y = DrawStringAtPoint(strPt1, x, y, i.fg, i.bg)
|
||||
if x >= maxWidth {
|
||||
y++
|
||||
x = startX
|
||||
}
|
||||
termbox.SetCell(x, y, cursorRune, i.cursorFg, i.cursorBg)
|
||||
x++
|
||||
if len(strPt2) > 0 {
|
||||
lenLeft := maxWidth - len(strPt1) - 1
|
||||
if lenLeft > 0 && len(strPt2) > lenLeft {
|
||||
DrawStringAtPoint(strPt2[:lenLeft], x+1, y, i.fg, i.bg)
|
||||
strPt2 = strPt2[lenLeft:]
|
||||
}
|
||||
for len(strPt2) > maxWidth {
|
||||
breakAt := maxWidth
|
||||
DrawStringAtPoint(strPt2[:breakAt], x, y, i.fg, i.bg)
|
||||
x = startX
|
||||
y++
|
||||
strPt2 = strPt2[breakAt:]
|
||||
}
|
||||
x, y = DrawStringAtPoint(strPt2, x, y, i.fg, i.bg)
|
||||
}
|
||||
} else {
|
||||
for len(strPt1)+len(strPt2)+1 > maxWidth {
|
||||
if len(strPt1) >= len(strPt2) {
|
||||
if len(strPt1) == 0 {
|
||||
break
|
||||
}
|
||||
strPt1 = strPt1[1:]
|
||||
} else {
|
||||
strPt2 = strPt2[:len(strPt2)-1]
|
||||
}
|
||||
}
|
||||
x, y = DrawStringAtPoint(strPt1, i.x+1, i.y+1, i.fg, i.bg)
|
||||
termbox.SetCell(x, y, cursorRune, i.cursorFg, i.cursorBg)
|
||||
DrawStringAtPoint(strPt2, x+1, y, i.fg, i.bg)
|
||||
}
|
||||
}
|
257
vendor/github.com/br0xen/termbox-util/termbox_inputmodal.go
generated
vendored
Normal file
257
vendor/github.com/br0xen/termbox-util/termbox_inputmodal.go
generated
vendored
Normal file
@@ -0,0 +1,257 @@
|
||||
package termboxUtil
|
||||
|
||||
import (
|
||||
"github.com/nsf/termbox-go"
|
||||
)
|
||||
|
||||
// InputModal A modal for text input
|
||||
type InputModal struct {
|
||||
id string
|
||||
title string
|
||||
text string
|
||||
input *InputField
|
||||
x, y, width, height int
|
||||
showHelp bool
|
||||
cursor int
|
||||
bg, fg termbox.Attribute
|
||||
isDone bool
|
||||
isAccepted bool
|
||||
isVisible bool
|
||||
bordered bool
|
||||
tabSkip bool
|
||||
inputSelected bool
|
||||
}
|
||||
|
||||
// CreateInputModal Create an input modal with the given attributes
|
||||
func CreateInputModal(title string, x, y, width, height int, fg, bg termbox.Attribute) *InputModal {
|
||||
i := InputModal{title: title, x: x, y: y, width: width, height: height, fg: fg, bg: bg, bordered: true}
|
||||
i.input = CreateInputField(i.x+2, i.y+3, i.width-2, 2, i.fg, i.bg)
|
||||
i.showHelp = true
|
||||
i.input.bordered = true
|
||||
i.isVisible = true
|
||||
i.inputSelected = true
|
||||
return &i
|
||||
}
|
||||
|
||||
// GetID returns this control's ID
|
||||
func (i *InputModal) GetID() string { return i.id }
|
||||
|
||||
// SetID sets this control's ID
|
||||
func (i *InputModal) SetID(newID string) {
|
||||
i.id = newID
|
||||
}
|
||||
|
||||
// GetTitle Return the title of the modal
|
||||
func (i *InputModal) GetTitle() string { return i.title }
|
||||
|
||||
// SetTitle Sets the title of the modal to s
|
||||
func (i *InputModal) SetTitle(s string) {
|
||||
i.title = s
|
||||
}
|
||||
|
||||
// GetText Return the text of the modal
|
||||
func (i *InputModal) GetText() string { return i.text }
|
||||
|
||||
// SetText Set the text of the modal to s
|
||||
func (i *InputModal) SetText(s string) {
|
||||
i.text = s
|
||||
}
|
||||
|
||||
// GetX Return the x position of the modal
|
||||
func (i *InputModal) GetX() int { return i.x }
|
||||
|
||||
// SetX set the x position of the modal to x
|
||||
func (i *InputModal) SetX(x int) {
|
||||
i.x = x
|
||||
}
|
||||
|
||||
// GetY Return the y position of the modal
|
||||
func (i *InputModal) GetY() int { return i.y }
|
||||
|
||||
// SetY Set the y position of the modal to y
|
||||
func (i *InputModal) SetY(y int) {
|
||||
i.y = y
|
||||
}
|
||||
|
||||
// GetWidth Return the width of the modal
|
||||
func (i *InputModal) GetWidth() int { return i.width }
|
||||
|
||||
// SetWidth Set the width of the modal to width
|
||||
func (i *InputModal) SetWidth(width int) {
|
||||
i.width = width
|
||||
}
|
||||
|
||||
// GetHeight Return the height of the modal
|
||||
func (i *InputModal) GetHeight() int { return i.height }
|
||||
|
||||
// SetHeight Set the height of the modal to height
|
||||
func (i *InputModal) SetHeight(height int) {
|
||||
i.height = height
|
||||
}
|
||||
|
||||
// SetMultiline returns whether this is a multiline modal
|
||||
func (i *InputModal) SetMultiline(m bool) {
|
||||
i.input.multiline = m
|
||||
}
|
||||
|
||||
// IsMultiline returns whether this is a multiline modal
|
||||
func (i *InputModal) IsMultiline() bool {
|
||||
return i.input.multiline
|
||||
}
|
||||
|
||||
// IsBordered returns whether this control is bordered or not
|
||||
func (i *InputModal) IsBordered() bool {
|
||||
return i.bordered
|
||||
}
|
||||
|
||||
// SetBordered sets whether we render a border around the frame
|
||||
func (i *InputModal) SetBordered(b bool) {
|
||||
i.bordered = b
|
||||
}
|
||||
|
||||
// IsTabSkipped returns whether this control has it's tabskip flag set
|
||||
func (i *InputModal) IsTabSkipped() bool {
|
||||
return i.tabSkip
|
||||
}
|
||||
|
||||
// SetTabSkip sets the tabskip flag for this control
|
||||
func (i *InputModal) SetTabSkip(b bool) {
|
||||
i.tabSkip = b
|
||||
}
|
||||
|
||||
// HelpIsShown Returns whether the modal is showing it's help text or not
|
||||
func (i *InputModal) HelpIsShown() bool { return i.showHelp }
|
||||
|
||||
// ShowHelp Set the "Show Help" flag
|
||||
func (i *InputModal) ShowHelp(b bool) {
|
||||
i.showHelp = b
|
||||
}
|
||||
|
||||
// GetFgColor returns the foreground color
|
||||
func (i *InputModal) GetFgColor() termbox.Attribute { return i.fg }
|
||||
|
||||
// SetFgColor sets the foreground color
|
||||
func (i *InputModal) SetFgColor(fg termbox.Attribute) {
|
||||
i.fg = fg
|
||||
}
|
||||
|
||||
// GetBgColor returns the background color
|
||||
func (i *InputModal) GetBgColor() termbox.Attribute { return i.bg }
|
||||
|
||||
// SetBgColor sets the current background color
|
||||
func (i *InputModal) SetBgColor(bg termbox.Attribute) {
|
||||
i.bg = bg
|
||||
}
|
||||
|
||||
// Show Sets the visibility flag to true
|
||||
func (i *InputModal) Show() {
|
||||
i.isVisible = true
|
||||
}
|
||||
|
||||
// Hide Sets the visibility flag to false
|
||||
func (i *InputModal) Hide() {
|
||||
i.isVisible = false
|
||||
}
|
||||
|
||||
// IsVisible returns the isVisible flag
|
||||
func (i *InputModal) IsVisible() bool {
|
||||
return i.isVisible
|
||||
}
|
||||
|
||||
// SetDone Sets the flag that tells whether this modal has completed it's purpose
|
||||
func (i *InputModal) SetDone(b bool) {
|
||||
i.isDone = b
|
||||
}
|
||||
|
||||
// IsDone Returns the "isDone" flag
|
||||
func (i *InputModal) IsDone() bool {
|
||||
return i.isDone
|
||||
}
|
||||
|
||||
// IsAccepted Returns whether the modal has been accepted
|
||||
func (i *InputModal) IsAccepted() bool {
|
||||
return i.isAccepted
|
||||
}
|
||||
|
||||
// GetValue Return the current value of the input
|
||||
func (i *InputModal) GetValue() string { return i.input.GetValue() }
|
||||
|
||||
// SetValue Sets the value of the input to s
|
||||
func (i *InputModal) SetValue(s string) {
|
||||
i.input.SetValue(s)
|
||||
}
|
||||
|
||||
// SetInputWrap sets whether the input field will wrap long text or not
|
||||
func (i *InputModal) SetInputWrap(b bool) {
|
||||
i.input.SetWrap(b)
|
||||
}
|
||||
|
||||
// Clear Resets all non-positional parameters of the modal
|
||||
func (i *InputModal) Clear() {
|
||||
i.title = ""
|
||||
i.text = ""
|
||||
i.input.SetValue("")
|
||||
i.isDone = false
|
||||
i.isVisible = false
|
||||
}
|
||||
|
||||
// HandleEvent Handle the termbox event, return true if it was consumed
|
||||
func (i *InputModal) HandleEvent(event termbox.Event) bool {
|
||||
if event.Key == termbox.KeyEnter {
|
||||
if !i.input.IsMultiline() || !i.inputSelected {
|
||||
// Done editing
|
||||
i.isDone = true
|
||||
i.isAccepted = true
|
||||
} else {
|
||||
i.input.HandleEvent(event)
|
||||
}
|
||||
return true
|
||||
} else if event.Key == termbox.KeyTab {
|
||||
if i.input.IsMultiline() {
|
||||
i.inputSelected = !i.inputSelected
|
||||
}
|
||||
} else if event.Key == termbox.KeyEsc {
|
||||
// Done editing
|
||||
i.isDone = true
|
||||
i.isAccepted = false
|
||||
return true
|
||||
}
|
||||
return i.input.HandleEvent(event)
|
||||
}
|
||||
|
||||
// Draw Draw the modal
|
||||
func (i *InputModal) Draw() {
|
||||
if i.isVisible {
|
||||
// First blank out the area we'll be putting the modal
|
||||
FillWithChar(' ', i.x, i.y, i.x+i.width, i.y+i.height, i.fg, i.bg)
|
||||
nextY := i.y + 1
|
||||
// The title
|
||||
if i.title != "" {
|
||||
if len(i.title) > i.width {
|
||||
diff := i.width - len(i.title)
|
||||
DrawStringAtPoint(i.title[:len(i.title)+diff-1], i.x+1, nextY, i.fg, i.bg)
|
||||
} else {
|
||||
DrawStringAtPoint(i.title, i.x+1, nextY, i.fg, i.bg)
|
||||
}
|
||||
nextY++
|
||||
FillWithChar('-', i.x+1, nextY, i.x+i.width-1, nextY, i.fg, i.bg)
|
||||
nextY++
|
||||
}
|
||||
if i.text != "" {
|
||||
DrawStringAtPoint(i.text, i.x+1, nextY, i.fg, i.bg)
|
||||
nextY++
|
||||
}
|
||||
i.input.SetY(nextY)
|
||||
i.input.Draw()
|
||||
nextY += 3
|
||||
if i.showHelp {
|
||||
helpString := " (ENTER) to Accept. (ESC) to Cancel. "
|
||||
helpX := (i.x + i.width - len(helpString)) - 1
|
||||
DrawStringAtPoint(helpString, helpX, nextY, i.fg, i.bg)
|
||||
}
|
||||
if i.bordered {
|
||||
// Now draw the border
|
||||
DrawBorder(i.x, i.y, i.x+i.width, i.y+i.height, i.fg, i.bg)
|
||||
}
|
||||
}
|
||||
}
|
140
vendor/github.com/br0xen/termbox-util/termbox_label.go
generated
vendored
Normal file
140
vendor/github.com/br0xen/termbox-util/termbox_label.go
generated
vendored
Normal file
@@ -0,0 +1,140 @@
|
||||
package termboxUtil
|
||||
|
||||
import "github.com/nsf/termbox-go"
|
||||
|
||||
// Label is a field for inputting text
|
||||
type Label struct {
|
||||
id string
|
||||
value string
|
||||
x, y, width, height int
|
||||
cursor int
|
||||
fg, bg termbox.Attribute
|
||||
bordered bool
|
||||
wrap bool
|
||||
multiline bool
|
||||
}
|
||||
|
||||
// CreateLabel creates an input field at x, y that is w by h
|
||||
func CreateLabel(lbl string, x, y, w, h int, fg, bg termbox.Attribute) *Label {
|
||||
i := Label{value: lbl, x: x, y: y, width: w, height: h, fg: fg, bg: bg}
|
||||
return &i
|
||||
}
|
||||
|
||||
// GetID returns this control's ID
|
||||
func (i *Label) GetID() string { return i.id }
|
||||
|
||||
// SetID sets this control's ID
|
||||
func (i *Label) SetID(newID string) {
|
||||
i.id = newID
|
||||
}
|
||||
|
||||
// GetValue gets the current text that is in the Label
|
||||
func (i *Label) GetValue() string { return i.value }
|
||||
|
||||
// SetValue sets the current text in the Label to s
|
||||
func (i *Label) SetValue(s string) {
|
||||
i.value = s
|
||||
}
|
||||
|
||||
// GetX returns the x position of the input field
|
||||
func (i *Label) GetX() int { return i.x }
|
||||
|
||||
// SetX sets the x position of the input field
|
||||
func (i *Label) SetX(x int) {
|
||||
i.x = x
|
||||
}
|
||||
|
||||
// GetY returns the y position of the input field
|
||||
func (i *Label) GetY() int { return i.y }
|
||||
|
||||
// SetY sets the y position of the input field
|
||||
func (i *Label) SetY(y int) {
|
||||
i.y = y
|
||||
}
|
||||
|
||||
// GetWidth returns the current width of the input field
|
||||
func (i *Label) GetWidth() int {
|
||||
if i.width == -1 {
|
||||
if i.bordered {
|
||||
return len(i.value) + 2
|
||||
}
|
||||
return len(i.value)
|
||||
}
|
||||
return i.width
|
||||
}
|
||||
|
||||
// SetWidth sets the current width of the input field
|
||||
func (i *Label) SetWidth(w int) {
|
||||
i.width = w
|
||||
}
|
||||
|
||||
// GetHeight returns the current height of the input field
|
||||
func (i *Label) GetHeight() int { return i.height }
|
||||
|
||||
// SetHeight sets the current height of the input field
|
||||
func (i *Label) SetHeight(h int) {
|
||||
i.height = h
|
||||
}
|
||||
|
||||
// GetFgColor returns the foreground color
|
||||
func (i *Label) GetFgColor() termbox.Attribute { return i.fg }
|
||||
|
||||
// SetFgColor sets the foreground color
|
||||
func (i *Label) SetFgColor(fg termbox.Attribute) {
|
||||
i.fg = fg
|
||||
}
|
||||
|
||||
// GetBgColor returns the background color
|
||||
func (i *Label) GetBgColor() termbox.Attribute { return i.bg }
|
||||
|
||||
// SetBgColor sets the current background color
|
||||
func (i *Label) SetBgColor(bg termbox.Attribute) {
|
||||
i.bg = bg
|
||||
}
|
||||
|
||||
// IsBordered returns true or false if this input field has a border
|
||||
func (i *Label) IsBordered() bool { return i.bordered }
|
||||
|
||||
// SetBordered sets whether we render a border around the input field
|
||||
func (i *Label) SetBordered(b bool) {
|
||||
i.bordered = b
|
||||
}
|
||||
|
||||
// DoesWrap returns true or false if this input field wraps text
|
||||
func (i *Label) DoesWrap() bool { return i.wrap }
|
||||
|
||||
// SetWrap sets whether we wrap the text at width.
|
||||
func (i *Label) SetWrap(b bool) {
|
||||
i.wrap = b
|
||||
}
|
||||
|
||||
// IsMultiline returns true or false if this field can have multiple lines
|
||||
func (i *Label) IsMultiline() bool { return i.multiline }
|
||||
|
||||
// SetMultiline sets whether the field can have multiple lines
|
||||
func (i *Label) SetMultiline(b bool) {
|
||||
i.multiline = b
|
||||
}
|
||||
|
||||
// HandleEvent accepts the termbox event and returns whether it was consumed
|
||||
func (i *Label) HandleEvent(event termbox.Event) bool { return false }
|
||||
|
||||
// Draw outputs the input field on the screen
|
||||
func (i *Label) Draw() {
|
||||
maxWidth := i.width
|
||||
maxHeight := i.height
|
||||
x, y := i.x, i.y
|
||||
startX := i.x
|
||||
startY := i.y
|
||||
if i.bordered {
|
||||
DrawBorder(i.x, i.y, i.x+i.GetWidth(), i.y+i.height, i.fg, i.bg)
|
||||
maxWidth--
|
||||
maxHeight--
|
||||
x++
|
||||
y++
|
||||
startX++
|
||||
startY++
|
||||
}
|
||||
|
||||
DrawStringAtPoint(i.value, x, y, i.fg, i.bg)
|
||||
}
|
478
vendor/github.com/br0xen/termbox-util/termbox_menu.go
generated
vendored
Normal file
478
vendor/github.com/br0xen/termbox-util/termbox_menu.go
generated
vendored
Normal file
@@ -0,0 +1,478 @@
|
||||
package termboxUtil
|
||||
|
||||
import "github.com/nsf/termbox-go"
|
||||
|
||||
// Menu is a menu with a list of options
|
||||
type Menu struct {
|
||||
id string
|
||||
title string
|
||||
options []MenuOption
|
||||
// If height is -1, then it is adaptive to the menu
|
||||
x, y, width, height int
|
||||
showHelp bool
|
||||
cursor int
|
||||
bg, fg termbox.Attribute
|
||||
selectedBg, selectedFg termbox.Attribute
|
||||
disabledBg, disabledFg termbox.Attribute
|
||||
isDone bool
|
||||
bordered bool
|
||||
vimMode bool
|
||||
tabSkip bool
|
||||
}
|
||||
|
||||
// CreateMenu Creates a menu with the specified attributes
|
||||
func CreateMenu(title string, options []string, x, y, width, height int, fg, bg termbox.Attribute) *Menu {
|
||||
i := Menu{
|
||||
title: title,
|
||||
x: x, y: y, width: width, height: height,
|
||||
fg: fg, bg: bg, selectedFg: bg, selectedBg: fg,
|
||||
disabledFg: bg, disabledBg: bg,
|
||||
}
|
||||
for _, line := range options {
|
||||
i.options = append(i.options, MenuOption{text: line})
|
||||
}
|
||||
if len(i.options) > 0 {
|
||||
i.SetSelectedOption(&i.options[0])
|
||||
}
|
||||
return &i
|
||||
}
|
||||
|
||||
// GetID returns this control's ID
|
||||
func (i *Menu) GetID() string { return i.id }
|
||||
|
||||
// SetID sets this control's ID
|
||||
func (i *Menu) SetID(newID string) {
|
||||
i.id = newID
|
||||
}
|
||||
|
||||
// GetTitle returns the current title of the menu
|
||||
func (i *Menu) GetTitle() string { return i.title }
|
||||
|
||||
// SetTitle sets the current title of the menu to s
|
||||
func (i *Menu) SetTitle(s string) {
|
||||
i.title = s
|
||||
}
|
||||
|
||||
// GetOptions returns the current options of the menu
|
||||
func (i *Menu) GetOptions() []MenuOption {
|
||||
return i.options
|
||||
}
|
||||
|
||||
// SetOptions set the menu's options to opts
|
||||
func (i *Menu) SetOptions(opts []MenuOption) {
|
||||
i.options = opts
|
||||
}
|
||||
|
||||
// SetOptionsFromStrings sets the options of this menu from a slice of strings
|
||||
func (i *Menu) SetOptionsFromStrings(opts []string) {
|
||||
var newOpts []MenuOption
|
||||
for _, v := range opts {
|
||||
newOpts = append(newOpts, *CreateOptionFromText(v))
|
||||
}
|
||||
i.SetOptions(newOpts)
|
||||
i.SetSelectedOption(i.GetOptionFromIndex(0))
|
||||
}
|
||||
|
||||
// GetX returns the current x coordinate of the menu
|
||||
func (i *Menu) GetX() int { return i.x }
|
||||
|
||||
// SetX sets the current x coordinate of the menu to x
|
||||
func (i *Menu) SetX(x int) {
|
||||
i.x = x
|
||||
}
|
||||
|
||||
// GetY returns the current y coordinate of the menu
|
||||
func (i *Menu) GetY() int { return i.y }
|
||||
|
||||
// SetY sets the current y coordinate of the menu to y
|
||||
func (i *Menu) SetY(y int) {
|
||||
i.y = y
|
||||
}
|
||||
|
||||
// GetWidth returns the current width of the menu
|
||||
func (i *Menu) GetWidth() int { return i.width }
|
||||
|
||||
// SetWidth sets the current menu width to width
|
||||
func (i *Menu) SetWidth(width int) {
|
||||
i.width = width
|
||||
}
|
||||
|
||||
// GetHeight returns the current height of the menu
|
||||
func (i *Menu) GetHeight() int { return i.height }
|
||||
|
||||
// SetHeight set the height of the menu to height
|
||||
func (i *Menu) SetHeight(height int) {
|
||||
i.height = height
|
||||
}
|
||||
|
||||
// GetSelectedOption returns the current selected option
|
||||
func (i *Menu) GetSelectedOption() *MenuOption {
|
||||
idx := i.GetSelectedIndex()
|
||||
if idx != -1 {
|
||||
return &i.options[idx]
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetOptionFromIndex Returns the
|
||||
func (i *Menu) GetOptionFromIndex(idx int) *MenuOption {
|
||||
if idx >= 0 && idx < len(i.options) {
|
||||
return &i.options[idx]
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetOptionFromText Returns the first option with the text v
|
||||
func (i *Menu) GetOptionFromText(v string) *MenuOption {
|
||||
for idx := range i.options {
|
||||
testOption := &i.options[idx]
|
||||
if testOption.GetText() == v {
|
||||
return testOption
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetSelectedIndex returns the index of the selected option
|
||||
// Returns -1 if nothing is selected
|
||||
func (i *Menu) GetSelectedIndex() int {
|
||||
for idx := range i.options {
|
||||
if i.options[idx].IsSelected() {
|
||||
return idx
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
// SetSelectedIndex sets the selection to setIdx
|
||||
func (i *Menu) SetSelectedIndex(idx int) {
|
||||
if len(i.options) > 0 {
|
||||
if idx < 0 {
|
||||
idx = 0
|
||||
} else if idx >= len(i.options) {
|
||||
idx = len(i.options) - 1
|
||||
}
|
||||
i.SetSelectedOption(&i.options[idx])
|
||||
}
|
||||
}
|
||||
|
||||
// SetSelectedOption sets the current selected option to v (if it's valid)
|
||||
func (i *Menu) SetSelectedOption(v *MenuOption) {
|
||||
for idx := range i.options {
|
||||
if &i.options[idx] == v {
|
||||
i.options[idx].Select()
|
||||
} else {
|
||||
i.options[idx].Unselect()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// SelectPrevOption Decrements the selected option (if it can)
|
||||
func (i *Menu) SelectPrevOption() {
|
||||
idx := i.GetSelectedIndex()
|
||||
for idx >= 0 {
|
||||
idx--
|
||||
testOption := i.GetOptionFromIndex(idx)
|
||||
if testOption != nil && !testOption.IsDisabled() {
|
||||
i.SetSelectedOption(testOption)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// SelectNextOption Increments the selected option (if it can)
|
||||
func (i *Menu) SelectNextOption() {
|
||||
idx := i.GetSelectedIndex()
|
||||
for idx < len(i.options) {
|
||||
idx++
|
||||
testOption := i.GetOptionFromIndex(idx)
|
||||
if testOption != nil && !testOption.IsDisabled() {
|
||||
i.SetSelectedOption(testOption)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// SelectPageUpOption Goes up 'menu height' options
|
||||
func (i *Menu) SelectPageUpOption() {
|
||||
idx := i.GetSelectedIndex()
|
||||
idx -= i.height
|
||||
if idx < 0 {
|
||||
idx = 0
|
||||
}
|
||||
i.SetSelectedIndex(idx)
|
||||
return
|
||||
}
|
||||
|
||||
// SelectPageDownOption Goes down 'menu height' options
|
||||
func (i *Menu) SelectPageDownOption() {
|
||||
idx := i.GetSelectedIndex()
|
||||
idx += i.height
|
||||
if idx >= len(i.options) {
|
||||
idx = len(i.options) - 1
|
||||
}
|
||||
i.SetSelectedIndex(idx)
|
||||
return
|
||||
}
|
||||
|
||||
// SelectFirstOption Goes to the top
|
||||
func (i *Menu) SelectFirstOption() {
|
||||
i.SetSelectedIndex(0)
|
||||
return
|
||||
}
|
||||
|
||||
// SelectLastOption Goes to the bottom
|
||||
func (i *Menu) SelectLastOption() {
|
||||
i.SetSelectedIndex(len(i.options) - 1)
|
||||
return
|
||||
}
|
||||
|
||||
// SetOptionDisabled Disables the specified option
|
||||
func (i *Menu) SetOptionDisabled(idx int) {
|
||||
if len(i.options) > idx {
|
||||
i.GetOptionFromIndex(idx).Disable()
|
||||
}
|
||||
}
|
||||
|
||||
// SetOptionEnabled Enables the specified option
|
||||
func (i *Menu) SetOptionEnabled(idx int) {
|
||||
if len(i.options) > idx {
|
||||
i.GetOptionFromIndex(idx).Enable()
|
||||
}
|
||||
}
|
||||
|
||||
// HelpIsShown returns true or false if the help is displayed
|
||||
func (i *Menu) HelpIsShown() bool { return i.showHelp }
|
||||
|
||||
// ShowHelp sets whether or not to display the help text
|
||||
func (i *Menu) ShowHelp(b bool) {
|
||||
i.showHelp = b
|
||||
}
|
||||
|
||||
// GetFgColor returns the foreground color
|
||||
func (i *Menu) GetFgColor() termbox.Attribute { return i.fg }
|
||||
|
||||
// SetFgColor sets the foreground color
|
||||
func (i *Menu) SetFgColor(fg termbox.Attribute) {
|
||||
i.fg = fg
|
||||
}
|
||||
|
||||
// GetBgColor returns the background color
|
||||
func (i *Menu) GetBgColor() termbox.Attribute { return i.bg }
|
||||
|
||||
// SetBgColor sets the current background color
|
||||
func (i *Menu) SetBgColor(bg termbox.Attribute) {
|
||||
i.bg = bg
|
||||
}
|
||||
|
||||
// IsDone returns whether the user has answered the modal
|
||||
func (i *Menu) IsDone() bool { return i.isDone }
|
||||
|
||||
// SetDone sets whether the modal has completed it's purpose
|
||||
func (i *Menu) SetDone(b bool) {
|
||||
i.isDone = b
|
||||
}
|
||||
|
||||
// IsBordered returns true or false if this menu has a border
|
||||
func (i *Menu) IsBordered() bool { return i.bordered }
|
||||
|
||||
// SetBordered sets whether we render a border around the menu
|
||||
func (i *Menu) SetBordered(b bool) {
|
||||
i.bordered = b
|
||||
}
|
||||
|
||||
// EnableVimMode Enables h,j,k,l navigation
|
||||
func (i *Menu) EnableVimMode() {
|
||||
i.vimMode = true
|
||||
}
|
||||
|
||||
// DisableVimMode Disables h,j,k,l navigation
|
||||
func (i *Menu) DisableVimMode() {
|
||||
i.vimMode = false
|
||||
}
|
||||
|
||||
// HandleEvent handles the termbox event and returns whether it was consumed
|
||||
func (i *Menu) HandleEvent(event termbox.Event) bool {
|
||||
if event.Key == termbox.KeyEnter || event.Key == termbox.KeySpace {
|
||||
i.isDone = true
|
||||
return true
|
||||
}
|
||||
currentIdx := i.GetSelectedIndex()
|
||||
switch event.Key {
|
||||
case termbox.KeyArrowUp:
|
||||
i.SelectPrevOption()
|
||||
case termbox.KeyArrowDown:
|
||||
i.SelectNextOption()
|
||||
case termbox.KeyArrowLeft:
|
||||
i.SelectPageUpOption()
|
||||
case termbox.KeyArrowRight:
|
||||
i.SelectPageDownOption()
|
||||
}
|
||||
if i.vimMode {
|
||||
switch event.Ch {
|
||||
case 'j':
|
||||
i.SelectNextOption()
|
||||
case 'k':
|
||||
i.SelectPrevOption()
|
||||
}
|
||||
if event.Key == termbox.KeyCtrlF {
|
||||
i.SelectPageDownOption()
|
||||
} else if event.Key == termbox.KeyCtrlB {
|
||||
i.SelectPageUpOption()
|
||||
}
|
||||
}
|
||||
if i.GetSelectedIndex() != currentIdx {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Draw draws the modal
|
||||
func (i *Menu) Draw() {
|
||||
// First blank out the area we'll be putting the menu
|
||||
FillWithChar(' ', i.x, i.y, i.x+i.width, i.y+i.height, i.fg, i.bg)
|
||||
// Now draw the border
|
||||
optionStartX := i.x
|
||||
optionStartY := i.y
|
||||
optionWidth := i.width
|
||||
optionHeight := i.height
|
||||
if optionHeight == -1 {
|
||||
optionHeight = len(i.options)
|
||||
}
|
||||
if i.bordered {
|
||||
if i.height == -1 {
|
||||
DrawBorder(i.x, i.y, i.x+i.width, i.y+optionHeight+1, i.fg, i.bg)
|
||||
} else {
|
||||
DrawBorder(i.x, i.y, i.x+i.width, i.y+optionHeight, i.fg, i.bg)
|
||||
}
|
||||
optionStartX = i.x + 1
|
||||
optionStartY = i.y + 1
|
||||
optionWidth = i.width - 1
|
||||
optionHeight -= 2
|
||||
}
|
||||
|
||||
// The title
|
||||
if i.title != "" {
|
||||
DrawStringAtPoint(AlignText(i.title, optionWidth, AlignCenter), optionStartX, optionStartY, i.fg, i.bg)
|
||||
optionStartY++
|
||||
if i.bordered {
|
||||
FillWithChar('-', optionStartX, optionStartY, optionWidth, optionStartY, i.fg, i.bg)
|
||||
optionStartY++
|
||||
optionHeight--
|
||||
}
|
||||
optionHeight--
|
||||
}
|
||||
|
||||
if len(i.options) > 0 {
|
||||
// If the currently selected option is disabled, move to the next
|
||||
if i.GetSelectedOption().IsDisabled() {
|
||||
i.SelectNextOption()
|
||||
}
|
||||
|
||||
// Print the options
|
||||
bldHeight := (optionHeight / 2)
|
||||
startIdx := i.GetSelectedIndex()
|
||||
endIdx := i.GetSelectedIndex()
|
||||
for bldHeight > 0 && startIdx >= 1 {
|
||||
startIdx--
|
||||
bldHeight--
|
||||
}
|
||||
bldHeight += (optionHeight / 2)
|
||||
for bldHeight > 0 && endIdx < len(i.options) {
|
||||
endIdx++
|
||||
bldHeight--
|
||||
}
|
||||
|
||||
for idx := startIdx; idx < endIdx; idx++ { //i.options {
|
||||
if i.GetSelectedIndex()-idx >= optionHeight-1 {
|
||||
// Skip this one
|
||||
continue
|
||||
}
|
||||
currOpt := &i.options[idx]
|
||||
outTxt := currOpt.GetText()
|
||||
if len(outTxt) >= i.width {
|
||||
outTxt = outTxt[:i.width]
|
||||
}
|
||||
if currOpt.IsDisabled() {
|
||||
DrawStringAtPoint(outTxt, optionStartX, optionStartY, i.disabledFg, i.disabledBg)
|
||||
} else if i.GetSelectedOption() == currOpt {
|
||||
DrawStringAtPoint(outTxt, optionStartX, optionStartY, i.selectedFg, i.selectedBg)
|
||||
} else {
|
||||
DrawStringAtPoint(outTxt, optionStartX, optionStartY, i.fg, i.bg)
|
||||
}
|
||||
optionStartY++
|
||||
if optionStartY > i.y+optionHeight-1 {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* MenuOption Struct & methods */
|
||||
|
||||
// MenuOption An option in the menu
|
||||
type MenuOption struct {
|
||||
id string
|
||||
text string
|
||||
selected bool
|
||||
disabled bool
|
||||
helpText string
|
||||
subMenu []MenuOption
|
||||
}
|
||||
|
||||
// CreateOptionFromText just returns a MenuOption object
|
||||
// That only has it's text value set.
|
||||
func CreateOptionFromText(s string) *MenuOption {
|
||||
return &MenuOption{text: s}
|
||||
}
|
||||
|
||||
// SetText Sets the text for this option
|
||||
func (i *MenuOption) SetText(s string) {
|
||||
i.text = s
|
||||
}
|
||||
|
||||
// GetText Returns the text for this option
|
||||
func (i *MenuOption) GetText() string { return i.text }
|
||||
|
||||
// Disable Sets this option to disabled
|
||||
func (i *MenuOption) Disable() {
|
||||
i.disabled = true
|
||||
}
|
||||
|
||||
// Enable Sets this option to enabled
|
||||
func (i *MenuOption) Enable() {
|
||||
i.disabled = false
|
||||
}
|
||||
|
||||
// IsDisabled returns whether this option is enabled
|
||||
func (i *MenuOption) IsDisabled() bool {
|
||||
return i.disabled
|
||||
}
|
||||
|
||||
// IsSelected Returns whether this option is selected
|
||||
func (i *MenuOption) IsSelected() bool {
|
||||
return i.selected
|
||||
}
|
||||
|
||||
// Select Sets this option to selected
|
||||
func (i *MenuOption) Select() {
|
||||
i.selected = true
|
||||
}
|
||||
|
||||
// Unselect Sets this option to not selected
|
||||
func (i *MenuOption) Unselect() {
|
||||
i.selected = false
|
||||
}
|
||||
|
||||
// SetHelpText Sets this option's help text to s
|
||||
func (i *MenuOption) SetHelpText(s string) {
|
||||
i.helpText = s
|
||||
}
|
||||
|
||||
// GetHelpText Returns the help text for this option
|
||||
func (i *MenuOption) GetHelpText() string { return i.helpText }
|
||||
|
||||
// AddToSubMenu adds a slice of MenuOptions to this option
|
||||
func (i *MenuOption) AddToSubMenu(sub *MenuOption) {
|
||||
i.subMenu = append(i.subMenu, *sub)
|
||||
}
|
237
vendor/github.com/br0xen/termbox-util/termbox_progressbar.go
generated
vendored
Normal file
237
vendor/github.com/br0xen/termbox-util/termbox_progressbar.go
generated
vendored
Normal file
@@ -0,0 +1,237 @@
|
||||
package termboxUtil
|
||||
|
||||
import "github.com/nsf/termbox-go"
|
||||
|
||||
// ProgressBar Just contains the data needed to display a progress bar
|
||||
type ProgressBar struct {
|
||||
id string
|
||||
total int
|
||||
progress int
|
||||
allowOverflow bool
|
||||
allowUnderflow bool
|
||||
fullChar rune
|
||||
emptyChar rune
|
||||
bordered bool
|
||||
alignment TextAlignment
|
||||
colorized bool
|
||||
|
||||
x, y int
|
||||
width, height int
|
||||
bg, fg termbox.Attribute
|
||||
}
|
||||
|
||||
// CreateProgressBar Create a progress bar object
|
||||
func CreateProgressBar(tot, x, y int, fg, bg termbox.Attribute) *ProgressBar {
|
||||
i := ProgressBar{total: tot,
|
||||
fullChar: '#', emptyChar: ' ',
|
||||
x: x, y: y, height: 1, width: 10,
|
||||
bordered: true, fg: fg, bg: bg,
|
||||
alignment: AlignLeft,
|
||||
}
|
||||
return &i
|
||||
}
|
||||
|
||||
// GetID returns this control's ID
|
||||
func (i *ProgressBar) GetID() string { return i.id }
|
||||
|
||||
// SetID sets this control's ID
|
||||
func (i *ProgressBar) SetID(newID string) {
|
||||
i.id = newID
|
||||
}
|
||||
|
||||
// GetProgress returns the curret progress value
|
||||
func (i *ProgressBar) GetProgress() int {
|
||||
return i.progress
|
||||
}
|
||||
|
||||
// SetProgress sets the current progress of the bar
|
||||
func (i *ProgressBar) SetProgress(p int) {
|
||||
if (p <= i.total || i.allowOverflow) || (p >= 0 || i.allowUnderflow) {
|
||||
i.progress = p
|
||||
}
|
||||
}
|
||||
|
||||
// IncrProgress increments the current progress of the bar
|
||||
func (i *ProgressBar) IncrProgress() {
|
||||
if i.progress < i.total || i.allowOverflow {
|
||||
i.progress++
|
||||
}
|
||||
}
|
||||
|
||||
// DecrProgress decrements the current progress of the bar
|
||||
func (i *ProgressBar) DecrProgress() {
|
||||
if i.progress > 0 || i.allowUnderflow {
|
||||
i.progress--
|
||||
}
|
||||
}
|
||||
|
||||
// GetPercent returns the percent full of the bar
|
||||
func (i *ProgressBar) GetPercent() int {
|
||||
return int(float64(i.progress) / float64(i.total) * 100)
|
||||
}
|
||||
|
||||
// EnableOverflow Tells the progress bar that it can go over the total
|
||||
func (i *ProgressBar) EnableOverflow() {
|
||||
i.allowOverflow = true
|
||||
}
|
||||
|
||||
// DisableOverflow Tells the progress bar that it can NOT go over the total
|
||||
func (i *ProgressBar) DisableOverflow() {
|
||||
i.allowOverflow = false
|
||||
}
|
||||
|
||||
// EnableUnderflow Tells the progress bar that it can go below zero
|
||||
func (i *ProgressBar) EnableUnderflow() {
|
||||
i.allowUnderflow = true
|
||||
}
|
||||
|
||||
// DisableUnderflow Tells the progress bar that it can NOT go below zero
|
||||
func (i *ProgressBar) DisableUnderflow() {
|
||||
i.allowUnderflow = false
|
||||
}
|
||||
|
||||
// GetFullChar returns the rune used for 'full'
|
||||
func (i *ProgressBar) GetFullChar() rune {
|
||||
return i.fullChar
|
||||
}
|
||||
|
||||
// SetFullChar sets the rune used for 'full'
|
||||
func (i *ProgressBar) SetFullChar(f rune) {
|
||||
i.fullChar = f
|
||||
}
|
||||
|
||||
// GetEmptyChar gets the rune used for 'empty'
|
||||
func (i *ProgressBar) GetEmptyChar() rune {
|
||||
return i.emptyChar
|
||||
}
|
||||
|
||||
// SetEmptyChar sets the rune used for 'empty'
|
||||
func (i *ProgressBar) SetEmptyChar(f rune) {
|
||||
i.emptyChar = f
|
||||
}
|
||||
|
||||
// GetX Return the x position of the Progress Bar
|
||||
func (i *ProgressBar) GetX() int { return i.x }
|
||||
|
||||
// SetX set the x position of the ProgressBar to x
|
||||
func (i *ProgressBar) SetX(x int) {
|
||||
i.x = x
|
||||
}
|
||||
|
||||
// GetY Return the y position of the ProgressBar
|
||||
func (i *ProgressBar) GetY() int { return i.y }
|
||||
|
||||
// SetY Set the y position of the ProgressBar to y
|
||||
func (i *ProgressBar) SetY(y int) {
|
||||
i.y = y
|
||||
}
|
||||
|
||||
// GetHeight returns the height of the progress bar
|
||||
// Defaults to 1 (3 if bordered)
|
||||
func (i *ProgressBar) GetHeight() int {
|
||||
return i.height
|
||||
}
|
||||
|
||||
// SetHeight Sets the height of the progress bar
|
||||
func (i *ProgressBar) SetHeight(h int) {
|
||||
i.height = h
|
||||
}
|
||||
|
||||
// GetWidth returns the width of the progress bar
|
||||
func (i *ProgressBar) GetWidth() int {
|
||||
return i.width
|
||||
}
|
||||
|
||||
// SetWidth Sets the width of the progress bar
|
||||
func (i *ProgressBar) SetWidth(w int) {
|
||||
i.width = w
|
||||
}
|
||||
|
||||
// GetFgColor returns the foreground color
|
||||
func (i *ProgressBar) GetFgColor() termbox.Attribute { return i.fg }
|
||||
|
||||
// SetFgColor sets the foreground color
|
||||
func (i *ProgressBar) SetFgColor(fg termbox.Attribute) {
|
||||
i.fg = fg
|
||||
}
|
||||
|
||||
// GetBgColor returns the background color
|
||||
func (i *ProgressBar) GetBgColor() termbox.Attribute { return i.bg }
|
||||
|
||||
// SetBgColor sets the current background color
|
||||
func (i *ProgressBar) SetBgColor(bg termbox.Attribute) {
|
||||
i.bg = bg
|
||||
}
|
||||
|
||||
// Align Tells which direction the progress bar empties
|
||||
func (i *ProgressBar) Align(a TextAlignment) {
|
||||
i.alignment = a
|
||||
}
|
||||
|
||||
// SetColorized sets whether the progress bar should be colored
|
||||
// depending on how full it is:
|
||||
// 10% - Red
|
||||
// 50% - Yellow
|
||||
// 80% - Green
|
||||
func (i *ProgressBar) SetColorized(c bool) {
|
||||
i.colorized = c
|
||||
}
|
||||
|
||||
// HandleEvent accepts the termbox event and returns whether it was consumed
|
||||
func (i *ProgressBar) HandleEvent(event termbox.Event) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// Draw outputs the input field on the screen
|
||||
func (i *ProgressBar) Draw() {
|
||||
// For now, just draw a [#### ] bar
|
||||
// TODO: make this more advanced
|
||||
useFg := i.fg
|
||||
if i.colorized {
|
||||
if i.GetPercent() < 10 {
|
||||
useFg = termbox.ColorRed
|
||||
} else if i.GetPercent() < 50 {
|
||||
useFg = termbox.ColorYellow
|
||||
} else {
|
||||
useFg = termbox.ColorGreen
|
||||
}
|
||||
}
|
||||
drawX, drawY := i.x, i.y
|
||||
fillWidth, fillHeight := i.width-2, i.height
|
||||
DrawStringAtPoint("[", drawX, drawY, i.fg, i.bg)
|
||||
numFull := int(float64(fillWidth) * float64(i.progress) / float64(i.total))
|
||||
FillWithChar(i.fullChar, drawX+1, drawY, drawX+1+numFull, drawY+(fillHeight-1), useFg, i.bg)
|
||||
DrawStringAtPoint("]", drawX+i.width-1, drawY, i.fg, i.bg)
|
||||
|
||||
/*
|
||||
drawX, drawY := i.x, i.y
|
||||
drawWidth, drawHeight := i.width, i.height
|
||||
if i.bordered {
|
||||
if i.height == 1 && i.width > 2 {
|
||||
// Just using [ & ] for the border
|
||||
DrawStringAtPoint("[", drawX, drawY, i.fg, i.bg)
|
||||
DrawStringAtPoint("]", drawX+i.width-1, drawY, i.fg, i.bg)
|
||||
drawX++
|
||||
drawWidth -= 2
|
||||
} else if i.height >= 3 {
|
||||
DrawBorder(drawX, drawY, drawX+i.width, drawY+i.height, i.fg, i.bg)
|
||||
drawX++
|
||||
drawY++
|
||||
drawWidth -= 2
|
||||
drawHeight -= 2
|
||||
}
|
||||
}
|
||||
|
||||
// Figure out how many chars are full
|
||||
numFull := drawWidth * (i.progress / i.total)
|
||||
switch i.alignment {
|
||||
case AlignRight: // TODO: Fill from right to left
|
||||
case AlignCenter: // TODO: Fill from middle out
|
||||
default: // Fill from left to right
|
||||
FillWithChar(i.fullChar, drawX, drawY, drawX+numFull, drawY+(drawHeight-1), i.fg, i.bg)
|
||||
if numFull < drawWidth {
|
||||
FillWithChar(i.emptyChar, drawX+numFull, drawY, drawX+drawWidth-1, drawY+(drawHeight-1), i.fg, i.bg)
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
180
vendor/github.com/br0xen/termbox-util/termbox_scrollframe.go
generated
vendored
Normal file
180
vendor/github.com/br0xen/termbox-util/termbox_scrollframe.go
generated
vendored
Normal file
@@ -0,0 +1,180 @@
|
||||
package termboxUtil
|
||||
|
||||
import "github.com/nsf/termbox-go"
|
||||
|
||||
// ScrollFrame is a frame for holding other elements
|
||||
// It manages it's own x/y, tab index
|
||||
type ScrollFrame struct {
|
||||
id string
|
||||
x, y, width, height int
|
||||
scrollX, scrollY int
|
||||
tabIdx int
|
||||
fg, bg termbox.Attribute
|
||||
bordered bool
|
||||
controls []termboxControl
|
||||
}
|
||||
|
||||
// CreateScrollFrame creates Scrolling Frame at x, y that is w by h
|
||||
func CreateScrollFrame(x, y, w, h int, fg, bg termbox.Attribute) *ScrollFrame {
|
||||
s := ScrollFrame{x: x, y: y, width: w, height: h, fg: fg, bg: bg}
|
||||
return &s
|
||||
}
|
||||
|
||||
// GetID returns this control's ID
|
||||
func (i *ScrollFrame) GetID() string { return i.id }
|
||||
|
||||
// SetID sets this control's ID
|
||||
func (i *ScrollFrame) SetID(newID string) {
|
||||
i.id = newID
|
||||
}
|
||||
|
||||
// GetX returns the x position of the scroll frame
|
||||
func (i *ScrollFrame) GetX() int { return i.x }
|
||||
|
||||
// SetX sets the x position of the scroll frame
|
||||
func (i *ScrollFrame) SetX(x int) {
|
||||
i.x = x
|
||||
}
|
||||
|
||||
// GetY returns the y position of the scroll frame
|
||||
func (i *ScrollFrame) GetY() int { return i.y }
|
||||
|
||||
// SetY sets the y position of the scroll frame
|
||||
func (i *ScrollFrame) SetY(y int) {
|
||||
i.y = y
|
||||
}
|
||||
|
||||
// GetWidth returns the current width of the scroll frame
|
||||
func (i *ScrollFrame) GetWidth() int { return i.width }
|
||||
|
||||
// SetWidth sets the current width of the scroll frame
|
||||
func (i *ScrollFrame) SetWidth(w int) {
|
||||
i.width = w
|
||||
}
|
||||
|
||||
// GetHeight returns the current height of the scroll frame
|
||||
func (i *ScrollFrame) GetHeight() int { return i.height }
|
||||
|
||||
// SetHeight sets the current height of the scroll frame
|
||||
func (i *ScrollFrame) SetHeight(h int) {
|
||||
i.height = h
|
||||
}
|
||||
|
||||
// GetFgColor returns the foreground color
|
||||
func (i *ScrollFrame) GetFgColor() termbox.Attribute { return i.fg }
|
||||
|
||||
// SetFgColor sets the foreground color
|
||||
func (i *ScrollFrame) SetFgColor(fg termbox.Attribute) {
|
||||
i.fg = fg
|
||||
}
|
||||
|
||||
// GetBgColor returns the background color
|
||||
func (i *ScrollFrame) GetBgColor() termbox.Attribute { return i.bg }
|
||||
|
||||
// SetBgColor sets the current background color
|
||||
func (i *ScrollFrame) SetBgColor(bg termbox.Attribute) {
|
||||
i.bg = bg
|
||||
}
|
||||
|
||||
// IsBordered returns true or false if this scroll frame has a border
|
||||
func (i *ScrollFrame) IsBordered() bool { return i.bordered }
|
||||
|
||||
// SetBordered sets whether we render a border around the scroll frame
|
||||
func (i *ScrollFrame) SetBordered(b bool) {
|
||||
i.bordered = b
|
||||
}
|
||||
|
||||
// GetScrollX returns the x distance scrolled
|
||||
func (i *ScrollFrame) GetScrollX() int {
|
||||
return i.scrollX
|
||||
}
|
||||
|
||||
// GetScrollY returns the y distance scrolled
|
||||
func (i *ScrollFrame) GetScrollY() int {
|
||||
return i.scrollY
|
||||
}
|
||||
|
||||
// ScrollDown scrolls the frame down
|
||||
func (i *ScrollFrame) ScrollDown() {
|
||||
i.scrollY++
|
||||
}
|
||||
|
||||
// ScrollUp scrolls the frame up
|
||||
func (i *ScrollFrame) ScrollUp() {
|
||||
if i.scrollY > 0 {
|
||||
i.scrollY--
|
||||
}
|
||||
}
|
||||
|
||||
// ScrollLeft scrolls the frame left
|
||||
func (i *ScrollFrame) ScrollLeft() {
|
||||
if i.scrollX > 0 {
|
||||
i.scrollX--
|
||||
}
|
||||
}
|
||||
|
||||
// ScrollRight scrolls the frame right
|
||||
func (i *ScrollFrame) ScrollRight() {
|
||||
i.scrollX++
|
||||
}
|
||||
|
||||
// AddControl adds a control to the frame
|
||||
func (i *ScrollFrame) AddControl(t termboxControl) {
|
||||
i.controls = append(i.controls, t)
|
||||
}
|
||||
|
||||
// DrawControl figures out the relative position of the control,
|
||||
// sets it, draws it, then resets it.
|
||||
func (i *ScrollFrame) DrawControl(t termboxControl) {
|
||||
if i.IsVisible(t) {
|
||||
ctlX, ctlY := t.GetX(), t.GetY()
|
||||
t.SetX((i.GetX() + ctlX))
|
||||
t.SetY((i.GetY() + ctlY))
|
||||
t.Draw()
|
||||
t.SetX(ctlX)
|
||||
t.SetY(ctlY)
|
||||
}
|
||||
}
|
||||
|
||||
// IsVisible takes a Termbox Control and returns whether
|
||||
// that control would be visible in the frame
|
||||
func (i *ScrollFrame) IsVisible(t termboxControl) bool {
|
||||
// Check if any part of t should be visible
|
||||
cX, cY := t.GetX(), t.GetY()
|
||||
if cX+t.GetWidth() >= i.scrollX && cX <= i.scrollX+i.width {
|
||||
return cY+t.GetHeight() >= i.scrollY && cY <= i.scrollY+i.height
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// HandleEvent accepts the termbox event and returns whether it was consumed
|
||||
func (i *ScrollFrame) HandleEvent(event termbox.Event) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// DrawToStrings generates a slice of strings with what should
|
||||
// be drawn to the screen
|
||||
func (i *ScrollFrame) DrawToStrings() []string {
|
||||
return []string{}
|
||||
}
|
||||
|
||||
// Draw outputs the Scoll Frame on the screen
|
||||
func (i *ScrollFrame) Draw() {
|
||||
maxWidth := i.width
|
||||
maxHeight := i.height
|
||||
x, y := i.x, i.y
|
||||
startX := i.x
|
||||
startY := i.y
|
||||
if i.bordered {
|
||||
DrawBorder(i.x, i.y, i.x+i.width, i.y+i.height, i.fg, i.bg)
|
||||
maxWidth--
|
||||
maxHeight--
|
||||
x++
|
||||
y++
|
||||
startX++
|
||||
startY++
|
||||
}
|
||||
for idx := range i.controls {
|
||||
i.DrawControl(i.controls[idx])
|
||||
}
|
||||
}
|
151
vendor/github.com/br0xen/termbox-util/termbox_util.go
generated
vendored
Normal file
151
vendor/github.com/br0xen/termbox-util/termbox_util.go
generated
vendored
Normal file
@@ -0,0 +1,151 @@
|
||||
package termboxUtil
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/nsf/termbox-go"
|
||||
)
|
||||
|
||||
type termboxControl interface {
|
||||
GetID() string
|
||||
GetX() int
|
||||
SetX(int)
|
||||
GetY() int
|
||||
SetY(int)
|
||||
GetWidth() int
|
||||
SetWidth(int)
|
||||
GetHeight() int
|
||||
SetHeight(int)
|
||||
GetFgColor() termbox.Attribute
|
||||
SetFgColor(termbox.Attribute)
|
||||
GetBgColor() termbox.Attribute
|
||||
SetBgColor(termbox.Attribute)
|
||||
HandleEvent(termbox.Event) bool
|
||||
IsBordered() bool
|
||||
SetBordered(bool)
|
||||
SetTabSkip(bool)
|
||||
IsTabSkipped() bool
|
||||
Draw()
|
||||
}
|
||||
|
||||
// TextAlignment is an int value for how we're aligning text
|
||||
type TextAlignment int
|
||||
|
||||
const (
|
||||
// AlignLeft Aligns text to the left
|
||||
AlignLeft = iota
|
||||
// AlignCenter Aligns text to the center
|
||||
AlignCenter
|
||||
// AlignRight Aligns text to the right
|
||||
AlignRight
|
||||
)
|
||||
|
||||
/* Basic Input Helpers */
|
||||
|
||||
// KeyIsAlphaNumeric Returns whether the termbox event is an
|
||||
// Alpha-Numeric Key Press
|
||||
func KeyIsAlphaNumeric(event termbox.Event) bool {
|
||||
return KeyIsAlpha(event) || KeyIsNumeric(event)
|
||||
}
|
||||
|
||||
// KeyIsAlpha Returns whether the termbox event is a
|
||||
// alphabetic Key press
|
||||
func KeyIsAlpha(event termbox.Event) bool {
|
||||
k := event.Ch
|
||||
if (k >= 'a' && k <= 'z') || (k >= 'A' && k <= 'Z') {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// KeyIsNumeric Returns whether the termbox event is a
|
||||
// numeric Key press
|
||||
func KeyIsNumeric(event termbox.Event) bool {
|
||||
k := event.Ch
|
||||
if k >= '0' && k <= '9' {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// KeyIsSymbol Returns whether the termbox event is a
|
||||
// symbol Key press
|
||||
func KeyIsSymbol(event termbox.Event) bool {
|
||||
symbols := []rune{'!', '@', '#', '$', '%', '^', '&', '*',
|
||||
'(', ')', '-', '_', '=', '+', '[', ']', '{', '}', '|',
|
||||
';', ':', '"', '\'', ',', '<', '.', '>', '/', '?', '`', '~'}
|
||||
k := event.Ch
|
||||
for i := range symbols {
|
||||
if k == symbols[i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/* Basic Output Helpers */
|
||||
|
||||
// DrawStringAtPoint Draw a string of text at x, y with foreground color fg, background color bg
|
||||
func DrawStringAtPoint(str string, x int, y int, fg termbox.Attribute, bg termbox.Attribute) (int, int) {
|
||||
xPos := x
|
||||
for _, runeValue := range str {
|
||||
termbox.SetCell(xPos, y, runeValue, fg, bg)
|
||||
xPos++
|
||||
}
|
||||
return xPos, y
|
||||
}
|
||||
|
||||
// FillWithChar Fills from x1,y1 through x2,y2 with the rune r, foreground color fg, background bg
|
||||
func FillWithChar(r rune, x1, y1, x2, y2 int, fg termbox.Attribute, bg termbox.Attribute) {
|
||||
for xx := x1; xx <= x2; xx++ {
|
||||
for yx := y1; yx <= y2; yx++ {
|
||||
termbox.SetCell(xx, yx, r, fg, bg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// DrawBorder Draw a border around the area inside x1,y1 -> x2, y2
|
||||
func DrawBorder(x1, y1, x2, y2 int, fg termbox.Attribute, bg termbox.Attribute) {
|
||||
termbox.SetCell(x1, y1, '+', fg, bg)
|
||||
FillWithChar('-', x1+1, y1, x2-1, y1, fg, bg)
|
||||
termbox.SetCell(x2, y1, '+', fg, bg)
|
||||
|
||||
FillWithChar('|', x1, y1+1, x1, y2-1, fg, bg)
|
||||
FillWithChar('|', x2, y1+1, x2, y2-1, fg, bg)
|
||||
|
||||
termbox.SetCell(x1, y2, '+', fg, bg)
|
||||
FillWithChar('-', x1+1, y2, x2-1, y2, fg, bg)
|
||||
termbox.SetCell(x2, y2, '+', fg, bg)
|
||||
}
|
||||
|
||||
// AlignText Aligns the text txt within width characters using the specified alignment
|
||||
func AlignText(txt string, width int, align TextAlignment) string {
|
||||
return AlignTextWithFill(txt, width, align, ' ')
|
||||
}
|
||||
|
||||
// AlignTextWithFill Aligns the text txt within width characters using the specified alignment
|
||||
// filling any spaces with the 'fill' character
|
||||
func AlignTextWithFill(txt string, width int, align TextAlignment, fill rune) string {
|
||||
fillChar := string(fill)
|
||||
numSpaces := width - len(txt)
|
||||
switch align {
|
||||
case AlignCenter:
|
||||
if numSpaces/2 > 0 {
|
||||
return fmt.Sprintf("%s%s%s",
|
||||
strings.Repeat(fillChar, numSpaces/2),
|
||||
txt, strings.Repeat(fillChar, numSpaces/2),
|
||||
)
|
||||
}
|
||||
return txt
|
||||
case AlignRight:
|
||||
return fmt.Sprintf("%s%s", strings.Repeat(fillChar, numSpaces), txt)
|
||||
default:
|
||||
if numSpaces >= 0 {
|
||||
return fmt.Sprintf("%s%s", txt, strings.Repeat(fillChar, numSpaces))
|
||||
}
|
||||
return txt
|
||||
}
|
||||
}
|
||||
|
||||
/* More advanced things are in their respective files */
|
Reference in New Issue
Block a user