Projects STRLCPY cfonts Commits e124b3c5
🤬
Showing first 64 files as there are too many
  • ■ ■ ■ ■ ■ ■
    .editorconfig
    skipped 12 lines
    13 13  [*.md]
    14 14  trim_trailing_whitespace = false
    15 15   
     16 +[*.yml]
     17 +indent_style = space
     18 + 
  • ■ ■ ■ ■ ■ ■
    .github/workflows/testing.yml
     1 +name: Testing
     2 + 
     3 +defaults:
     4 + run:
     5 + shell: bash
     6 + 
     7 +on:
     8 + push:
     9 + branches:
     10 + - 'released'
     11 + tags:
     12 + - '!v*'
     13 + pull_request:
     14 + branches:
     15 + - 'released'
     16 + 
     17 +jobs:
     18 + # ---------------------------------| RUST |--------------------------------- #
     19 + # ***********
     20 + # RUST - linting
     21 + # ***********
     22 + lint-rust:
     23 + strategy:
     24 + matrix:
     25 + os:
     26 + - ubuntu-latest
     27 + runs-on: ${{ matrix.os }}
     28 + defaults:
     29 + run:
     30 + working-directory: ./rust
     31 + 
     32 + steps:
     33 + - uses: actions/checkout@v2
     34 + 
     35 + - uses: actions-rs/toolchain@v1
     36 + with:
     37 + toolchain: stable
     38 + components: rustfmt, clippy
     39 + args: --manifest-path ./rust/Cargo.toml
     40 + 
     41 + - name: Run Makefile
     42 + run: make
     43 + 
     44 + - name: Tree files
     45 + run: |
     46 + sudo apt-get -y install tree & which tree
     47 + tree -I "node_modules*|.git*"
     48 + 
     49 + - name: Check formatting
     50 + uses: actions-rs/cargo@v1
     51 + with:
     52 + command: fmt
     53 + args: --manifest-path ./rust/Cargo.toml -- --check
     54 + 
     55 + - name: Annotate commit with clippy warnings
     56 + uses: actions-rs/clippy-check@v1
     57 + with:
     58 + token: ${{ secrets.GITHUB_TOKEN }}
     59 + args: --all-features --manifest-path ./rust/Cargo.toml
     60 + 
     61 + # disabled until https://github.com/actions-rs/audit-check/issues/194 is fixed
     62 + # - name: Security audit
     63 + # uses: actions-rs/audit-check@v1
     64 + # with:
     65 + # token: ${{ secrets.GITHUB_TOKEN }}
     66 + 
     67 + # ***********
     68 + # RUST - testing
     69 + # ***********
     70 + test-rust:
     71 + strategy:
     72 + fail-fast: false
     73 + matrix:
     74 + os:
     75 + - ubuntu-latest
     76 + - macos-latest
     77 + - windows-latest
     78 + runs-on: ${{ matrix.os }}
     79 + env:
     80 + OS: ${{ matrix.OS }}
     81 + defaults:
     82 + run:
     83 + working-directory: ./rust
     84 + 
     85 + steps:
     86 + - uses: actions/checkout@v2
     87 + 
     88 + - name: Setup Node
     89 + uses: actions/setup-node@v3
     90 + with:
     91 + node-version: 16
     92 + 
     93 + - uses: actions-rs/toolchain@v1
     94 + with:
     95 + toolchain: stable
     96 + 
     97 + - name: Run Makefile
     98 + run: make
     99 + 
     100 + - name: Run cargo tests
     101 + uses: actions-rs/cargo@v1
     102 + with:
     103 + command: test
     104 + args: --no-fail-fast --manifest-path ./rust/Cargo.toml -- --nocapture
     105 + 
     106 + - name: Run build
     107 + run: cargo build --release --verbose
     108 + 
     109 + - name: Install dependencies in node folder for end-to-end tests
     110 + run: cd ../nodejs && yarn install --frozen-lockfile && yarn build
     111 + 
     112 + - name: Run end-to-end test
     113 + run: node tests/end-to-end/index.js
     114 + 
     115 + # ---------------------------------| NODE |--------------------------------- #
     116 + # ***********
     117 + # NODEJS - testing
     118 + # ***********
     119 + test-nodejs:
     120 + strategy:
     121 + matrix:
     122 + node: [ 12, 14, 16 ]
     123 + os:
     124 + - ubuntu-latest
     125 + - windows-latest
     126 + - macOS-latest
     127 + runs-on: ${{ matrix.os }}
     128 + defaults:
     129 + run:
     130 + working-directory: ./nodejs
     131 + 
     132 + steps:
     133 + - uses: actions/checkout@v2
     134 + 
     135 + - name: Setup Node
     136 + uses: actions/setup-node@v3
     137 + with:
     138 + node-version: ${{ matrix.node }}
     139 + 
     140 + - name: Get yarn cache
     141 + id: yarn-cache
     142 + run: echo "::set-output name=dir::$(yarn cache dir)"
     143 + 
     144 + - name: Cache dependencies
     145 + uses: actions/cache@v2
     146 + with:
     147 + path: ${{ steps.yarn-cache.outputs.dir }}
     148 + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
     149 + restore-keys: |
     150 + ${{ runner.os }}-yarn-
     151 + 
     152 + - name: Node version
     153 + run: node --version
     154 + 
     155 + - name: npm version
     156 + run: npm --version
     157 + 
     158 + - name: Yarn version
     159 + run: yarn --version
     160 + 
     161 + - name: Yarn install dependencies
     162 + run: yarn install --frozen-lockfile
     163 + 
     164 + - name: Build files
     165 + run: yarn build
     166 + 
     167 + - name: Tree files
     168 + run: npx tree-cli -l 5 --ignore "node_modules/, .git/"
     169 + 
     170 + - name: Yarn test
     171 + run: yarn test
     172 + 
     173 + 
     174 + coverage-nodejs:
     175 + needs: test-nodejs
     176 + strategy:
     177 + matrix:
     178 + node: [16]
     179 + os:
     180 + - ubuntu-latest
     181 + runs-on: ${{ matrix.os }}
     182 + defaults:
     183 + run:
     184 + working-directory: ./nodejs
     185 + 
     186 + steps:
     187 + - uses: actions/checkout@v2
     188 + 
     189 + - name: Setup Node
     190 + uses: actions/setup-node@v3
     191 + with:
     192 + node-version: ${{ matrix.node }}
     193 + 
     194 + - name: Get yarn cache
     195 + id: yarn-cache
     196 + run: echo "::set-output name=dir::$(yarn cache dir)"
     197 + 
     198 + - name: Cache dependencies
     199 + uses: actions/cache@v2
     200 + with:
     201 + path: ${{ steps.yarn-cache.outputs.dir }}
     202 + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
     203 + restore-keys: |
     204 + ${{ runner.os }}-yarn-
     205 + 
     206 + - name: Yarn install dependencies
     207 + run: yarn install --frozen-lockfile
     208 + 
     209 + - name: Build files
     210 + run: yarn build
     211 + 
     212 + - name: Produce Coverage
     213 + run: yarn jest --coverage
     214 + 
     215 + - name: Upload to coveralls
     216 + uses: coverallsapp/github-action@master
     217 + with:
     218 + github-token: ${{ secrets.GITHUB_TOKEN }}
     219 + path-to-lcov: ./nodejs/coverage/lcov.info
     220 + 
  • ■ ■ ■ ■ ■
    .gitignore
    1 1  coverage
    2 2  .DS_Store
    3  -*.sublime-project
    4 3  *.sublime-workspace
    5 4  codekit-config.json
    6 5  *.codekit
    skipped 8 lines
    15 14  lib/
    16 15  package-lock.json
    17 16  .coveralls.yml
     17 +nodejs/fonts
     18 +rust/fonts
     19 +rust/target
    18 20   
  • ■ ■ ■ ■ ■ ■
    .travis.yml
    1  -language: node_js
    2  - 
    3  -os:
    4  - - osx
    5  - - linux
    6  - 
    7  -node_js:
    8  - - 10
    9  - - 12
    10  - - node
    11  - 
    12  -jobs:
    13  - fast_finish: true
    14  - include:
    15  - - name: "Windows node 10 build"
    16  - os: windows
    17  - node_js: 10
    18  - cache: false # windows cache uploads are slow
    19  - env: YARN_GPG=no # starts gpg-agent that never exits
    20  - 
    21  - - name: "Windows node 12 build"
    22  - os: windows
    23  - node_js: 12
    24  - cache: false # windows cache uploads are slow
    25  - env: YARN_GPG=no # starts gpg-agent that never exits
    26  - 
    27  - - name: "Windows node latest build"
    28  - os: windows
    29  - node_js: node
    30  - cache: false # windows cache uploads are slow
    31  - env: YARN_GPG=no # starts gpg-agent that never exits
    32  - 
    33  - - stage: Produce Coverage
    34  - node_js: node
    35  - os: osx
    36  - script: jest --coverage && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage
    37  - 
    38  -# before_install:
    39  -# - if [ "$TRAVIS_OS_NAME" = "windows" ]; then powershell -command 'Set-MpPreference -DisableRealtimeMonitoring $true' ; fi
    40  -# - if [ "$TRAVIS_OS_NAME" = "windows" ]; then export NODEPATH=$(where.exe node.exe) ; fi
    41  -# - if [ "$TRAVIS_OS_NAME" = "windows" ]; then export PROJECTDIR=$(pwd) ; fi
    42  -# - if [ "$TRAVIS_OS_NAME" = "windows" ]; then export YARNCACHE=$(yarn cache dir) ; fi
    43  -# - if [ "$TRAVIS_OS_NAME" = "windows" ]; then export TEMPDIR=$LOCALAPPDATA\\Temp ; fi
    44  - 
    45  -# - if [ "$TRAVIS_OS_NAME" = "windows" ]; then powershell Add-MpPreference -ExclusionProcess ${NODEPATH} ; fi
    46  -# - if [ "$TRAVIS_OS_NAME" = "windows" ]; then powershell Add-MpPreference -ExclusionPath ${YARNCACHE} ; fi
    47  -# - if [ "$TRAVIS_OS_NAME" = "windows" ]; then powershell Add-MpPreference -ExclusionPath ${PROJECTDIR} ; fi
    48  -# - if [ "$TRAVIS_OS_NAME" = "windows" ]; then powershell Add-MpPreference -ExclusionPath ${TEMPDIR} ; fi
    49  - 
    50  -# - if [ "$TRAVIS_OS_NAME" = "windows" ]; then echo "DisableArchiveScanning..." ; fi
    51  -# - if [ "$TRAVIS_OS_NAME" = "windows" ]; then powershell Start-Process -PassThru -Wait PowerShell -ArgumentList "'-Command Set-MpPreference -DisableArchiveScanning \$true'" ; fi
    52  - 
    53  -# - if [ "$TRAVIS_OS_NAME" = "windows" ]; then echo "DisableBehaviorMonitoring..." ; fi
    54  -# - if [ "$TRAVIS_OS_NAME" = "windows" ]; then powershell Start-Process -PassThru -Wait PowerShell -ArgumentList "'-Command Set-MpPreference -DisableBehaviorMonitoring \$true'" ; fi
    55  - 
    56  -# - if [ "$TRAVIS_OS_NAME" = "windows" ]; then echo "DisableRealtimeMonitoring..." ; fi
    57  -# - if [ "$TRAVIS_OS_NAME" = "windows" ]; then powershell Start-Process -PassThru -Wait PowerShell -ArgumentList "'-Command Set-MpPreference -DisableRealtimeMonitoring \$true'" ; fi
    58  - 
  • ■ ■ ■ ■ ■ ■
    LICENSE
    1  -GNU GENERAL PUBLIC LICENSE
    2  - Version 2, June 1991
     1 + GNU GENERAL PUBLIC LICENSE
     2 + Version 3, 29 June 2007
    3 3   
    4  - Copyright (C) 1989, 1991 Free Software Foundation, Inc., <http://fsf.org/>
    5  - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     4 + Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
    6 5   Everyone is permitted to copy and distribute verbatim copies
    7 6   of this license document, but changing it is not allowed.
    8 7   
    9 8   Preamble
    10 9   
    11  - The licenses for most software are designed to take away your
    12  -freedom to share and change it. By contrast, the GNU General Public
    13  -License is intended to guarantee your freedom to share and change free
    14  -software--to make sure the software is free for all its users. This
    15  -General Public License applies to most of the Free Software
    16  -Foundation's software and to any other program whose authors commit to
    17  -using it. (Some other Free Software Foundation software is covered by
    18  -the GNU Lesser General Public License instead.) You can apply it to
     10 + The GNU General Public License is a free, copyleft license for
     11 +software and other kinds of works.
     12 + 
     13 + The licenses for most software and other practical works are designed
     14 +to take away your freedom to share and change the works. By contrast,
     15 +the GNU General Public License is intended to guarantee your freedom to
     16 +share and change all versions of a program--to make sure it remains free
     17 +software for all its users. We, the Free Software Foundation, use the
     18 +GNU General Public License for most of our software; it applies also to
     19 +any other work released this way by its authors. You can apply it to
    19 20  your programs, too.
    20 21   
    21 22   When we speak of free software, we are referring to freedom, not
    22 23  price. Our General Public Licenses are designed to make sure that you
    23 24  have the freedom to distribute copies of free software (and charge for
    24  -this service if you wish), that you receive source code or can get it
    25  -if you want it, that you can change the software or use pieces of it
    26  -in new free programs; and that you know you can do these things.
     25 +them if you wish), that you receive source code or can get it if you
     26 +want it, that you can change the software or use pieces of it in new
     27 +free programs, and that you know you can do these things.
    27 28   
    28  - To protect your rights, we need to make restrictions that forbid
    29  -anyone to deny you these rights or to ask you to surrender the rights.
    30  -These restrictions translate to certain responsibilities for you if you
    31  -distribute copies of the software, or if you modify it.
     29 + To protect your rights, we need to prevent others from denying you
     30 +these rights or asking you to surrender the rights. Therefore, you have
     31 +certain responsibilities if you distribute copies of the software, or if
     32 +you modify it: responsibilities to respect the freedom of others.
    32 33   
    33 34   For example, if you distribute copies of such a program, whether
    34  -gratis or for a fee, you must give the recipients all the rights that
    35  -you have. You must make sure that they, too, receive or can get the
    36  -source code. And you must show them these terms so they know their
    37  -rights.
     35 +gratis or for a fee, you must pass on to the recipients the same
     36 +freedoms that you received. You must make sure that they, too, receive
     37 +or can get the source code. And you must show them these terms so they
     38 +know their rights.
     39 + 
     40 + Developers that use the GNU GPL protect your rights with two steps:
     41 +(1) assert copyright on the software, and (2) offer you this License
     42 +giving you legal permission to copy, distribute and/or modify it.
    38 43   
    39  - We protect your rights with two steps: (1) copyright the software, and
    40  -(2) offer you this license which gives you legal permission to copy,
    41  -distribute and/or modify the software.
     44 + For the developers' and authors' protection, the GPL clearly explains
     45 +that there is no warranty for this free software. For both users' and
     46 +authors' sake, the GPL requires that modified versions be marked as
     47 +changed, so that their problems will not be attributed erroneously to
     48 +authors of previous versions.
    42 49   
    43  - Also, for each author's protection and ours, we want to make certain
    44  -that everyone understands that there is no warranty for this free
    45  -software. If the software is modified by someone else and passed on, we
    46  -want its recipients to know that what they have is not the original, so
    47  -that any problems introduced by others will not reflect on the original
    48  -authors' reputations.
     50 + Some devices are designed to deny users access to install or run
     51 +modified versions of the software inside them, although the manufacturer
     52 +can do so. This is fundamentally incompatible with the aim of
     53 +protecting users' freedom to change the software. The systematic
     54 +pattern of such abuse occurs in the area of products for individuals to
     55 +use, which is precisely where it is most unacceptable. Therefore, we
     56 +have designed this version of the GPL to prohibit the practice for those
     57 +products. If such problems arise substantially in other domains, we
     58 +stand ready to extend this provision to those domains in future versions
     59 +of the GPL, as needed to protect the freedom of users.
    49 60   
    50  - Finally, any free program is threatened constantly by software
    51  -patents. We wish to avoid the danger that redistributors of a free
    52  -program will individually obtain patent licenses, in effect making the
    53  -program proprietary. To prevent this, we have made it clear that any
    54  -patent must be licensed for everyone's free use or not licensed at all.
     61 + Finally, every program is threatened constantly by software patents.
     62 +States should not allow patents to restrict development and use of
     63 +software on general-purpose computers, but in those that do, we wish to
     64 +avoid the special danger that patents applied to a free program could
     65 +make it effectively proprietary. To prevent this, the GPL assures that
     66 +patents cannot be used to render the program non-free.
    55 67   
    56 68   The precise terms and conditions for copying, distribution and
    57 69  modification follow.
    58 70   
    59  - GNU GENERAL PUBLIC LICENSE
    60  - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
     71 + TERMS AND CONDITIONS
     72 + 
     73 + 0. Definitions.
     74 + 
     75 + "This License" refers to version 3 of the GNU General Public License.
     76 + 
     77 + "Copyright" also means copyright-like laws that apply to other kinds of
     78 +works, such as semiconductor masks.
     79 + 
     80 + "The Program" refers to any copyrightable work licensed under this
     81 +License. Each licensee is addressed as "you". "Licensees" and
     82 +"recipients" may be individuals or organizations.
     83 + 
     84 + To "modify" a work means to copy from or adapt all or part of the work
     85 +in a fashion requiring copyright permission, other than the making of an
     86 +exact copy. The resulting work is called a "modified version" of the
     87 +earlier work or a work "based on" the earlier work.
    61 88   
    62  - 0. This License applies to any program or other work which contains
    63  -a notice placed by the copyright holder saying it may be distributed
    64  -under the terms of this General Public License. The "Program", below,
    65  -refers to any such program or work, and a "work based on the Program"
    66  -means either the Program or any derivative work under copyright law:
    67  -that is to say, a work containing the Program or a portion of it,
    68  -either verbatim or with modifications and/or translated into another
    69  -language. (Hereinafter, translation is included without limitation in
    70  -the term "modification".) Each licensee is addressed as "you".
     89 + A "covered work" means either the unmodified Program or a work based
     90 +on the Program.
     91 + 
     92 + To "propagate" a work means to do anything with it that, without
     93 +permission, would make you directly or secondarily liable for
     94 +infringement under applicable copyright law, except executing it on a
     95 +computer or modifying a private copy. Propagation includes copying,
     96 +distribution (with or without modification), making available to the
     97 +public, and in some countries other activities as well.
     98 + 
     99 + To "convey" a work means any kind of propagation that enables other
     100 +parties to make or receive copies. Mere interaction with a user through
     101 +a computer network, with no transfer of a copy, is not conveying.
     102 + 
     103 + An interactive user interface displays "Appropriate Legal Notices"
     104 +to the extent that it includes a convenient and prominently visible
     105 +feature that (1) displays an appropriate copyright notice, and (2)
     106 +tells the user that there is no warranty for the work (except to the
     107 +extent that warranties are provided), that licensees may convey the
     108 +work under this License, and how to view a copy of this License. If
     109 +the interface presents a list of user commands or options, such as a
     110 +menu, a prominent item in the list meets this criterion.
     111 + 
     112 + 1. Source Code.
     113 + 
     114 + The "source code" for a work means the preferred form of the work
     115 +for making modifications to it. "Object code" means any non-source
     116 +form of a work.
     117 + 
     118 + A "Standard Interface" means an interface that either is an official
     119 +standard defined by a recognized standards body, or, in the case of
     120 +interfaces specified for a particular programming language, one that
     121 +is widely used among developers working in that language.
     122 + 
     123 + The "System Libraries" of an executable work include anything, other
     124 +than the work as a whole, that (a) is included in the normal form of
     125 +packaging a Major Component, but which is not part of that Major
     126 +Component, and (b) serves only to enable use of the work with that
     127 +Major Component, or to implement a Standard Interface for which an
     128 +implementation is available to the public in source code form. A
     129 +"Major Component", in this context, means a major essential component
     130 +(kernel, window system, and so on) of the specific operating system
     131 +(if any) on which the executable work runs, or a compiler used to
     132 +produce the work, or an object code interpreter used to run it.
     133 + 
     134 + The "Corresponding Source" for a work in object code form means all
     135 +the source code needed to generate, install, and (for an executable
     136 +work) run the object code and to modify the work, including scripts to
     137 +control those activities. However, it does not include the work's
     138 +System Libraries, or general-purpose tools or generally available free
     139 +programs which are used unmodified in performing those activities but
     140 +which are not part of the work. For example, Corresponding Source
     141 +includes interface definition files associated with source files for
     142 +the work, and the source code for shared libraries and dynamically
     143 +linked subprograms that the work is specifically designed to require,
     144 +such as by intimate data communication or control flow between those
     145 +subprograms and other parts of the work.
     146 + 
     147 + The Corresponding Source need not include anything that users
     148 +can regenerate automatically from other parts of the Corresponding
     149 +Source.
     150 + 
     151 + The Corresponding Source for a work in source code form is that
     152 +same work.
     153 + 
     154 + 2. Basic Permissions.
     155 + 
     156 + All rights granted under this License are granted for the term of
     157 +copyright on the Program, and are irrevocable provided the stated
     158 +conditions are met. This License explicitly affirms your unlimited
     159 +permission to run the unmodified Program. The output from running a
     160 +covered work is covered by this License only if the output, given its
     161 +content, constitutes a covered work. This License acknowledges your
     162 +rights of fair use or other equivalent, as provided by copyright law.
     163 + 
     164 + You may make, run and propagate covered works that you do not
     165 +convey, without conditions so long as your license otherwise remains
     166 +in force. You may convey covered works to others for the sole purpose
     167 +of having them make modifications exclusively for you, or provide you
     168 +with facilities for running those works, provided that you comply with
     169 +the terms of this License in conveying all material for which you do
     170 +not control copyright. Those thus making or running the covered works
     171 +for you must do so exclusively on your behalf, under your direction
     172 +and control, on terms that prohibit them from making any copies of
     173 +your copyrighted material outside their relationship with you.
     174 + 
     175 + Conveying under any other circumstances is permitted solely under
     176 +the conditions stated below. Sublicensing is not allowed; section 10
     177 +makes it unnecessary.
     178 + 
     179 + 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
     180 + 
     181 + No covered work shall be deemed part of an effective technological
     182 +measure under any applicable law fulfilling obligations under article
     183 +11 of the WIPO copyright treaty adopted on 20 December 1996, or
     184 +similar laws prohibiting or restricting circumvention of such
     185 +measures.
     186 + 
     187 + When you convey a covered work, you waive any legal power to forbid
     188 +circumvention of technological measures to the extent such circumvention
     189 +is effected by exercising rights under this License with respect to
     190 +the covered work, and you disclaim any intention to limit operation or
     191 +modification of the work as a means of enforcing, against the work's
     192 +users, your or third parties' legal rights to forbid circumvention of
     193 +technological measures.
    71 194   
    72  -Activities other than copying, distribution and modification are not
    73  -covered by this License; they are outside its scope. The act of
    74  -running the Program is not restricted, and the output from the Program
    75  -is covered only if its contents constitute a work based on the
    76  -Program (independent of having been made by running the Program).
    77  -Whether that is true depends on what the Program does.
     195 + 4. Conveying Verbatim Copies.
    78 196   
    79  - 1. You may copy and distribute verbatim copies of the Program's
    80  -source code as you receive it, in any medium, provided that you
    81  -conspicuously and appropriately publish on each copy an appropriate
    82  -copyright notice and disclaimer of warranty; keep intact all the
    83  -notices that refer to this License and to the absence of any warranty;
    84  -and give any other recipients of the Program a copy of this License
    85  -along with the Program.
     197 + You may convey verbatim copies of the Program's source code as you
     198 +receive it, in any medium, provided that you conspicuously and
     199 +appropriately publish on each copy an appropriate copyright notice;
     200 +keep intact all notices stating that this License and any
     201 +non-permissive terms added in accord with section 7 apply to the code;
     202 +keep intact all notices of the absence of any warranty; and give all
     203 +recipients a copy of this License along with the Program.
    86 204   
    87  -You may charge a fee for the physical act of transferring a copy, and
    88  -you may at your option offer warranty protection in exchange for a fee.
     205 + You may charge any price or no price for each copy that you convey,
     206 +and you may offer support or warranty protection for a fee.
    89 207   
    90  - 2. You may modify your copy or copies of the Program or any portion
    91  -of it, thus forming a work based on the Program, and copy and
    92  -distribute such modifications or work under the terms of Section 1
    93  -above, provided that you also meet all of these conditions:
     208 + 5. Conveying Modified Source Versions.
    94 209   
    95  - a) You must cause the modified files to carry prominent notices
    96  - stating that you changed the files and the date of any change.
     210 + You may convey a work based on the Program, or the modifications to
     211 +produce it from the Program, in the form of source code under the
     212 +terms of section 4, provided that you also meet all of these conditions:
    97 213   
    98  - b) You must cause any work that you distribute or publish, that in
    99  - whole or in part contains or is derived from the Program or any
    100  - part thereof, to be licensed as a whole at no charge to all third
    101  - parties under the terms of this License.
     214 + a) The work must carry prominent notices stating that you modified
     215 + it, and giving a relevant date.
    102 216   
    103  - c) If the modified program normally reads commands interactively
    104  - when run, you must cause it, when started running for such
    105  - interactive use in the most ordinary way, to print or display an
    106  - announcement including an appropriate copyright notice and a
    107  - notice that there is no warranty (or else, saying that you provide
    108  - a warranty) and that users may redistribute the program under
    109  - these conditions, and telling the user how to view a copy of this
    110  - License. (Exception: if the Program itself is interactive but
    111  - does not normally print such an announcement, your work based on
    112  - the Program is not required to print an announcement.)
     217 + b) The work must carry prominent notices stating that it is
     218 + released under this License and any conditions added under section
     219 + 7. This requirement modifies the requirement in section 4 to
     220 + "keep intact all notices".
    113 221   
    114  -These requirements apply to the modified work as a whole. If
    115  -identifiable sections of that work are not derived from the Program,
    116  -and can be reasonably considered independent and separate works in
    117  -themselves, then this License, and its terms, do not apply to those
    118  -sections when you distribute them as separate works. But when you
    119  -distribute the same sections as part of a whole which is a work based
    120  -on the Program, the distribution of the whole must be on the terms of
    121  -this License, whose permissions for other licensees extend to the
    122  -entire whole, and thus to each and every part regardless of who wrote it.
     222 + c) You must license the entire work, as a whole, under this
     223 + License to anyone who comes into possession of a copy. This
     224 + License will therefore apply, along with any applicable section 7
     225 + additional terms, to the whole of the work, and all its parts,
     226 + regardless of how they are packaged. This License gives no
     227 + permission to license the work in any other way, but it does not
     228 + invalidate such permission if you have separately received it.
    123 229   
    124  -Thus, it is not the intent of this section to claim rights or contest
    125  -your rights to work written entirely by you; rather, the intent is to
    126  -exercise the right to control the distribution of derivative or
    127  -collective works based on the Program.
     230 + d) If the work has interactive user interfaces, each must display
     231 + Appropriate Legal Notices; however, if the Program has interactive
     232 + interfaces that do not display Appropriate Legal Notices, your
     233 + work need not make them do so.
    128 234   
    129  -In addition, mere aggregation of another work not based on the Program
    130  -with the Program (or with a work based on the Program) on a volume of
    131  -a storage or distribution medium does not bring the other work under
    132  -the scope of this License.
     235 + A compilation of a covered work with other separate and independent
     236 +works, which are not by their nature extensions of the covered work,
     237 +and which are not combined with it such as to form a larger program,
     238 +in or on a volume of a storage or distribution medium, is called an
     239 +"aggregate" if the compilation and its resulting copyright are not
     240 +used to limit the access or legal rights of the compilation's users
     241 +beyond what the individual works permit. Inclusion of a covered work
     242 +in an aggregate does not cause this License to apply to the other
     243 +parts of the aggregate.
    133 244   
    134  - 3. You may copy and distribute the Program (or a work based on it,
    135  -under Section 2) in object code or executable form under the terms of
    136  -Sections 1 and 2 above provided that you also do one of the following:
     245 + 6. Conveying Non-Source Forms.
    137 246   
    138  - a) Accompany it with the complete corresponding machine-readable
    139  - source code, which must be distributed under the terms of Sections
    140  - 1 and 2 above on a medium customarily used for software interchange; or,
     247 + You may convey a covered work in object code form under the terms
     248 +of sections 4 and 5, provided that you also convey the
     249 +machine-readable Corresponding Source under the terms of this License,
     250 +in one of these ways:
    141 251   
    142  - b) Accompany it with a written offer, valid for at least three
    143  - years, to give any third party, for a charge no more than your
    144  - cost of physically performing source distribution, a complete
    145  - machine-readable copy of the corresponding source code, to be
    146  - distributed under the terms of Sections 1 and 2 above on a medium
    147  - customarily used for software interchange; or,
     252 + a) Convey the object code in, or embodied in, a physical product
     253 + (including a physical distribution medium), accompanied by the
     254 + Corresponding Source fixed on a durable physical medium
     255 + customarily used for software interchange.
    148 256   
    149  - c) Accompany it with the information you received as to the offer
    150  - to distribute corresponding source code. (This alternative is
    151  - allowed only for noncommercial distribution and only if you
    152  - received the program in object code or executable form with such
    153  - an offer, in accord with Subsection b above.)
     257 + b) Convey the object code in, or embodied in, a physical product
     258 + (including a physical distribution medium), accompanied by a
     259 + written offer, valid for at least three years and valid for as
     260 + long as you offer spare parts or customer support for that product
     261 + model, to give anyone who possesses the object code either (1) a
     262 + copy of the Corresponding Source for all the software in the
     263 + product that is covered by this License, on a durable physical
     264 + medium customarily used for software interchange, for a price no
     265 + more than your reasonable cost of physically performing this
     266 + conveying of source, or (2) access to copy the
     267 + Corresponding Source from a network server at no charge.
    154 268   
    155  -The source code for a work means the preferred form of the work for
    156  -making modifications to it. For an executable work, complete source
    157  -code means all the source code for all modules it contains, plus any
    158  -associated interface definition files, plus the scripts used to
    159  -control compilation and installation of the executable. However, as a
    160  -special exception, the source code distributed need not include
    161  -anything that is normally distributed (in either source or binary
    162  -form) with the major components (compiler, kernel, and so on) of the
    163  -operating system on which the executable runs, unless that component
    164  -itself accompanies the executable.
     269 + c) Convey individual copies of the object code with a copy of the
     270 + written offer to provide the Corresponding Source. This
     271 + alternative is allowed only occasionally and noncommercially, and
     272 + only if you received the object code with such an offer, in accord
     273 + with subsection 6b.
    165 274   
    166  -If distribution of executable or object code is made by offering
    167  -access to copy from a designated place, then offering equivalent
    168  -access to copy the source code from the same place counts as
    169  -distribution of the source code, even though third parties are not
    170  -compelled to copy the source along with the object code.
     275 + d) Convey the object code by offering access from a designated
     276 + place (gratis or for a charge), and offer equivalent access to the
     277 + Corresponding Source in the same way through the same place at no
     278 + further charge. You need not require recipients to copy the
     279 + Corresponding Source along with the object code. If the place to
     280 + copy the object code is a network server, the Corresponding Source
     281 + may be on a different server (operated by you or a third party)
     282 + that supports equivalent copying facilities, provided you maintain
     283 + clear directions next to the object code saying where to find the
     284 + Corresponding Source. Regardless of what server hosts the
     285 + Corresponding Source, you remain obligated to ensure that it is
     286 + available for as long as needed to satisfy these requirements.
    171 287   
    172  - 4. You may not copy, modify, sublicense, or distribute the Program
    173  -except as expressly provided under this License. Any attempt
    174  -otherwise to copy, modify, sublicense or distribute the Program is
    175  -void, and will automatically terminate your rights under this License.
    176  -However, parties who have received copies, or rights, from you under
    177  -this License will not have their licenses terminated so long as such
    178  -parties remain in full compliance.
     288 + e) Convey the object code using peer-to-peer transmission, provided
     289 + you inform other peers where the object code and Corresponding
     290 + Source of the work are being offered to the general public at no
     291 + charge under subsection 6d.
    179 292   
    180  - 5. You are not required to accept this License, since you have not
    181  -signed it. However, nothing else grants you permission to modify or
    182  -distribute the Program or its derivative works. These actions are
    183  -prohibited by law if you do not accept this License. Therefore, by
    184  -modifying or distributing the Program (or any work based on the
    185  -Program), you indicate your acceptance of this License to do so, and
    186  -all its terms and conditions for copying, distributing or modifying
    187  -the Program or works based on it.
     293 + A separable portion of the object code, whose source code is excluded
     294 +from the Corresponding Source as a System Library, need not be
     295 +included in conveying the object code work.
    188 296   
    189  - 6. Each time you redistribute the Program (or any work based on the
    190  -Program), the recipient automatically receives a license from the
    191  -original licensor to copy, distribute or modify the Program subject to
    192  -these terms and conditions. You may not impose any further
    193  -restrictions on the recipients' exercise of the rights granted herein.
    194  -You are not responsible for enforcing compliance by third parties to
     297 + A "User Product" is either (1) a "consumer product", which means any
     298 +tangible personal property which is normally used for personal, family,
     299 +or household purposes, or (2) anything designed or sold for incorporation
     300 +into a dwelling. In determining whether a product is a consumer product,
     301 +doubtful cases shall be resolved in favor of coverage. For a particular
     302 +product received by a particular user, "normally used" refers to a
     303 +typical or common use of that class of product, regardless of the status
     304 +of the particular user or of the way in which the particular user
     305 +actually uses, or expects or is expected to use, the product. A product
     306 +is a consumer product regardless of whether the product has substantial
     307 +commercial, industrial or non-consumer uses, unless such uses represent
     308 +the only significant mode of use of the product.
     309 + 
     310 + "Installation Information" for a User Product means any methods,
     311 +procedures, authorization keys, or other information required to install
     312 +and execute modified versions of a covered work in that User Product from
     313 +a modified version of its Corresponding Source. The information must
     314 +suffice to ensure that the continued functioning of the modified object
     315 +code is in no case prevented or interfered with solely because
     316 +modification has been made.
     317 + 
     318 + If you convey an object code work under this section in, or with, or
     319 +specifically for use in, a User Product, and the conveying occurs as
     320 +part of a transaction in which the right of possession and use of the
     321 +User Product is transferred to the recipient in perpetuity or for a
     322 +fixed term (regardless of how the transaction is characterized), the
     323 +Corresponding Source conveyed under this section must be accompanied
     324 +by the Installation Information. But this requirement does not apply
     325 +if neither you nor any third party retains the ability to install
     326 +modified object code on the User Product (for example, the work has
     327 +been installed in ROM).
     328 + 
     329 + The requirement to provide Installation Information does not include a
     330 +requirement to continue to provide support service, warranty, or updates
     331 +for a work that has been modified or installed by the recipient, or for
     332 +the User Product in which it has been modified or installed. Access to a
     333 +network may be denied when the modification itself materially and
     334 +adversely affects the operation of the network or violates the rules and
     335 +protocols for communication across the network.
     336 + 
     337 + Corresponding Source conveyed, and Installation Information provided,
     338 +in accord with this section must be in a format that is publicly
     339 +documented (and with an implementation available to the public in
     340 +source code form), and must require no special password or key for
     341 +unpacking, reading or copying.
     342 + 
     343 + 7. Additional Terms.
     344 + 
     345 + "Additional permissions" are terms that supplement the terms of this
     346 +License by making exceptions from one or more of its conditions.
     347 +Additional permissions that are applicable to the entire Program shall
     348 +be treated as though they were included in this License, to the extent
     349 +that they are valid under applicable law. If additional permissions
     350 +apply only to part of the Program, that part may be used separately
     351 +under those permissions, but the entire Program remains governed by
     352 +this License without regard to the additional permissions.
     353 + 
     354 + When you convey a copy of a covered work, you may at your option
     355 +remove any additional permissions from that copy, or from any part of
     356 +it. (Additional permissions may be written to require their own
     357 +removal in certain cases when you modify the work.) You may place
     358 +additional permissions on material, added by you to a covered work,
     359 +for which you have or can give appropriate copyright permission.
     360 + 
     361 + Notwithstanding any other provision of this License, for material you
     362 +add to a covered work, you may (if authorized by the copyright holders of
     363 +that material) supplement the terms of this License with terms:
     364 + 
     365 + a) Disclaiming warranty or limiting liability differently from the
     366 + terms of sections 15 and 16 of this License; or
     367 + 
     368 + b) Requiring preservation of specified reasonable legal notices or
     369 + author attributions in that material or in the Appropriate Legal
     370 + Notices displayed by works containing it; or
     371 + 
     372 + c) Prohibiting misrepresentation of the origin of that material, or
     373 + requiring that modified versions of such material be marked in
     374 + reasonable ways as different from the original version; or
     375 + 
     376 + d) Limiting the use for publicity purposes of names of licensors or
     377 + authors of the material; or
     378 + 
     379 + e) Declining to grant rights under trademark law for use of some
     380 + trade names, trademarks, or service marks; or
     381 + 
     382 + f) Requiring indemnification of licensors and authors of that
     383 + material by anyone who conveys the material (or modified versions of
     384 + it) with contractual assumptions of liability to the recipient, for
     385 + any liability that these contractual assumptions directly impose on
     386 + those licensors and authors.
     387 + 
     388 + All other non-permissive additional terms are considered "further
     389 +restrictions" within the meaning of section 10. If the Program as you
     390 +received it, or any part of it, contains a notice stating that it is
     391 +governed by this License along with a term that is a further
     392 +restriction, you may remove that term. If a license document contains
     393 +a further restriction but permits relicensing or conveying under this
     394 +License, you may add to a covered work material governed by the terms
     395 +of that license document, provided that the further restriction does
     396 +not survive such relicensing or conveying.
     397 + 
     398 + If you add terms to a covered work in accord with this section, you
     399 +must place, in the relevant source files, a statement of the
     400 +additional terms that apply to those files, or a notice indicating
     401 +where to find the applicable terms.
     402 + 
     403 + Additional terms, permissive or non-permissive, may be stated in the
     404 +form of a separately written license, or stated as exceptions;
     405 +the above requirements apply either way.
     406 + 
     407 + 8. Termination.
     408 + 
     409 + You may not propagate or modify a covered work except as expressly
     410 +provided under this License. Any attempt otherwise to propagate or
     411 +modify it is void, and will automatically terminate your rights under
     412 +this License (including any patent licenses granted under the third
     413 +paragraph of section 11).
     414 + 
     415 + However, if you cease all violation of this License, then your
     416 +license from a particular copyright holder is reinstated (a)
     417 +provisionally, unless and until the copyright holder explicitly and
     418 +finally terminates your license, and (b) permanently, if the copyright
     419 +holder fails to notify you of the violation by some reasonable means
     420 +prior to 60 days after the cessation.
     421 + 
     422 + Moreover, your license from a particular copyright holder is
     423 +reinstated permanently if the copyright holder notifies you of the
     424 +violation by some reasonable means, this is the first time you have
     425 +received notice of violation of this License (for any work) from that
     426 +copyright holder, and you cure the violation prior to 30 days after
     427 +your receipt of the notice.
     428 + 
     429 + Termination of your rights under this section does not terminate the
     430 +licenses of parties who have received copies or rights from you under
     431 +this License. If your rights have been terminated and not permanently
     432 +reinstated, you do not qualify to receive new licenses for the same
     433 +material under section 10.
     434 + 
     435 + 9. Acceptance Not Required for Having Copies.
     436 + 
     437 + You are not required to accept this License in order to receive or
     438 +run a copy of the Program. Ancillary propagation of a covered work
     439 +occurring solely as a consequence of using peer-to-peer transmission
     440 +to receive a copy likewise does not require acceptance. However,
     441 +nothing other than this License grants you permission to propagate or
     442 +modify any covered work. These actions infringe copyright if you do
     443 +not accept this License. Therefore, by modifying or propagating a
     444 +covered work, you indicate your acceptance of this License to do so.
     445 + 
     446 + 10. Automatic Licensing of Downstream Recipients.
     447 + 
     448 + Each time you convey a covered work, the recipient automatically
     449 +receives a license from the original licensors, to run, modify and
     450 +propagate that work, subject to this License. You are not responsible
     451 +for enforcing compliance by third parties with this License.
     452 + 
     453 + An "entity transaction" is a transaction transferring control of an
     454 +organization, or substantially all assets of one, or subdividing an
     455 +organization, or merging organizations. If propagation of a covered
     456 +work results from an entity transaction, each party to that
     457 +transaction who receives a copy of the work also receives whatever
     458 +licenses to the work the party's predecessor in interest had or could
     459 +give under the previous paragraph, plus a right to possession of the
     460 +Corresponding Source of the work from the predecessor in interest, if
     461 +the predecessor has it or can get it with reasonable efforts.
     462 + 
     463 + You may not impose any further restrictions on the exercise of the
     464 +rights granted or affirmed under this License. For example, you may
     465 +not impose a license fee, royalty, or other charge for exercise of
     466 +rights granted under this License, and you may not initiate litigation
     467 +(including a cross-claim or counterclaim in a lawsuit) alleging that
     468 +any patent claim is infringed by making, using, selling, offering for
     469 +sale, or importing the Program or any portion of it.
     470 + 
     471 + 11. Patents.
     472 + 
     473 + A "contributor" is a copyright holder who authorizes use under this
     474 +License of the Program or a work on which the Program is based. The
     475 +work thus licensed is called the contributor's "contributor version".
     476 + 
     477 + A contributor's "essential patent claims" are all patent claims
     478 +owned or controlled by the contributor, whether already acquired or
     479 +hereafter acquired, that would be infringed by some manner, permitted
     480 +by this License, of making, using, or selling its contributor version,
     481 +but do not include claims that would be infringed only as a
     482 +consequence of further modification of the contributor version. For
     483 +purposes of this definition, "control" includes the right to grant
     484 +patent sublicenses in a manner consistent with the requirements of
    195 485  this License.
    196 486   
    197  - 7. If, as a consequence of a court judgment or allegation of patent
    198  -infringement or for any other reason (not limited to patent issues),
    199  -conditions are imposed on you (whether by court order, agreement or
     487 + Each contributor grants you a non-exclusive, worldwide, royalty-free
     488 +patent license under the contributor's essential patent claims, to
     489 +make, use, sell, offer for sale, import and otherwise run, modify and
     490 +propagate the contents of its contributor version.
     491 + 
     492 + In the following three paragraphs, a "patent license" is any express
     493 +agreement or commitment, however denominated, not to enforce a patent
     494 +(such as an express permission to practice a patent or covenant not to
     495 +sue for patent infringement). To "grant" such a patent license to a
     496 +party means to make such an agreement or commitment not to enforce a
     497 +patent against the party.
     498 + 
     499 + If you convey a covered work, knowingly relying on a patent license,
     500 +and the Corresponding Source of the work is not available for anyone
     501 +to copy, free of charge and under the terms of this License, through a
     502 +publicly available network server or other readily accessible means,
     503 +then you must either (1) cause the Corresponding Source to be so
     504 +available, or (2) arrange to deprive yourself of the benefit of the
     505 +patent license for this particular work, or (3) arrange, in a manner
     506 +consistent with the requirements of this License, to extend the patent
     507 +license to downstream recipients. "Knowingly relying" means you have
     508 +actual knowledge that, but for the patent license, your conveying the
     509 +covered work in a country, or your recipient's use of the covered work
     510 +in a country, would infringe one or more identifiable patents in that
     511 +country that you have reason to believe are valid.
     512 + 
     513 + If, pursuant to or in connection with a single transaction or
     514 +arrangement, you convey, or propagate by procuring conveyance of, a
     515 +covered work, and grant a patent license to some of the parties
     516 +receiving the covered work authorizing them to use, propagate, modify
     517 +or convey a specific copy of the covered work, then the patent license
     518 +you grant is automatically extended to all recipients of the covered
     519 +work and works based on it.
     520 + 
     521 + A patent license is "discriminatory" if it does not include within
     522 +the scope of its coverage, prohibits the exercise of, or is
     523 +conditioned on the non-exercise of one or more of the rights that are
     524 +specifically granted under this License. You may not convey a covered
     525 +work if you are a party to an arrangement with a third party that is
     526 +in the business of distributing software, under which you make payment
     527 +to the third party based on the extent of your activity of conveying
     528 +the work, and under which the third party grants, to any of the
     529 +parties who would receive the covered work from you, a discriminatory
     530 +patent license (a) in connection with copies of the covered work
     531 +conveyed by you (or copies made from those copies), or (b) primarily
     532 +for and in connection with specific products or compilations that
     533 +contain the covered work, unless you entered into that arrangement,
     534 +or that patent license was granted, prior to 28 March 2007.
     535 + 
     536 + Nothing in this License shall be construed as excluding or limiting
     537 +any implied license or other defenses to infringement that may
     538 +otherwise be available to you under applicable patent law.
     539 + 
     540 + 12. No Surrender of Others' Freedom.
     541 + 
     542 + If conditions are imposed on you (whether by court order, agreement or
    200 543  otherwise) that contradict the conditions of this License, they do not
    201  -excuse you from the conditions of this License. If you cannot
    202  -distribute so as to satisfy simultaneously your obligations under this
    203  -License and any other pertinent obligations, then as a consequence you
    204  -may not distribute the Program at all. For example, if a patent
    205  -license would not permit royalty-free redistribution of the Program by
    206  -all those who receive copies directly or indirectly through you, then
    207  -the only way you could satisfy both it and this License would be to
    208  -refrain entirely from distribution of the Program.
     544 +excuse you from the conditions of this License. If you cannot convey a
     545 +covered work so as to satisfy simultaneously your obligations under this
     546 +License and any other pertinent obligations, then as a consequence you may
     547 +not convey it at all. For example, if you agree to terms that obligate you
     548 +to collect a royalty for further conveying from those to whom you convey
     549 +the Program, the only way you could satisfy both those terms and this
     550 +License would be to refrain entirely from conveying the Program.
    209 551   
    210  -If any portion of this section is held invalid or unenforceable under
    211  -any particular circumstance, the balance of the section is intended to
    212  -apply and the section as a whole is intended to apply in other
    213  -circumstances.
     552 + 13. Use with the GNU Affero General Public License.
    214 553   
    215  -It is not the purpose of this section to induce you to infringe any
    216  -patents or other property right claims or to contest validity of any
    217  -such claims; this section has the sole purpose of protecting the
    218  -integrity of the free software distribution system, which is
    219  -implemented by public license practices. Many people have made
    220  -generous contributions to the wide range of software distributed
    221  -through that system in reliance on consistent application of that
    222  -system; it is up to the author/donor to decide if he or she is willing
    223  -to distribute software through any other system and a licensee cannot
    224  -impose that choice.
    225  - 
    226  -This section is intended to make thoroughly clear what is believed to
    227  -be a consequence of the rest of this License.
     554 + Notwithstanding any other provision of this License, you have
     555 +permission to link or combine any covered work with a work licensed
     556 +under version 3 of the GNU Affero General Public License into a single
     557 +combined work, and to convey the resulting work. The terms of this
     558 +License will continue to apply to the part which is the covered work,
     559 +but the special requirements of the GNU Affero General Public License,
     560 +section 13, concerning interaction through a network will apply to the
     561 +combination as such.
    228 562   
    229  - 8. If the distribution and/or use of the Program is restricted in
    230  -certain countries either by patents or by copyrighted interfaces, the
    231  -original copyright holder who places the Program under this License
    232  -may add an explicit geographical distribution limitation excluding
    233  -those countries, so that distribution is permitted only in or among
    234  -countries not thus excluded. In such case, this License incorporates
    235  -the limitation as if written in the body of this License.
     563 + 14. Revised Versions of this License.
    236 564   
    237  - 9. The Free Software Foundation may publish revised and/or new versions
    238  -of the General Public License from time to time. Such new versions will
     565 + The Free Software Foundation may publish revised and/or new versions of
     566 +the GNU General Public License from time to time. Such new versions will
    239 567  be similar in spirit to the present version, but may differ in detail to
    240 568  address new problems or concerns.
    241 569   
    242  -Each version is given a distinguishing version number. If the Program
    243  -specifies a version number of this License which applies to it and "any
    244  -later version", you have the option of following the terms and conditions
    245  -either of that version or of any later version published by the Free
    246  -Software Foundation. If the Program does not specify a version number of
    247  -this License, you may choose any version ever published by the Free Software
    248  -Foundation.
     570 + Each version is given a distinguishing version number. If the
     571 +Program specifies that a certain numbered version of the GNU General
     572 +Public License "or any later version" applies to it, you have the
     573 +option of following the terms and conditions either of that numbered
     574 +version or of any later version published by the Free Software
     575 +Foundation. If the Program does not specify a version number of the
     576 +GNU General Public License, you may choose any version ever published
     577 +by the Free Software Foundation.
     578 + 
     579 + If the Program specifies that a proxy can decide which future
     580 +versions of the GNU General Public License can be used, that proxy's
     581 +public statement of acceptance of a version permanently authorizes you
     582 +to choose that version for the Program.
     583 + 
     584 + Later license versions may give you additional or different
     585 +permissions. However, no additional obligations are imposed on any
     586 +author or copyright holder as a result of your choosing to follow a
     587 +later version.
     588 + 
     589 + 15. Disclaimer of Warranty.
     590 + 
     591 + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
     592 +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
     593 +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
     594 +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
     595 +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     596 +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
     597 +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
     598 +ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
    249 599   
    250  - 10. If you wish to incorporate parts of the Program into other free
    251  -programs whose distribution conditions are different, write to the author
    252  -to ask for permission. For software which is copyrighted by the Free
    253  -Software Foundation, write to the Free Software Foundation; we sometimes
    254  -make exceptions for this. Our decision will be guided by the two goals
    255  -of preserving the free status of all derivatives of our free software and
    256  -of promoting the sharing and reuse of software generally.
     600 + 16. Limitation of Liability.
    257 601   
    258  - NO WARRANTY
     602 + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
     603 +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
     604 +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
     605 +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
     606 +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
     607 +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
     608 +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
     609 +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
     610 +SUCH DAMAGES.
    259 611   
    260  - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
    261  -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
    262  -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
    263  -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
    264  -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    265  -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
    266  -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
    267  -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
    268  -REPAIR OR CORRECTION.
     612 + 17. Interpretation of Sections 15 and 16.
    269 613   
    270  - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
    271  -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
    272  -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
    273  -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
    274  -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
    275  -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
    276  -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
    277  -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
    278  -POSSIBILITY OF SUCH DAMAGES.
     614 + If the disclaimer of warranty and limitation of liability provided
     615 +above cannot be given local legal effect according to their terms,
     616 +reviewing courts shall apply local law that most closely approximates
     617 +an absolute waiver of all civil liability in connection with the
     618 +Program, unless a warranty or assumption of liability accompanies a
     619 +copy of the Program in return for a fee.
    279 620   
    280 621   END OF TERMS AND CONDITIONS
    281 622   
    skipped 5 lines
    287 628   
    288 629   To do so, attach the following notices to the program. It is safest
    289 630  to attach them to the start of each source file to most effectively
    290  -convey the exclusion of warranty; and each file should have at least
     631 +state the exclusion of warranty; and each file should have at least
    291 632  the "copyright" line and a pointer to where the full notice is found.
    292 633   
    293  - {description}
    294  - Copyright (C) {year} {fullname}
     634 + cfonts - This is a silly little command line tool for sexy fonts in the console. Give your cli some love.
     635 + Copyright (C) 2022 Dominik Wilkowski
    295 636   
    296  - This program is free software; you can redistribute it and/or modify
     637 + This program is free software: you can redistribute it and/or modify
    297 638   it under the terms of the GNU General Public License as published by
    298  - the Free Software Foundation; either version 2 of the License, or
     639 + the Free Software Foundation, either version 3 of the License, or
    299 640   (at your option) any later version.
    300 641   
    301 642   This program is distributed in the hope that it will be useful,
    skipped 1 lines
    303 644   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    304 645   GNU General Public License for more details.
    305 646   
    306  - You should have received a copy of the GNU General Public License along
    307  - with this program; if not, write to the Free Software Foundation, Inc.,
    308  - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
     647 + You should have received a copy of the GNU General Public License
     648 + along with this program. If not, see <https://www.gnu.org/licenses/>.
    309 649   
    310 650  Also add information on how to contact you by electronic and paper mail.
    311 651   
    312  -If the program is interactive, make it output a short notice like this
    313  -when it starts in an interactive mode:
     652 + If the program does terminal interaction, make it output a short
     653 +notice like this when it starts in an interactive mode:
    314 654   
    315  - Gnomovision version 69, Copyright (C) year name of author
    316  - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
     655 + cfonts Copyright (C) 2022 Dominik Wilkowski
     656 + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
    317 657   This is free software, and you are welcome to redistribute it
    318 658   under certain conditions; type `show c' for details.
    319 659   
    320 660  The hypothetical commands `show w' and `show c' should show the appropriate
    321  -parts of the General Public License. Of course, the commands you use may
    322  -be called something other than `show w' and `show c'; they could even be
    323  -mouse-clicks or menu items--whatever suits your program.
     661 +parts of the General Public License. Of course, your program's commands
     662 +might be different; for a GUI interface, you would use an "about box".
    324 663   
    325  -You should also get your employer (if you work as a programmer) or your
    326  -school, if any, to sign a "copyright disclaimer" for the program, if
    327  -necessary. Here is a sample; alter the names:
    328  - 
    329  - Yoyodyne, Inc., hereby disclaims all copyright interest in the program
    330  - `Gnomovision' (which makes passes at compilers) written by James Hacker.
     664 + You should also get your employer (if you work as a programmer) or school,
     665 +if any, to sign a "copyright disclaimer" for the program, if necessary.
     666 +For more information on this, and how to apply and follow the GNU GPL, see
     667 +<https://www.gnu.org/licenses/>.
    331 668   
    332  - {signature of Ty Coon}, 1 April 1989
    333  - Ty Coon, President of Vice
     669 + The GNU General Public License does not permit incorporating your program
     670 +into proprietary programs. If your program is a subroutine library, you
     671 +may consider it more useful to permit linking proprietary applications with
     672 +the library. If this is what you want to do, use the GNU Lesser General
     673 +Public License instead of this License. But first, please read
     674 +<https://www.gnu.org/licenses/why-not-lgpl.html>.
    334 675   
    335  -This General Public License does not permit incorporating your program into
    336  -proprietary programs. If your program is a subroutine library, you may
    337  -consider it more useful to permit linking proprietary applications with the
    338  -library. If this is what you want to do, use the GNU Lesser General
    339  -Public License instead of this License.
  • ■ ■ ■ ■ ■ ■
    README.md
    1  -```shell
     1 +```sh
    2 2   ██████╗ ███████╗ ██████╗ ███╗ ██╗ ████████╗ ███████╗
    3 3   ██╔════╝ ██╔════╝ ██╔═══██╗ ████╗ ██║ ╚══██╔══╝ ██╔════╝
    4 4   ██║ █████╗ ██║ ██║ ██╔██╗ ██║ ██║ ███████╗
    skipped 2 lines
    7 7   ╚═════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═╝ ╚══════╝
    8 8  ```
    9 9   
    10  -![cfont styles](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/example1.png)
     10 +![cfont styles](./img/example1.png)
    11 11   
    12  - 
    13  -<p align="center"><img src="https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/example2.png" alt="api example"></p>
    14  -<p align="center"><a href="https://nodei.co/npm/cfonts/"><img src="https://nodei.co/npm/cfonts.png?downloads=true" alt="npm status"></a></p>
     12 +<p align="center"><img src="./img/example2.png" alt="api example"></p>
    15 13  <p align="center">
    16  - <a href="https://travis-ci.org/dominikwilkowski/cfonts"><img src="https://travis-ci.org/dominikwilkowski/cfonts.svg?branch=released" alt="build status"></a>
    17  - <a href='https://coveralls.io/github/dominikwilkowski/cfonts?branch=released'><img src='https://coveralls.io/repos/github/dominikwilkowski/cfonts/badge.svg?branch=released' alt='CFont Coverage Status' /></a>
     14 + <a href="https://crates.io/crates/cfonts"><img src="https://img.shields.io/crates/v/cfonts.svg" alt="crates badge"></a>
     15 + <a href="https://crates.io/crates/cfonts"><img src="https://docs.rs/cfonts/badge.svg" alt="crates docs tests"></a>
     16 + <a href="https://github.com/dominikwilkowski/cfonts/actions/workflows/testing.yml"><img src="https://github.com/dominikwilkowski/cfonts/actions/workflows/testing.yml/badge.svg" alt="build status"></a>
     17 + <a href="https://www.npmjs.com/package/cfonts"><img alt="npm" src="https://img.shields.io/npm/v/cfonts"></a>
     18 + <a href='https://coveralls.io/github/dominikwilkowski/cfonts?branch=released'><img src='https://coveralls.io/repos/github/dominikwilkowski/cfonts/badge.svg?branch=released' alt='cfonts Coverage Status' /></a>
    18 19  </p>
    19 20   
    20 21  <p align="center">This is a silly little command line tool for sexy fonts in the console. <strong>Give your cli some love.</strong></p>
    21 22   
    22  -## Installing
     23 +## Platforms
     24 + 
     25 +### Rust
     26 + 
     27 +Read more in the [Rust folder](./rust).
     28 + 
     29 +### Nodejs
     30 + 
     31 +Read more in the [Nodejs folder](./nodejs).
     32 + 
    23 33   
    24  -To install the CLI app, simply NPM install it globally.
     34 +## Install
     35 +<!--
     36 +<details>
     37 +<summary><h3>Unix<h3></summary>
    25 38   
    26  -```shell
    27  -$ npm install cfonts -g
     39 +#### [snapcraft](https://snapcraft.io/cfonts)
     40 + 
     41 +```sh
     42 +sudo snap install cfonts
    28 43  ```
    29 44   
    30  -To use it in your shell:
     45 +#### [MacPorts](https://ports.macports.org/port/cfonts/)
    31 46   
    32  -```shell
    33  -$ cfonts "Hello|World\!"
     47 +```sh
     48 +sudo port install cfonts
    34 49  ```
    35 50   
    36  -_Remember to escape the `!` character with `\` in the shell_
     51 +#### [Alpine Linux repository](https://pkgs.alpinelinux.org/packages?name=cfonts)
    37 52   
    38  -Or use it in your project:
     53 +_💡 The correct repository (see above link for the most up-to-date information) should be enabled before `apk add`._
    39 54   
    40  -```js
    41  -const CFonts = require('cfonts');
     55 +```sh
     56 +sudo apk add cfonts
     57 +```
    42 58   
    43  -CFonts.say('Hello|world!', {
    44  - font: 'block', // define the font face
    45  - align: 'left', // define text alignment
    46  - colors: ['system'], // define all colors
    47  - background: 'transparent', // define the background color, you can also use `backgroundColor` here as key
    48  - letterSpacing: 1, // define letter spacing
    49  - lineHeight: 1, // define the line height
    50  - space: true, // define if the output text should have empty lines on top and on the bottom
    51  - maxLength: '0', // define how many character can be on one line
    52  - gradient: false, // define your two gradient colors
    53  - independentGradient: false, // define if you want to recalculate the gradient for each new line
    54  - transitionGradient: false, // define if this is a transition between colors directly
    55  - env: 'node' // define the environment CFonts is being executed in
    56  -});
     59 +#### [Arch Linus User repository](https://aur.archlinux.org/packages/cfonts)
     60 + 
     61 +```sh
     62 +sudo pacman -S cfonts
    57 63  ```
    58 64   
    59  -_All settings are optional and shown here with their default_
     65 +#### [Scoop](https://scoop.sh/)
     66 + 
     67 +```sh
     68 +scoop install cfonts
     69 +```
    60 70   
    61  -You can use CFonts in your project without the direct output to the console:
     71 +#### Fedora
    62 72   
    63  -```js
    64  -const CFonts = require('cfonts');
     73 +```sh
     74 +sudo dnf install cfonts
     75 +```
    65 76   
    66  -const prettyFont = CFonts.render('Hello|world!', {/* same settings object as above */});
     77 +#### RPM
    67 78   
    68  -prettyFont.string // the ansi string for sexy console font
    69  -prettyFont.array // returns the array for the output
    70  -prettyFont.lines // returns the lines used
    71  -prettyFont.options // returns the options used
     79 +```sh
     80 +TODO
     81 +```
     82 + 
     83 +</details>
     84 + 
     85 +### [homebrew](https://formulae.brew.sh/formula/cfonts)
     86 + 
     87 +```sh
     88 +brew install cfonts
     89 +```
     90 +-->
     91 +### [cargo](https://crates.io/crates/cfonts)
     92 + 
     93 +```sh
     94 +cargo install cfonts
     95 +```
     96 + 
     97 +### [npm](https://www.npmjs.com/package/cfonts)
     98 + 
     99 +```sh
     100 +npm i cfonts -g
     101 +```
     102 + 
     103 +### [yarn](https://yarnpkg.com/package/cfonts)
     104 + 
     105 +```sh
     106 +yarn global add cfonts
    72 107  ```
    73 108   
    74 109   
    skipped 8 lines
    83 118  At any point you can run the *help* command to get a full list of commands and
    84 119  how to use them.
    85 120   
    86  -```shell
     121 +```sh
    87 122  $ cfonts --help
    88 123  ```
    89 124   
    skipped 29 lines
    119 154   
    120 155  This shows a list of all available options.
    121 156   
    122  -```shell
     157 +```sh
    123 158  $ cfonts --help
    124 159  ```
    125 160   
    126  -![Help command](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/help.png)
     161 +![Help command](./img/help.png)
    127 162   
    128 163   
    129 164  #### -V, --version
    skipped 2 lines
    132 167   
    133 168  This shows the installed version.
    134 169   
    135  -```shell
     170 +```sh
    136 171  $ cfonts --version
    137 172  ```
    138 173   
    139  -![Version command](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/version.png)
     174 +![Version command](./img/version.png)
    140 175   
    141 176   
    142 177  #### text
    skipped 3 lines
    146 181  This is the "text input" to be converted into a nice font.
    147 182  The `|` character will be replaced with a line break.
    148 183   
    149  -```shell
     184 +```sh
    150 185  $ cfonts "Hello world"
    151 186  ```
    152 187   
    153  -![Text command](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/text.png)
     188 +![Text command](./img/text.png)
    154 189   
    155 190   
    156 191  #### -f, --font
    skipped 2 lines
    159 194   
    160 195  This is the font face you want to use. So far this plugin ships with with following font faces:
    161 196   
    162  -```shell
     197 +```sh
    163 198  $ cfonts "text" --font "chrome"
    164 199  ```
    165 200   
    166  -![Font command](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/font.png)
     201 +![Font command](./img/font.png)
    167 202   
    168 203  - `block` [colors: 2] _(default)_
    169  - ![block font style](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/block.png)
     204 + ![block font style](./img/block.png)
    170 205  - `slick` [colors: 2]
    171  - ![slick font style](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/slick.png)
     206 + ![slick font style](./img/slick.png)
    172 207  - `tiny` [colors: 1]
    173  - ![tiny font style](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/tiny.png)
     208 + ![tiny font style](./img/tiny.png)
    174 209  - `grid` [colors: 2]
    175  - ![grid font style](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/grid.png)
     210 + ![grid font style](./img/grid.png)
    176 211  - `pallet` [colors: 2]
    177  - ![pallet font style](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/pallet.png)
     212 + ![pallet font style](./img/pallet.png)
    178 213  - `shade` [colors: 2]
    179  - ![shade font style](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/shade.png)
     214 + ![shade font style](./img/shade.png)
    180 215  - `chrome` [colors: 3]
    181  - ![chrome font style](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/chrome.png)
     216 + ![chrome font style](./img/chrome.png)
    182 217  - `simple` [colors: 1]
    183  - ![simple font style](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/simple.png)
     218 + ![simple font style](./img/simple.png)
    184 219  - `simpleBlock` [colors: 1]
    185  - ![simple-block font style](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/simple-block.png)
     220 + ![simple-block font style](./img/simple-block.png)
    186 221  - `3d` [colors: 2]
    187  - ![3d font style](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/3d.png)
     222 + ![3d font style](./img/3d.png)
    188 223  - `simple3d` [colors: 1]
    189  - ![simple-3d font style](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/simple-3d.png)
     224 + ![simple-3d font style](./img/simple-3d.png)
    190 225  - `huge` [colors: 2]
    191  - ![huge font style](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/huge.png)
     226 + ![huge font style](./img/huge.png)
    192 227  - `console` [colors: 1]
    193  - ![console font style](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/console.png)
     228 + ![console font style](./img/console.png)
    194 229   
    195 230   
    196 231  #### -a, --align
    skipped 8 lines
    205 240  - `top` _(Will be ignored if used with the spaceless option)_
    206 241  - `bottom` _(Will be ignored if used with the spaceless option)_
    207 242   
    208  -```shell
     243 +```sh
    209 244  $ cfonts "text" --align "center"
    210 245  ```
    211 246   
    212  -![Align command](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/align.png)
     247 +![Align command](./img/align.png)
    213 248   
    214 249   
    215 250  #### -c, --colors
    skipped 1 lines
    217 252  Default value: `['system']`
    218 253   
    219 254  With this setting you can set the colors for your font.
    220  -Use the below color strings built in by [chalk](https://github.com/chalk/chalk) or a hex color.
     255 +Use the below color strings or a hex color.
    221 256  Provide colors in a comma-separated string, eg: `red,blue`. _(no spaces)_
    222  -If you use a hex color make sure you include the `#` prefix. _(In the terminal wrap the hex in quotes)_
     257 +If you use a hex color make sure you include the `#` prefix. _(In most terminals wrap the hex in quotes)_
    223 258  The `system` color falls back to the system color of your terminal.
     259 + 
     260 +💡 There are [environment variables](#consistency) that can effect the display of colors in your terminal.
    224 261   
    225 262  - `system` _(default)_
    226 263  - `black`
    skipped 15 lines
    242 279  - `#ff8800` _(any valid hex color)_
    243 280  - `#f80` _(short form is supported as well)_
    244 281   
    245  -```shell
     282 +```sh
    246 283  $ cfonts "text" --colors white,"#f80"
    247 284  ```
    248 285   
    249  -![Colors command](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/colors.png)
     286 +![Colors command](./img/colors.png)
    250 287   
    251 288   
    252 289  #### -g, --gradient
    skipped 4 lines
    257 294  This setting supersedes the color open.
    258 295  The gradient requires two colors, a start color and an end color from left to right.
    259 296  _(If you want to set your own colors for the gradient, use the [transition](#-t---transition-gradient) option.)_
    260  -CFonts will then generate a gradient through as many colors as it can find to make the output most impressive.
     297 +`cfonts` will then generate a gradient through as many colors as it can find to make the output most impressive.
    261 298  Provide two colors in a comma-separated string, eg: `red,blue`. _(no spaces)_
    262 299  If you use a hex color make sure you include the `#` prefix. _(In the terminal wrap the hex in quotes)_
    263 300   
    skipped 10 lines
    274 311  - `#ff8800` _(any valid hex color)_
    275 312  - `#f80` _(short form is supported as well)_
    276 313   
    277  -```shell
     314 +```sh
    278 315  $ cfonts "text" --gradient red,"#f80"
    279 316  ```
    280 317   
    281  -![Gradient command](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/gradient.png)
     318 +![Gradient command](./img/gradient.png)
    282 319   
    283 320   
    284 321  #### -i, --independent-gradient
    skipped 3 lines
    288 325  Set this option to re-calculate the gradient colors for each new line.
    289 326  Only works in combination with the [gradient](#-g---gradient) option.
    290 327   
    291  -```shell
     328 +```sh
    292 329  $ cfonts "text|next line" --gradient red,"#f80" --independent-gradient
    293 330  ```
    294 331   
    295  -![Independent gradient command](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/independent-gradient.png)
     332 +![Independent gradient command](./img/independent-gradient.png)
    296 333   
    297 334   
    298 335  #### -t, --transition-gradient
    skipped 5 lines
    304 341  This option allows you to specify more than just two colors for your gradient.
    305 342  Only works in combination with the [gradient](#-g---gradient) option.
    306 343   
    307  -```shell
     344 +```sh
    308 345  $ cfonts "text" --gradient red,"#f80",green,blue --transition-gradient
    309 346  ```
    310 347   
    311  -![Independent gradient command](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/transition-gradient.png)
     348 +![Independent gradient command](./img/transition-gradient.png)
    312 349   
    313 350   
    314 351  #### -b, --background
    315 352  Type: `<string>`
    316 353  Default value: `"transparent"`
    317 354   
    318  -With this setting you can set the background colors for the output. Use the below color strings built in by [chalk](https://github.com/chalk/chalk).
     355 +With this setting you can set the background colors for the output. Use the below color strings.
    319 356  Provide the background color from the below supported list, eg: 'white'
    320 357   
    321 358  - `transparent` _(default)_
    skipped 13 lines
    335 372  - `magentaBright`
    336 373  - `cyanBright`
    337 374  - `whiteBright`
     375 +- `#ff8800` _(any valid hex color)_
     376 +- `#f80` _(short form is supported as well)_
    338 377   
    339  -```shell
     378 +```sh
    340 379  $ cfonts "text" --background "Green"
    341 380  ```
    342 381   
    343  -![Background command](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/background.png)
     382 +![Background command](./img/background.png)
    344 383   
    345 384   
    346 385  #### -l, --letter-spacing
    skipped 2 lines
    349 388   
    350 389  Set this option to widen the space between characters.
    351 390   
    352  -```shell
     391 +```sh
    353 392  $ cfonts "text" --letter-spacing 2
    354 393  ```
    355 394   
    356  -![Letter spacing command](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/letter-spacing.png)
     395 +![Letter spacing command](./img/letter-spacing.png)
    357 396   
    358 397   
    359 398  #### -z, --line-height
    skipped 2 lines
    362 401   
    363 402  Set this option to widen the space between lines.
    364 403   
    365  -```shell
     404 +```sh
    366 405  $ cfonts "text" --line-height 2
    367 406  ```
    368 407   
    369  -![Line height command](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/line-height.png)
     408 +![Line height command](./img/line-height.png)
    370 409   
    371 410   
    372 411  #### -s, --spaceless
    skipped 2 lines
    375 414   
    376 415  Set this option to false if you don't want the plugin to insert two empty lines on top and on the bottom of the output.
    377 416   
    378  -```shell
     417 +```sh
    379 418  $ cfonts "text" --spaceless
    380 419  ```
    381 420   
    382  -![Spaceless command](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/spaceless.png)
     421 +![Spaceless command](./img/spaceless.png)
    383 422   
    384 423   
    385 424  #### -m, --max-length
    skipped 1 lines
    387 426  Default value: `0`
    388 427   
    389 428  This option sets the maximum characters that will be printed on one line.
    390  -CFonts detects the size of your terminal but you can opt out and determine your own max width.
     429 +`cfonts` detects the size of your terminal but you can opt out and determine your own max width.
    391 430  `0` means no max width and the text will break at the edge of the terminal window.
    392 431   
    393  -```shell
     432 +```sh
    394 433  $ cfonts "text" --max-length 15
    395 434  ```
    396 435   
    397  -![Max length command](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/max-length.png)
     436 +![Max length command](./img/max-length.png)
    398 437   
    399 438   
    400 439  #### -e, --env
    401 440  Type: `<string>`
    402  -Default value: `node`
     441 +Default value: `cli`
    403 442   
    404  -This option lets you use CFonts to generate HTML instead of ANSI code.
    405  -Note that `max-length` won't be automatically detected anymore and you will have to supply it if you want the text to wrap.
    406  -Best used in a node script.
     443 +This option lets you use `cfonts` to generate HTML instead of ANSI code.
     444 +Note that `max-length` will be set to very large.
    407 445   
    408  -```js
    409  -const CFonts = require('cfonts');
    410  -const path = require('path');
    411  -const fs = require('fs');
    412  - 
    413  -const output = CFonts.render('My text', {
    414  - colors: ['white'],
    415  - gradient: ['cyan', 'red'],
    416  - background: 'black',
    417  - space: false,
    418  - env: 'browser',
    419  -});
    420  - 
    421  -fs.writeFileSync(
    422  - path.normalize(`${ __dirname }/test.html`),
    423  - output.string,
    424  - {
    425  - encoding: 'utf8',
    426  - }
    427  -);
     446 +```sh
     447 +$ cfonts "text" --env browser
    428 448  ```
    429 449   
    430  -![Max length command](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/env.png)
     450 +![Max length command](./img/env.png)
    431 451   
    432 452   
    433 453  ## Consistency
    434  -[Chalk](https://github.com/chalk/chalk) detects what colors are supported on your platform.
    435  -It sets a [level of support](https://github.com/chalk/chalk#256-and-truecolor-color-support) automatically.
    436  -In CFonts you can override this by passing in the `FORCE_COLOR` environment variable.
     454 +`cfonts` detects what colors are supported on your platform.
     455 +It sets a level of support automatically.
     456 +In `cfonts` you can override this by passing in the `FORCE_COLOR` environment variable.
    437 457   
    438  -```shell
     458 +```sh
    439 459  FORCE_COLOR=3 cfonts "hello world" -c "#0088ff"
    440 460  ```
    441 461   
    442  -## Contributing
    443  -To build the repo install dependencies via:
    444  -_(Since we ship a `yarn.lock` file please use [`yarn`](https://yarnpkg.com/) for development.)_
    445  - 
    446  -```shell
    447  -yarn
    448  -```
    449  - 
    450  -and run the watch to continuously transpile the code.
    451  - 
    452  -```shell
    453  -yarn watch
    454  -```
    455  - 
    456  -Please look at the coding style and work with it, not against it ;)
    457  - 
    458  - 
    459  -## Tests
    460  -This package is tested on the below platform and node combinations as part of our [CI](https://github.com/dominikwilkowski/cfonts/tree/released/.travis.yml).
    461  - 
    462  -| Platform | Node |
    463  -|----------|--------|
    464  -| Linux | v10 |
    465  -| Linux | v12 |
    466  -| Linux | latest |
    467  -| OSX | v10 |
    468  -| OSX | v12 |
    469  -| OSX | latest |
    470  -| Windows | v10 |
    471  -| Windows | v12 |
    472  -| Windows | latest |
    473  - 
    474  -### Unit tests
    475  -The package comes with a bunch of [unit tests](https://github.com/dominikwilkowski/cfonts/tree/released/test/unit) that aim to cover 100% of the code base.
    476  -For more details about the code coverage check out [coveralls](https://coveralls.io/github/dominikwilkowski/cfonts?branch=released).
    477  - 
    478  -```shell
    479  -npm run test:unit
    480  -```
    481  - 
    482  -### Type tests
    483  -Since the code base uses [JSDocs](https://jsdoc.app/) we use [typescript](https://www.typescriptlang.org/) to test the inferred types from those comments.
    484  -Typescript [supports JSDocs](https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html#supported-jsdoc) and we use it in our
    485  -[test](https://github.com/dominikwilkowski/cfonts/blob/released/package.json#L38).
     462 +You can also use the `NO_COLOR` environment variable to set no color output for environments like CI.
    486 463   
    487  -```shell
    488  -npm run test:types
     464 +```sh
     465 +NO_COLOR="" cfonts "hello world" -c "#0088ff"
    489 466  ```
    490 467   
    491  -### Font file test
    492  -There is also a [test suite](https://github.com/dominikwilkowski/cfonts/blob/released/test/fonttest.js) for font files.
     468 +💡 `FORCE_COLOR` overrides `NO_COLOR` if both are set.
    493 469   
    494  -```shell
    495  -npm run test:fonts
    496  -```
    497  - 
    498  -This tool checks:
    499  -- the existence of the font
    500  -- all attributes of a font
    501  -- each character for:
    502  - - existence
    503  - - consistent width
    504  - - consistent lines
    505  - 
    506  -### All tests
    507  -Run all tests via:
    508  - 
    509  -```shell
    510  -npm run test
    511  -```
    512  - 
    513  - 
    514  -## Release History
    515  -* 2.10.1 - bumped dependencies
    516  -* 2.10.0 - bumped dependencies, added typescript definitions into npm bundle
    517  -* 2.9.3 - bumped dependencies
    518  -* 2.9.2 - bumped dependencies
    519  -* 2.9.1 - bumped dependencies
    520  -* 2.9.0 - added `top` and `bottom` align options
    521  -* 2.8.6 - bumped dependencies
    522  -* 2.8.5 - renamed branches
    523  -* 2.8.4 - fixed block double quote
    524  -* 2.8.3 - bumped dependencies
    525  -* 2.8.2 - bumped dependencies, added linting, fixed #22 (again)
    526  -* 2.8.1 - bumped dependencies
    527  -* 2.8.0 - added environment support, added font `tiny`
    528  -* 2.7.0 - added font `slick`, `grid` and `pallet`, added double quote to all fonts
    529  -* 2.6.1 - fixed console `maxLength`, `gradient` and `lineHeight`, added more end-to-end tests
    530  -* 2.6.0 - added transition gradients and sets
    531  -* 2.5.2 - fixed jsDocs, added typescript type test
    532  -* 2.5.1 - fixed array output to include everything including colors
    533  -* 2.5.0 - added gradient option, separated code into files, added 100% unit testing coverage
    534  -* 2.4.8 - removed `ansi-styles` from direct dependencies
    535  -* 2.4.7 - fixed bug from adopting chalk v3 and hex colors
    536  -* 2.4.6 - bumped dependencies, removed `change-case` dependency, added `UpperCaseFirst` with tests
    537  -* 2.4.5 - bumped dependencies, moved to relative links for fonts for webpack support (#22)
    538  -* 2.4.4 - bumped dependencies
    539  -* 2.4.3 - bumped dependencies
    540  -* 2.4.2 - bumped dependencies
    541  -* 2.4.1 - updated to babel 7, removed runtime from dependencies
    542  -* 2.4.0 - added font `shade`, added hex color support
    543  -* 2.3.1 - added tests, fixed options, updated dependencies
    544  -* 2.3.0 - added apostrophe support in all fonts
    545  -* 2.2.3 - bumped dependencies
    546  -* 2.2.2 - bumped dependencies
    547  -* 2.2.1 - bumped dependencies
    548  -* 2.2.0 - inside the API you can use line breaks as well as the pipe
    549  -* 2.1.3 - refactored some loops
    550  -* 2.1.2 - made WinSize more robust
    551  -* 2.1.1 - fixed size detection in non-tty environments
    552  -* 2.1.0 - rebuilt cfonts with pure functions, made colors case-insensitive
    553  -* 2.0.1 - fixed terminal width detection
    554  -* 2.0.0 - added tests, split into more pure functions
    555  -* 1.2.0 - added `transparent` and `system` as default background and color option, added `backgroundColor` as alias for `background`, upgraded deps
    556  -* 1.1.3 - fixed help text, removing old -t option
    557  -* 1.1.2 - fixed issue with older commander version #3, updated docs
    558  -* 1.1.1 - moved from `babel-polyfill` to `babel-plugin-transform-runtime`, added files to package.json, added images to docs, fixed dependencies
    559  -* 1.1.0 - transpiled code to support node 0.12.15 and up
    560  -* 1.0.2 - fixed background in `console` font, added comma, added font `huge`, added render method, added candy color
    561  -* 1.0.1 - added `chrome` font, fonttest
    562  -* 1.0.0 - refactor, added alignment and line height option, new cli commands, added `simpleBlock`
    563  -* 0.0.13 - fixed `simple3d`
    564  -* 0.0.12 - fixed `simple3d` and added to grunt test
    565  -* 0.0.11 - added `simple3d` font
    566  -* 0.0.10 - added npmignore, added to docs
    567  -* 0.0.9 - added `console` font
    568  -* 0.0.8 - fixed bugs, docs
    569  -* 0.0.7 - changed to settings object
    570  -* 0.0.6 - added `3d` font
    571  -* 0.0.5 - added grunt test
    572  -* 0.0.4 - fixed `simple` font
    573  -* 0.0.3 - fixes, added `simple` font
    574  -* 0.0.2 - fixed paths
    575  -* 0.0.1 - alpha test
     470 +![Color consistency via env vars](./img/color-consistency.png)
    576 471   
    577 472   
    578 473  ## License
    579  -Copyright (c) 2018 Dominik Wilkowski. Licensed under the [GNU GPLv2](https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE).
     474 +Copyright (c) 2022 Dominik Wilkowski.
     475 +Licensed under the [GNU GPLv3](https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE).
    580 476   
  • ■ ■ ■ ■ ■ ■
    cfonts.sublime-project
     1 +{
     2 + "folders":
     3 + [
     4 + {
     5 + "follow_symlinks": true,
     6 + "path": "."
     7 + }
     8 + ],
     9 + "settings": {
     10 + "todoreview": {
     11 + "exclude_folders": [
     12 + "*.git*",
     13 + "**/node_modules/**"
     14 + ]
     15 + }
     16 + }
     17 +}
     18 + 
  • ■ ■ ■ ■ ■
    fonts/3d.json
    1 1  {
    2 2   "name": "3D",
    3  - "version": "0.1.1",
     3 + "version": "0.2.0",
    4 4   "homepage": "https://github.com/dominikwilkowski/cfonts",
    5 5   "colors": 2,
    6 6   "lines": 9,
    skipped 19 lines
    26 26   "<c2>_</c2>",
    27 27   "<c2>_</c2>"
    28 28   ],
     29 + "letterspace_size": 1,
    29 30   "chars": {
    30 31   "A": [
    31 32   "<c2>____</c2><c1>/\\\\\\\\\\\\\\\\\\</c1><c2>___</c2>",
    skipped 628 lines
  • ■ ■ ■ ■ ■
    fonts/block.json
    1 1  {
    2 2   "name": "block",
    3  - "version": "0.1.1",
     3 + "version": "0.2.0",
    4 4   "homepage": "https://github.com/dominikwilkowski/cfonts",
    5 5   "colors": 2,
    6 6   "lines": 6,
    skipped 13 lines
    20 20   " ",
    21 21   " "
    22 22   ],
     23 + "letterspace_size": 1,
    23 24   "chars": {
    24 25   "A": [
    25 26   " <c1>█████</c1><c2>╗</c2> ",
    skipped 457 lines
  • ■ ■ ■ ■ ■
    fonts/chrome.json
    1 1  {
    2 2   "name": "chrome",
    3  - "version": "0.1.0",
     3 + "version": "0.2.0",
    4 4   "homepage": "https://github.com/dominikwilkowski/cfonts",
    5 5   "colors": 3,
    6 6   "lines": 3,
    skipped 6 lines
    13 13   " ",
    14 14   " ",
    15 15   " "
    16  - ],
     16 + ],
     17 + "letterspace_size": 1,
    17 18   "chars": {
    18 19   "A": [
    19 20   "<c1>╔═╗</c1>",
    skipped 286 lines
  • ■ ■ ■ ■ ■ ■
    fonts/console.json
     1 +{
     2 + "name": "console",
     3 + "version": "1.0.0",
     4 + "homepage": "https://github.com/dominikwilkowski/cfonts",
     5 + "colors": 1,
     6 + "lines": 1,
     7 + "buffer": [
     8 + ""
     9 + ],
     10 + "letterspace": [
     11 + ""
     12 + ],
     13 + "letterspace_size": 0,
     14 + "chars": {
     15 + "A": ["a"],
     16 + "B": ["b"],
     17 + "C": ["c"],
     18 + "D": ["d"],
     19 + "E": ["e"],
     20 + "F": ["f"],
     21 + "G": ["g"],
     22 + "H": ["h"],
     23 + "I": ["i"],
     24 + "J": ["j"],
     25 + "K": ["k"],
     26 + "L": ["l"],
     27 + "M": ["m"],
     28 + "N": ["n"],
     29 + "O": ["o"],
     30 + "P": ["p"],
     31 + "Q": ["q"],
     32 + "R": ["r"],
     33 + "S": ["s"],
     34 + "T": ["t"],
     35 + "U": ["u"],
     36 + "V": ["v"],
     37 + "W": ["w"],
     38 + "X": ["x"],
     39 + "Y": ["y"],
     40 + "Z": ["z"],
     41 + "0": ["0"],
     42 + "1": ["1"],
     43 + "2": ["2"],
     44 + "3": ["3"],
     45 + "4": ["4"],
     46 + "5": ["5"],
     47 + "6": ["6"],
     48 + "7": ["7"],
     49 + "8": ["8"],
     50 + "9": ["9"],
     51 + "!": ["!"],
     52 + "?": ["?"],
     53 + ".": ["."],
     54 + "+": ["+"],
     55 + "-": ["-"],
     56 + "_": ["_"],
     57 + "=": ["="],
     58 + "@": ["@"],
     59 + "#": ["#"],
     60 + "$": ["$"],
     61 + "%": ["%"],
     62 + "&": ["&"],
     63 + "(": ["("],
     64 + ")": [")"],
     65 + "/": ["/"],
     66 + ":": [":"],
     67 + ";": [";"],
     68 + ",": [","],
     69 + "'": ["'"],
     70 + "\"": ["\""],
     71 + " ": [" "]
     72 + }
     73 +}
     74 + 
  • ■ ■ ■ ■ ■
    fonts/grid.json
    1 1  {
    2 2   "name": "grid",
    3  - "version": "0.0.1",
     3 + "version": "0.1.0",
    4 4   "homepage": "https://github.com/dominikwilkowski/cfonts",
    5 5   "colors": 2,
    6 6   "lines": 6,
    skipped 13 lines
    20 20   "<c2>╋</c2>",
    21 21   "<c2>╋</c2>"
    22 22   ],
     23 + "letterspace_size": 1,
    23 24   "chars": {
    24 25   "A": [
    25 26   "<c2>╋╋╋╋</c2>",
    skipped 457 lines
  • ■ ■ ■ ■ ■
    fonts/huge.json
    1 1  {
    2 2   "name": "huge",
    3  - "version": "0.1.0",
     3 + "version": "0.2.0",
    4 4   "homepage": "https://github.com/dominikwilkowski/cfonts",
    5 5   "colors": 2,
    6 6   "lines": 11,
    skipped 22 lines
    29 29   " ",
    30 30   " ",
    31 31   " "
    32  - ],
     32 + ],
     33 + "letterspace_size": 1,
    33 34   "chars": {
    34 35   "A": [
    35 36   " <c1>▄▄▄▄▄▄▄▄▄▄▄</c1> ",
    skipped 742 lines
  • ■ ■ ■ ■ ■
    fonts/pallet.json
    1 1  {
    2 2   "name": "pallet",
    3  - "version": "0.0.1",
     3 + "version": "0.1.0",
    4 4   "homepage": "https://github.com/dominikwilkowski/cfonts",
    5 5   "colors": 2,
    6 6   "lines": 6,
    skipped 13 lines
    20 20   "<c2>─</c2>",
    21 21   "<c2>─</c2>"
    22 22   ],
     23 + "letterspace_size": 1,
    23 24   "chars": {
    24 25   "A": [
    25 26   "<c1>╔═══╗</c1>",
    skipped 457 lines
  • ■ ■ ■ ■ ■
    fonts/shade.json
    1 1  {
    2 2   "name": "shade",
    3  - "version": "0.1.0",
     3 + "version": "0.2.0",
    4 4   "homepage": "https://github.com/dominikwilkowski/cfonts",
    5 5   "colors": 2,
    6 6   "lines": 8,
    skipped 17 lines
    24 24   "<c2>░</c2>",
    25 25   "<c2>░</c2>"
    26 26   ],
     27 + "letterspace_size": 1,
    27 28   "chars": {
    28 29   "A": [
    29 30   "<c2>░░░░</c2>",
    skipped 571 lines
  • ■ ■ ■ ■ ■
    fonts/simple.json
    1 1  {
    2 2   "name": "simple",
    3  - "version": "0.1.0",
     3 + "version": "0.2.0",
    4 4   "homepage": "https://github.com/dominikwilkowski/cfonts",
    5 5   "colors": 1,
    6 6   "lines": 4,
    skipped 9 lines
    16 16   " ",
    17 17   " "
    18 18   ],
     19 + "letterspace_size": 1,
    19 20   "chars": {
    20 21   "A": [
    21 22   " _ ",
    skipped 343 lines
  • ■ ■ ■ ■ ■
    fonts/simple3d.json
    1 1  {
    2 2   "name": "simple3d",
    3  - "version": "0.1.0",
     3 + "version": "0.2.0",
    4 4   "homepage": "https://github.com/dominikwilkowski/cfonts",
    5 5   "colors": 1,
    6 6   "lines": 7,
    skipped 15 lines
    22 22   "",
    23 23   ""
    24 24   ],
     25 + "letterspace_size": 0,
    25 26   "chars": {
    26 27   "A": [
    27 28   " ",
    skipped 514 lines
  • ■ ■ ■ ■ ■
    fonts/simpleBlock.json
    1 1  {
    2 2   "name": "simpleBlock",
    3  - "version": "0.1.0",
     3 + "version": "0.2.0",
    4 4   "homepage": "https://github.com/dominikwilkowski/cfonts",
    5 5   "colors": 1,
    6 6   "lines": 7,
    skipped 14 lines
    21 21   " ",
    22 22   " ",
    23 23   " "
    24  - ],
     24 + ],
     25 + "letterspace_size": 1,
    25 26   "chars": {
    26 27   "A": [
    27 28   " ",
    skipped 514 lines
  • ■ ■ ■ ■ ■
    fonts/slick.json
    1 1  {
    2 2   "name": "slick",
    3  - "version": "0.0.1",
     3 + "version": "0.1.0",
    4 4   "homepage": "https://github.com/dominikwilkowski/cfonts",
    5 5   "colors": 2,
    6 6   "lines": 6,
    skipped 13 lines
    20 20   "<c2>╱</c2>",
    21 21   "<c2>╱</c2>"
    22 22   ],
     23 + "letterspace_size": 1,
    23 24   "chars": {
    24 25   "A": [
    25 26   "<c1>╭━━━╮</c1>",
    skipped 457 lines
  • ■ ■ ■ ■ ■
    fonts/tiny.json
    1 1  {
    2 2   "name": "tiny",
    3  - "version": "0.1.0",
     3 + "version": "0.2.0",
    4 4   "homepage": "https://github.com/dominikwilkowski/cfonts",
    5 5   "colors": 1,
    6 6   "lines": 2,
    skipped 4 lines
    11 11   "letterspace": [
    12 12   " ",
    13 13   " "
    14  - ],
     14 + ],
     15 + "letterspace_size": 1,
    15 16   "chars": {
    16 17   "A": [
    17 18   "▄▀█",
    skipped 229 lines
  • img/color-consistency.png
  • .babelrc nodejs/.babelrc
    Content is identical
  • ■ ■ ■ ■ ■
    .npmignore nodejs/.npmignore
    1 1  *.sublime-project
    2 2  *.sublime-workspace
    3  -img/
    4 3   
  • ■ ■ ■ ■ ■
    nodejs/.prettierignore
     1 +bin/
     2 +coverage/
     3 +fonts/
     4 +lib/
     5 + 
  • ■ ■ ■ ■ ■ ■
    nodejs/.prettierrc
     1 +{
     2 + proseWrap: 'preserve',
     3 + singleQuote: true,
     4 + trailingComma: 'es5',
     5 + useTabs: true,
     6 + printWidth: 120,
     7 +}
     8 + 
  • ■ ■ ■ ■ ■ ■
    nodejs/README.md
     1 +```sh
     2 + ██████╗ ███████╗ ██████╗ ███╗ ██╗ ████████╗ ███████╗
     3 + ██╔════╝ ██╔════╝ ██╔═══██╗ ████╗ ██║ ╚══██╔══╝ ██╔════╝
     4 + ██║ █████╗ ██║ ██║ ██╔██╗ ██║ ██║ ███████╗
     5 + ██║ ██╔══╝ ██║ ██║ ██║╚██╗██║ ██║ ╚════██║ ╔╗╔ ╔═╗ ╔╦╗ ╔═╗ ╦ ╔═╗
     6 + ╚██████╗ ██║ ╚██████╔╝ ██║ ╚████║ ██║ ███████║ ║║║ ║ ║ ║║ ║╣ ║ ╚═╗
     7 + ╚═════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═╝ ╚══════╝ ╝╚╝ ╚═╝ ═╩╝ ╚═╝ ╚╝ ╚═╝
     8 +```
     9 + 
     10 +![cfont styles](./img/example1.png)
     11 + 
     12 +<p align="center"><img src="./img/example2.png" alt="api example"></p>
     13 +<p align="center">
     14 + <a href="https://github.com/dominikwilkowski/cfonts/actions/workflows/testing.yml"><img src="https://github.com/dominikwilkowski/cfonts/actions/workflows/testing.yml/badge.svg" alt="build status"></a>
     15 + <a href="https://www.npmjs.com/package/cfonts"><img alt="npm" src="https://img.shields.io/npm/v/cfonts"></a>
     16 + <a href='https://coveralls.io/github/dominikwilkowski/cfonts?branch=released'><img src='https://coveralls.io/repos/github/dominikwilkowski/cfonts/badge.svg?branch=released' alt='cfonts Coverage Status' /></a>
     17 +</p>
     18 + 
     19 +<p align="center">This is a silly little command line tool for sexy fonts in the console. <strong>Give your cli some love.</strong></p>
     20 + 
     21 +## Installing
     22 + 
     23 +### [npm](https://www.npmjs.com/package/cfonts)
     24 + 
     25 +```sh
     26 +npm i cfonts -g
     27 +```
     28 + 
     29 +### [yarn](https://yarnpkg.com/package/cfonts)
     30 + 
     31 +```sh
     32 +yarn global add cfonts
     33 +```
     34 + 
     35 +To use it in your shell:
     36 + 
     37 +```sh
     38 +$ cfonts "Hello|World\!"
     39 +```
     40 + 
     41 +_💡 Remember to escape the `!` character with `\` in the shell_
     42 + 
     43 +Or use it in your project:
     44 + 
     45 +```js
     46 +const cfonts = require('cfonts');
     47 + 
     48 +cfonts.say('Hello|world!', {
     49 + font: 'block', // define the font face
     50 + align: 'left', // define text alignment
     51 + colors: ['system'], // define all colors
     52 + background: 'transparent', // define the background color, you can also use `backgroundColor` here as key
     53 + letterSpacing: 1, // define letter spacing
     54 + lineHeight: 1, // define the line height
     55 + space: true, // define if the output text should have empty lines on top and on the bottom
     56 + maxLength: '0', // define how many character can be on one line
     57 + gradient: false, // define your two gradient colors
     58 + independentGradient: false, // define if you want to recalculate the gradient for each new line
     59 + transitionGradient: false, // define if this is a transition between colors directly
     60 + env: 'node' // define the environment cfonts is being executed in
     61 +});
     62 +```
     63 + 
     64 +_All settings are optional and shown here with their default_
     65 + 
     66 +You can use `cfonts` in your project without the direct output to the console:
     67 + 
     68 +```js
     69 +const cfonts = require('cfonts');
     70 + 
     71 +const prettyFont = cfonts.render('Hello|world!', {/* same settings object as above */});
     72 + 
     73 +prettyFont.string // the ansi string for sexy console font
     74 +prettyFont.array // returns the array for the output
     75 +prettyFont.lines // returns the lines used
     76 +prettyFont.options // returns the options used
     77 +```
     78 + 
     79 + 
     80 +## CLI Usage
     81 + 
     82 +Read more in the [root repo](../).
     83 + 
     84 + 
     85 +## Tests
     86 + 
     87 +This package is tested on the below platform and node combinations as part of our [CI](https://github.com/dominikwilkowski/cfonts/tree/released/.github/workflows/testing.yml).
     88 + 
     89 +| Platform | Node |
     90 +|----------|------|
     91 +| Linux | v12 |
     92 +| Linux | v14 |
     93 +| Linux | v16 |
     94 +| OSX | v10 |
     95 +| OSX | v12 |
     96 +| OSX | v16 |
     97 +| Windows | v10 |
     98 +| Windows | v12 |
     99 +| Windows | v16 |
     100 + 
     101 +### Unit tests
     102 + 
     103 +The package comes with a bunch of [unit tests](https://github.com/dominikwilkowski/cfonts/tree/released/test/unit) that aim to cover 100% of the code base.
     104 +For more details about the code coverage check out [coveralls](https://coveralls.io/github/dominikwilkowski/cfonts?branch=released).
     105 + 
     106 +```sh
     107 +npm run test:unit
     108 +```
     109 + 
     110 +### Type tests
     111 + 
     112 +Since the code base uses [JSDocs](https://jsdoc.app/) we use [typescript](https://www.typescriptlang.org/) to test the inferred types from those comments.
     113 +Typescript [supports JSDocs](https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html#supported-jsdoc) and we use it in our
     114 +[test](https://github.com/dominikwilkowski/cfonts/blob/released/nodejs/package.json#L37).
     115 + 
     116 +```sh
     117 +npm run test:types
     118 +```
     119 + 
     120 +### Font file test
     121 + 
     122 +There is also a [test suite](https://github.com/dominikwilkowski/cfonts/blob/released/nodejs/test/fonttest.js) for font files.
     123 + 
     124 +```sh
     125 +npm run test:fonts
     126 +```
     127 + 
     128 +This tool checks:
     129 +- the existence of the font
     130 +- all attributes of a font
     131 +- each character for:
     132 + - existence
     133 + - consistent width
     134 + - consistent lines
     135 + 
     136 +### All tests
     137 + 
     138 +Run all tests via:
     139 + 
     140 +```sh
     141 +npm run test
     142 +```
     143 + 
     144 + 
     145 +## Contributing
     146 + 
     147 +To build the repo install dependencies via:
     148 +_(Since we ship a `yarn.lock` file please use [`yarn`](https://yarnpkg.com/) for development.)_
     149 + 
     150 +```sh
     151 +yarn
     152 +```
     153 + 
     154 +and run the watch to continuously transpile the code.
     155 + 
     156 +```sh
     157 +yarn watch
     158 +```
     159 + 
     160 +Please look at the coding style and work with it, not against it ;)
     161 + 
     162 + 
     163 +## Release History
     164 + 
     165 +* 3.0.0 - Added rust library port, aligned APIs, added hex background colors, fixed minor alignment bugs, updated license from GPLv2 to GPLv3
     166 +* 2.10.1 - bumped dependencies
     167 +* 2.10.0 - bumped dependencies, added typescript definitions into npm bundle
     168 +* 2.9.3 - bumped dependencies
     169 +* 2.9.2 - bumped dependencies
     170 +* 2.9.1 - bumped dependencies
     171 +* 2.9.0 - added `top` and `bottom` align options
     172 +* 2.8.6 - bumped dependencies
     173 +* 2.8.5 - renamed branches
     174 +* 2.8.4 - fixed block double quote
     175 +* 2.8.3 - bumped dependencies
     176 +* 2.8.2 - bumped dependencies, added linting, fixed #22 (again)
     177 +* 2.8.1 - bumped dependencies
     178 +* 2.8.0 - added environment support, added font `tiny`
     179 +* 2.7.0 - added font `slick`, `grid` and `pallet`, added double quote to all fonts
     180 +* 2.6.1 - fixed console `maxLength`, `gradient` and `lineHeight`, added more end-to-end tests
     181 +* 2.6.0 - added transition gradients and sets
     182 +* 2.5.2 - fixed jsDocs, added typescript type test
     183 +* 2.5.1 - fixed array output to include everything including colors
     184 +* 2.5.0 - added gradient option, separated code into files, added 100% unit testing coverage
     185 +* 2.4.8 - removed `ansi-styles` from direct dependencies
     186 +* 2.4.7 - fixed bug from adopting chalk v3 and hex colors
     187 +* 2.4.6 - bumped dependencies, removed `change-case` dependency, added `UpperCaseFirst` with tests
     188 +* 2.4.5 - bumped dependencies, moved to relative links for fonts for webpack support (#22)
     189 +* 2.4.4 - bumped dependencies
     190 +* 2.4.3 - bumped dependencies
     191 +* 2.4.2 - bumped dependencies
     192 +* 2.4.1 - updated to babel 7, removed runtime from dependencies
     193 +* 2.4.0 - added font `shade`, added hex color support
     194 +* 2.3.1 - added tests, fixed options, updated dependencies
     195 +* 2.3.0 - added apostrophe support in all fonts
     196 +* 2.2.3 - bumped dependencies
     197 +* 2.2.2 - bumped dependencies
     198 +* 2.2.1 - bumped dependencies
     199 +* 2.2.0 - inside the API you can use line breaks as well as the pipe
     200 +* 2.1.3 - refactored some loops
     201 +* 2.1.2 - made WinSize more robust
     202 +* 2.1.1 - fixed size detection in non-tty environments
     203 +* 2.1.0 - rebuilt `cfonts` with pure functions, made colors case-insensitive
     204 +* 2.0.1 - fixed terminal width detection
     205 +* 2.0.0 - added tests, split into more pure functions
     206 +* 1.2.0 - added `transparent` and `system` as default background and color option, added `backgroundColor` as alias for `background`, upgraded deps
     207 +* 1.1.3 - fixed help text, removing old -t option
     208 +* 1.1.2 - fixed issue with older commander version #3, updated docs
     209 +* 1.1.1 - moved from `babel-polyfill` to `babel-plugin-transform-runtime`, added files to package.json, added images to docs, fixed dependencies
     210 +* 1.1.0 - transpiled code to support node 0.12.15 and up
     211 +* 1.0.2 - fixed background in `console` font, added comma, added font `huge`, added render method, added candy color
     212 +* 1.0.1 - added `chrome` font, fonttest
     213 +* 1.0.0 - refactor, added alignment and line height option, new cli commands, added `simpleBlock`
     214 +* 0.0.13 - fixed `simple3d`
     215 +* 0.0.12 - fixed `simple3d` and added to grunt test
     216 +* 0.0.11 - added `simple3d` font
     217 +* 0.0.10 - added npmignore, added to docs
     218 +* 0.0.9 - added `console` font
     219 +* 0.0.8 - fixed bugs, docs
     220 +* 0.0.7 - changed to settings object
     221 +* 0.0.6 - added `3d` font
     222 +* 0.0.5 - added grunt test
     223 +* 0.0.4 - fixed `simple` font
     224 +* 0.0.3 - fixes, added `simple` font
     225 +* 0.0.2 - fixed paths
     226 +* 0.0.1 - alpha test
     227 + 
     228 + 
     229 +## License
     230 + 
     231 +Copyright (c) 2022 Dominik Wilkowski.
     232 +Licensed under the [GNU GPLv3](https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE).
     233 + 
  • ■ ■ ■ ■ ■ ■
    package.json nodejs/package.json
    1 1  {
    2 2   "name": "cfonts",
    3 3   "description": "Sexy fonts for the console",
    4  - "version": "2.10.1",
     4 + "version": "3.0.0",
    5 5   "homepage": "https://github.com/dominikwilkowski/cfonts",
    6 6   "author": {
    7 7   "name": "Dominik Wilkowski",
    skipped 12 lines
    20 20   "bugs": {
    21 21   "url": "https://github.com/dominikwilkowski/cfonts/issues"
    22 22   },
    23  - "licenses": [
    24  - {
    25  - "type": "GPL-2.0",
    26  - "url": "https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE"
    27  - }
    28  - ],
    29 23   "engines": {
    30 24   "node": ">=10"
    31 25   },
    32 26   "scripts": {
    33  - "prepublish": "yarn build && yarn test",
    34  - "test": "yarn build && yarn test:unit && yarn test:lint && yarn test:types && yarn test:fonts",
     27 + "test": "yarn format && yarn build && yarn test:unit && yarn test:lint && yarn test:types && yarn test:fonts",
    35 28   "test:fonts": "node ./test/fonttest.js",
    36 29   "test:watch": "jest --watchAll --coverage",
    37 30   "test:unit": "npx cross-env FORCE_COLOR=3 jest",
    38 31   "test:types": "yarn types:clean && tsc -p tsconfig.json",
    39 32   "test:lint": "eslint src/",
    40  - "build": "yarn build:lib && yarn build:bin",
     33 + "test:format": "prettier --list-different \"**/*.{js,json}\"",
     34 + "format": "prettier --write \"**/*.{js,json}\"",
     35 + "build": "yarn build:lib && yarn build:bin && yarn build:fonts",
    41 36   "build:bin": "npx mkdirp bin && mv lib/bin.js bin/index.js",
    42 37   "build:lib": "npx mkdirp lib && babel src --out-dir lib",
    43  - "types:clean": "find lib/ -type f -name '*.d.ts' -exec rm {} +",
     38 + "build:fonts": "npx mkdirp fonts && npx cpy-cli \"../fonts/*\" \"./fonts/\"",
     39 + "types:clean": "npx trash-cli \"lib/*.d.ts\"",
    44 40   "watch": "yarn build:lib && onchange 'src/**/*' -- yarn build:lib",
    45 41   "coveralls": "jest --coverage --coverageReporters=text-lcov | coveralls",
    46 42   "nuke": "rm -rf lib && rm -rf node_modules && rm yarn.lock"
    skipped 7 lines
    54 50   "eslint": "^8.12.0",
    55 51   "jest-cli": "^27.5.1",
    56 52   "onchange": "^7.1.0",
     53 + "prettier": "^2.6.2",
    57 54   "typescript": "^4.6.3"
    58 55   },
    59 56   "peerDependencies": {},
    60 57   "dependencies": {
    61  - "chalk": "^4",
     58 + "supports-color": "^8",
    62 59   "window-size": "^1.1.1"
    63 60   },
    64 61   "jest": {
    skipped 61 lines
    126 123   "bin": {
    127 124   "cfonts": "./bin/index.js"
    128 125   },
    129  - "license": "GPL-2.0"
     126 + "licenses": [
     127 + {
     128 + "type": "GPL-3.0",
     129 + "url": "https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE"
     130 + }
     131 + ],
     132 + "license": "GPL-3.0"
    130 133  }
    131 134   
  • ■ ■ ■ ■ ■ ■
    src/AddChar.js nodejs/src/AddChar.js
    skipped 3 lines
    4 4   *
    5 5   * Sexy fonts for the console. (CLI output)
    6 6   *
    7  - * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv2
     7 + * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv3
    8 8   * @author Dominik Wilkowski [email protected]
    9 9   * @repository https://github.com/dominikwilkowski/cfonts
    10 10   *
    skipped 7 lines
    18 18  const { Debugging } = require('./Debugging.js');
    19 19  const { Colorize } = require('./Colorize.js');
    20 20   
    21  - 
    22 21  /**
    23 22   * Add a new character to the output array
    24 23   *
    skipped 6 lines
    31 30   *
    32 31   * @return {array} - The output array with new line
    33 32   */
    34  -const AddChar = ( CHAR, output, fontLines, fontChars, fontColors, colors ) => {
    35  - Debugging.report( `Running AddChar with "${ CHAR }"`, 1 );
     33 +const AddChar = (CHAR, output, fontLines, fontChars, fontColors, colors) => {
     34 + Debugging.report(`Running AddChar with "${CHAR}"`, 1);
    36 35   
    37 36   let lines = output.length - fontLines; // last line is fontLines tall and is located at the bottom of the output array
    38 37   
    39  - for( let i = lines; i < output.length; i++ ) { // iterate over last line
     38 + for (let i = lines; i < output.length; i++) {
     39 + // iterate over last line
    40 40   let index = i - lines;
    41 41   
    42  - output[ i ] += Colorize( fontChars[ CHAR ][ index ], fontColors, colors );
     42 + output[i] += Colorize(fontChars[CHAR][index], fontColors, colors);
    43 43   }
    44 44   
    45 45   return output;
    46 46  };
    47  - 
    48 47   
    49 48  module.exports = exports = {
    50 49   AddChar,
    skipped 2 lines
  • ■ ■ ■ ■ ■ ■
    src/AddLetterSpacing.js nodejs/src/AddLetterSpacing.js
    skipped 3 lines
    4 4   *
    5 5   * Sexy fonts for the console. (CLI output)
    6 6   *
    7  - * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv2
     7 + * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv3
    8 8   * @author Dominik Wilkowski [email protected]
    9 9   * @repository https://github.com/dominikwilkowski/cfonts
    10 10   *
    skipped 7 lines
    18 18  const { Debugging } = require('./Debugging.js');
    19 19  const { Colorize } = require('./Colorize.js');
    20 20   
    21  - 
    22  - 
    23 21  /**
    24 22   * Add letter spacing for the next character
    25 23   *
    skipped 6 lines
    32 30   *
    33 31   * @return {array} - The output array with space
    34 32   */
    35  -const AddLetterSpacing = ( output, fontLines, fontLetterspace, fontColors, colors, letterSpacing ) => {
    36  - Debugging.report( `Running AddLetterSpacing`, 1 );
     33 +const AddLetterSpacing = (output, fontLines, fontLetterspace, fontColors, colors, letterSpacing) => {
     34 + Debugging.report(`Running AddLetterSpacing`, 1);
    37 35   
    38 36   let lines = output.length - fontLines; // last line is fontLines tall and is located at the bottom of the output array
    39 37   
    40  - for( let i = lines; i < output.length; i++ ) { // iterate over last line
     38 + for (let i = lines; i < output.length; i++) {
     39 + // iterate over last line
    41 40   let index = i - lines;
    42  - let space = Colorize( fontLetterspace[ index ], fontColors, colors );
     41 + let space = Colorize(fontLetterspace[index], fontColors, colors);
    43 42   
    44  - if( space.length === 0 && letterSpacing > 0 ) {
    45  - Debugging.report( `AddLetterSpacing: Adding space to letter spacing`, 1 );
     43 + if (space.length === 0 && letterSpacing > 0) {
     44 + Debugging.report(`AddLetterSpacing: Adding space to letter spacing`, 1);
    46 45   
    47 46   space = ' ';
    48 47   }
    49 48   
    50  - output[ i ] += space.repeat( letterSpacing );
     49 + output[i] += space.repeat(letterSpacing);
    51 50   }
    52 51   
    53 52   return output;
    54 53  };
    55  - 
    56 54   
    57 55  module.exports = exports = {
    58 56   AddLetterSpacing,
    skipped 2 lines
  • ■ ■ ■ ■ ■ ■
    src/AddLine.js nodejs/src/AddLine.js
    skipped 3 lines
    4 4   *
    5 5   * Sexy fonts for the console. (CLI output)
    6 6   *
    7  - * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv2
     7 + * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv3
    8 8   * @author Dominik Wilkowski [email protected]
    9 9   * @repository https://github.com/dominikwilkowski/cfonts
    10 10   *
    skipped 5 lines
    16 16  'use strict';
    17 17   
    18 18  const { Debugging } = require('./Debugging.js');
    19  - 
    20 19   
    21 20  /**
    22 21   * Add a new line to the output array
    skipped 5 lines
    28 27   *
    29 28   * @return {array} - The output array with new line
    30 29   */
    31  -const AddLine = ( output, fontLines, FontBuffer, lineHeight ) => {
    32  - Debugging.report( `Running AddLine`, 1 );
     30 +const AddLine = (output, fontLines, FontBuffer, lineHeight) => {
     31 + Debugging.report(`Running AddLine`, 1);
    33 32   
    34  - if( output.length === 0 ) {
     33 + if (output.length === 0) {
    35 34   lineHeight = 0;
    36 35   }
    37 36   
    38 37   let lines = fontLines + output.length + lineHeight;
    39 38   let length = output.length;
    40 39   
    41  - for( let i = length; i < lines; i++ ) {
     40 + for (let i = length; i < lines; i++) {
    42 41   let index = i - length;
    43 42   
    44  - if( index > lineHeight ) {
    45  - output[ i ] = FontBuffer[ ( index - lineHeight ) ];
    46  - }
    47  - else {
    48  - output[ i ] = '';
     43 + if (index > lineHeight) {
     44 + output[i] = FontBuffer[index - lineHeight];
     45 + } else {
     46 + output[i] = '';
    49 47   }
    50 48   }
    51 49   
    52 50   return output;
    53 51  };
    54  - 
    55 52   
    56 53  module.exports = exports = {
    57 54   AddLine,
    skipped 2 lines
  • ■ ■ ■ ■ ■ ■
    src/AddShortcuts.js nodejs/src/AddShortcuts.js
    skipped 3 lines
    4 4   *
    5 5   * Sexy fonts for the console. (CLI output)
    6 6   *
    7  - * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv2
     7 + * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv3
    8 8   * @author Dominik Wilkowski [email protected]
    9 9   * @repository https://github.com/dominikwilkowski/cfonts
    10 10   *
    skipped 4 lines
    15 15   
    16 16  'use strict';
    17 17   
    18  - 
    19 18  /**
    20 19   * Flatten the shortcuts in our cli options object
    21 20   *
    skipped 1 lines
    23 22   *
    24 23   * @return {object} - All short keys flattened into first level
    25 24   */
    26  -const AddShortcuts = ( options ) => {
    27  - const flatOptions = Object.assign( {}, options );
     25 +const AddShortcuts = (options) => {
     26 + const flatOptions = Object.assign({}, options);
    28 27   
    29  - Object.keys( flatOptions ).forEach( option => {
    30  - flatOptions[ option ]._name = option;
    31  - flatOptions[ flatOptions[ option ].short ] = flatOptions[ option ];
     28 + Object.keys(flatOptions).forEach((option) => {
     29 + flatOptions[option]._name = option;
     30 + flatOptions[flatOptions[option].short] = flatOptions[option];
    32 31   });
    33 32   
    34 33   return flatOptions;
    35 34  };
    36  - 
    37 35   
    38 36  module.exports = exports = {
    39 37   AddShortcuts,
    skipped 2 lines
  • ■ ■ ■ ■ ■ ■
    src/AlignText.js nodejs/src/AlignText.js
    skipped 3 lines
    4 4   *
    5 5   * Sexy fonts for the console. (CLI output)
    6 6   *
    7  - * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv2
     7 + * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv3
    8 8   * @author Dominik Wilkowski [email protected]
    9 9   * @repository https://github.com/dominikwilkowski/cfonts
    10 10   *
    skipped 7 lines
    18 18  const { Debugging } = require('./Debugging.js');
    19 19  const { Size } = require('./Size.js');
    20 20   
    21  - 
    22 21  /**
    23 22   * Calculate the spaces to be added to the left of each line to align them either center or right
    24 23   *
    skipped 7 lines
    32 31   *
    33 32   * @return {array} - The output array with space added on the left for alignment
    34 33   */
    35  -const AlignText = ( output, lineLength, characterLines, align, size = Size ) => {
    36  - Debugging.report( `Running AlignText`, 1 );
     34 +const AlignText = (output, lineLength, characterLines, align, size = Size) => {
     35 + Debugging.report(`Running AlignText`, 1);
    37 36   
    38 37   let space = 0;
    39 38   
    40  - if( align === 'center' ) { // calculate the size for center alignment
    41  - space = Math.floor( ( size.width - lineLength ) / 2 );
     39 + if (align === 'center') {
     40 + // calculate the size for center alignment
     41 + space = Math.ceil((size.width - lineLength) / 2);
    42 42   
    43  - Debugging.report( `AlignText: Center lineLength: ${ lineLength }, size.width: ${ size.width }, space: ${ space }`, 2 );
     43 + Debugging.report(`AlignText: Center lineLength: ${lineLength}, size.width: ${size.width}, space: ${space}`, 2);
    44 44   }
    45 45   
    46  - if( align === 'right' ) { // calculate the size for right alignment
     46 + if (align === 'right') {
     47 + // calculate the size for right alignment
    47 48   space = size.width - lineLength;
    48 49   
    49  - Debugging.report( `AlignText: Right lineLength: ${ lineLength }, size.width: ${ size.width }, space: ${ space }`, 2 );
     50 + Debugging.report(`AlignText: Right lineLength: ${lineLength}, size.width: ${size.width}, space: ${space}`, 2);
    50 51   }
    51 52   
    52  - 
    53  - if( space > 0 ) { // only add if there is something to add
     53 + if (space > 0) {
     54 + // only add if there is something to add
    54 55   let lines = output.length - characterLines; // last line is characterLines tall and is located at the bottom of the output array
    55  - const spaces = ' '.repeat( space );
     56 + const spaces = ' '.repeat(space);
    56 57   
    57  - for( let i = lines; i < output.length; i++ ) { // iterate over last line (which can be several line breaks long)
    58  - output[ i ] = spaces + output[ i ];
     58 + for (let i = lines; i < output.length; i++) {
     59 + // iterate over last line (which can be several line breaks long)
     60 + output[i] = spaces + output[i];
    59 61   }
    60 62   }
    61 63   
    62 64   return output;
    63 65  };
    64  - 
    65 66   
    66 67  module.exports = exports = {
    67 68   AlignText,
    skipped 2 lines
  • ■ ■ ■ ■ ■ ■
    src/CharLength.js nodejs/src/CharLength.js
    skipped 3 lines
    4 4   *
    5 5   * Sexy fonts for the console. (CLI output)
    6 6   *
    7  - * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv2
     7 + * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv3
    8 8   * @author Dominik Wilkowski [email protected]
    9 9   * @repository https://github.com/dominikwilkowski/cfonts
    10 10   *
    skipped 6 lines
    17 17   
    18 18  const { Debugging } = require('./Debugging.js');
    19 19   
    20  - 
    21 20  /**
    22 21   * Return the max width of a character by looking at its longest line
    23 22   *
    skipped 3 lines
    27 26   *
    28 27   * @return {number} - The length of a longest line in a character
    29 28   */
    30  -const CharLength = ( character, fontLines, letterSpacing ) => {
    31  - Debugging.report( `Running CharLength`, 1 );
     29 +const CharLength = (character, fontLines, letterSpacing) => {
     30 + Debugging.report(`Running CharLength`, 1);
    32 31   
    33 32   let charWidth = 0;
    34 33   
    35  - for( let i = 0; i < fontLines; i++ ) {
    36  - let char = character[ i ].replace( /(<([^>]+)>)/ig, '' ); // get character and strip color infos
     34 + for (let i = 0; i < fontLines; i++) {
     35 + let char = character[i].replace(/(<([^>]+)>)/gi, ''); // get character and strip color infos
    37 36   
    38  - if( char.length > charWidth ) {
     37 + if (char.length > charWidth) {
    39 38   charWidth = char.length; // assign only largest
    40 39   }
    41 40   }
    42 41   
    43  - if( charWidth === 0 && letterSpacing > 0 ) {
    44  - Debugging.report( `CharLength: Adding space to letter spacing`, 1 );
     42 + if (charWidth === 0 && letterSpacing > 0) {
     43 + Debugging.report(`CharLength: Adding space to letter spacing`, 1);
    45 44   
    46 45   charWidth = 1;
    47 46   }
    48 47   
    49 48   return charWidth;
    50 49  };
    51  - 
    52 50   
    53 51  module.exports = exports = {
    54 52   CharLength,
    skipped 2 lines
  • ■ ■ ■ ■ ■ ■
    nodejs/src/CheckInput.js
     1 +/***************************************************************************************************************************************************************
     2 + *
     3 + * cfonts
     4 + *
     5 + * Sexy fonts for the console. (CLI output)
     6 + *
     7 + * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv3
     8 + * @author Dominik Wilkowski [email protected]
     9 + * @repository https://github.com/dominikwilkowski/cfonts
     10 + *
     11 + * CheckInput
     12 + * Check input for human errors
     13 + *
     14 + **************************************************************************************************************************************************************/
     15 + 
     16 +'use strict';
     17 + 
     18 +const { HEXTEST, Color } = require('./Color.js');
     19 +const { COLORS, BGCOLORS, GRADIENTCOLORS, GRADIENTS, ALIGNMENT, FONTFACES } = require('./constants.js');
     20 + 
     21 +/**
     22 + * Check input for human errors
     23 + *
     24 + * @param {string} INPUT - The string you want to write out
     25 + * @param {string} userFont - The user specified font
     26 + * @param {array} userColors - The user specified colors
     27 + * @param {string} userBackground - The user specified background color
     28 + * @param {string} userAlign - The user specified alignment option
     29 + * @param {array} userGradient - The user specified gradient option
     30 + * @param {boolean} userTransitionGradient - The user specified gradient transition option
     31 + * @param {string} userEnv - The user specified environment
     32 + * @param {object} fontfaces - All allowed fontfaces
     33 + * @param {object} colors - All allowed font colors
     34 + * @param {object} bgcolors - All allowed background colors
     35 + * @param {object} gradientcolors - All allowed gradient colors
     36 + * @param {object} gradients - All allowed gradients
     37 + * @param {array} alignment - All allowed alignments
     38 + *
     39 + * @typedef {object} ReturnObject
     40 + * @property {boolean} pass - Whether the input is valid
     41 + * @property {string} message - Possible error messages
     42 + *
     43 + * @return {ReturnObject} - An object with error messages and a pass key
     44 + */
     45 +const CheckInput = (
     46 + INPUT,
     47 + userFont,
     48 + userColors,
     49 + userBackground,
     50 + userAlign,
     51 + userGradient,
     52 + userTransitionGradient,
     53 + userEnv,
     54 + fontfaces = FONTFACES,
     55 + colors = COLORS,
     56 + bgcolors = BGCOLORS,
     57 + gradientcolors = GRADIENTCOLORS,
     58 + gradients = GRADIENTS,
     59 + alignment = ALIGNMENT
     60 +) => {
     61 + let result = {
     62 + message: '',
     63 + pass: true,
     64 + };
     65 + 
     66 + const { open: red_open, close: red_close } = Color('red');
     67 + const { open: green_open, close: green_close } = Color('green');
     68 + 
     69 + // checking input
     70 + if (INPUT === undefined || INPUT === '') {
     71 + return {
     72 + message: 'Please provide text to convert',
     73 + pass: false,
     74 + };
     75 + }
     76 + 
     77 + // checking font
     78 + if (Object.keys(fontfaces).indexOf(userFont.toLowerCase()) === -1) {
     79 + return {
     80 + message:
     81 + `"${red_open}${userFont}${red_close}" is not a valid font option.\n` +
     82 + `Please use a font from the supported stack:\n${green_open}${Object.keys(fontfaces)
     83 + .map((font) => fontfaces[font])
     84 + .join(', ')}${green_close}`,
     85 + pass: false,
     86 + };
     87 + }
     88 + 
     89 + // checking colors
     90 + userColors.forEach((color) => {
     91 + // check color usage
     92 + if (Object.keys(colors).indexOf(color.toLowerCase()) === -1 && color !== 'candy' && !HEXTEST.test(color)) {
     93 + result = {
     94 + message:
     95 + `"${red_open}${color}${red_close}" is not a valid font color option.\n` +
     96 + `Please use a color from the supported stack or any valid hex color:\n` +
     97 + `${green_open}${Object.keys(colors)
     98 + .map((color) => colors[color])
     99 + .join(', ')}, candy, "#3456ff", "#f80", etc...${green_close}`,
     100 + pass: false,
     101 + };
     102 + }
     103 + });
     104 + 
     105 + // checking background colors
     106 + if (Object.keys(bgcolors).indexOf(userBackground.toLowerCase()) === -1 && !HEXTEST.test(userBackground)) {
     107 + return {
     108 + message:
     109 + `"${red_open}${userBackground}${red_close}" is not a valid background option.\n` +
     110 + `Please use a color from the supported stack:\n` +
     111 + `${green_open}${Object.keys(bgcolors)
     112 + .map((bgcolor) => bgcolors[bgcolor])
     113 + .join(', ')}, "#3456ff", "#f80", etc...${green_close}`,
     114 + pass: false,
     115 + };
     116 + }
     117 + 
     118 + // CHECKING ALIGNMENT
     119 + if (alignment.indexOf(userAlign.toLowerCase()) === -1) {
     120 + return {
     121 + message:
     122 + `"${red_open}${userAlign}${red_close}" is not a valid alignment option.\n` +
     123 + `Please use an alignment option from the supported stack:\n${green_open}${alignment.join(' | ')}${green_close}`,
     124 + pass: false,
     125 + };
     126 + }
     127 + 
     128 + // CHECKING GRADIENT
     129 + if (userGradient) {
     130 + if (
     131 + userGradient.length === 1 &&
     132 + Object.keys(gradients).indexOf(userGradient[0].toLowerCase()) !== -1 &&
     133 + userTransitionGradient
     134 + ) {
     135 + return result;
     136 + } else {
     137 + if (userGradient.length < 2) {
     138 + return {
     139 + message:
     140 + `"${red_open}${userGradient}${red_close}" is not a valid gradient option.\n` +
     141 + `Please pass in${userTransitionGradient ? ' at least' : ''} two colors.`,
     142 + pass: false,
     143 + };
     144 + }
     145 + 
     146 + if (userGradient.length !== 2 && !userTransitionGradient) {
     147 + return {
     148 + message:
     149 + `"${red_open}${userGradient}${red_close}" is not a valid gradient option.\n` + `Please pass in two colors.`,
     150 + pass: false,
     151 + };
     152 + }
     153 + 
     154 + // check validity of colors
     155 + userGradient.forEach((color) => {
     156 + if (Object.keys(gradientcolors).indexOf(color.toLowerCase()) === -1 && !HEXTEST.test(color)) {
     157 + result = {
     158 + message:
     159 + `"${red_open}${color}${red_close}" is not a valid gradient color option.\n` +
     160 + `Please use a color from the supported stack or any valid hex color:\n${green_open}${Object.keys(
     161 + gradientcolors
     162 + )
     163 + .map((color) => colors[color])
     164 + .join(', ')}, "#3456ff", "#f80", etc...${green_close}`,
     165 + pass: false,
     166 + };
     167 + }
     168 + });
     169 + }
     170 + }
     171 + 
     172 + // CHECKING ENVIRONMENT
     173 + if (userEnv !== 'node' && userEnv !== 'browser') {
     174 + return {
     175 + message:
     176 + `"${red_open}${userEnv}${red_close}" is not a valid environment option.\n` +
     177 + `Please use only the supported options:\n${green_open}node | browser${green_close}`,
     178 + pass: false,
     179 + };
     180 + }
     181 + 
     182 + return result;
     183 +};
     184 + 
     185 +module.exports = exports = {
     186 + CheckInput,
     187 +};
     188 + 
  • ■ ■ ■ ■ ■ ■
    src/CleanInput.js nodejs/src/CleanInput.js
    skipped 3 lines
    4 4   *
    5 5   * Sexy fonts for the console. (CLI output)
    6 6   *
    7  - * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv2
     7 + * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv3
    8 8   * @author Dominik Wilkowski [email protected]
    9 9   * @repository https://github.com/dominikwilkowski/cfonts
    10 10   *
    skipped 6 lines
    17 17   
    18 18  const { CHARS } = require('./constants.js');
    19 19   
    20  - 
    21 20  /**
    22 21   * Filter only allowed character
    23 22   *
    skipped 2 lines
    26 25   *
    27 26   * @return {string} - The filtered input text
    28 27   */
    29  -const CleanInput = ( INPUT, chars = CHARS ) => {
    30  - if( typeof INPUT === 'string' ) {
    31  - const clean = INPUT
    32  - .replace(/(?:\r\n|\r|\n)/g, '|')
     28 +const CleanInput = (INPUT, chars = CHARS) => {
     29 + if (typeof INPUT === 'string') {
     30 + const clean = INPUT.replace(/(?:\r\n|\r|\n)/g, '|')
    33 31   .split('')
    34  - .filter( char => chars.includes( char.toUpperCase() ) )
     32 + .filter((char) => chars.includes(char.toUpperCase()))
    35 33   .join('');
    36 34   
    37 35   return clean;
    38  - }
    39  - else {
     36 + } else {
    40 37   return '';
    41 38   }
    42 39  };
    43  - 
    44 40   
    45 41  module.exports = exports = {
    46 42   CleanInput,
    skipped 2 lines
  • ■ ■ ■ ■ ■ ■
    nodejs/src/Color.js
     1 +/***************************************************************************************************************************************************************
     2 + *
     3 + * cfonts
     4 + *
     5 + * Sexy fonts for the console. (CLI output)
     6 + *
     7 + * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv3
     8 + * @author Dominik Wilkowski [email protected]
     9 + * @repository https://github.com/dominikwilkowski/cfonts
     10 + *
     11 + * HEXTEST - Regex to see if a string is a hex color
     12 + * Rgb2hsv - Converts an RGB color value to HSV
     13 + * Hsv2rgb - Converts an HSV color value to RGB
     14 + * Rgb2hex - Converts RGB to HEX
     15 + * Hex2rgb - Convert HEX to RGB
     16 + * Hsv2hsvRad - Convert HSV coordinate to HSVrad (degree to radian)
     17 + * HsvRad2hsv - Convert HSVrad color to HSV (radian to degree)
     18 + * Hex2hsvRad - Convert HEX to HSVrad
     19 + * HsvRad2hex - Convert HSVrad to HEX
     20 + * rgb2ansi_16m - - Convert RGB values to ANSI16 million colors - truecolor
     21 + * rgb2ansi256Code - Convert RGB values to ANSI256 escape code
     22 + * rgb2ansi_256 - Convert RGB values to ANSI256
     23 + * ansi_2562ansi_16 - Convert ANSI256 code values to ANSI16
     24 + * get_term_color_support - Detect the ANSI support for the current terminal taking into account env vars NO_COLOR and FORCE_COLOR
     25 + * Color - Abstraction for coloring hex-, keyword- and background-colors
     26 + *
     27 + **************************************************************************************************************************************************************/
     28 + 
     29 +'use strict';
     30 + 
     31 +const { supportsColor } = require('supports-color');
     32 + 
     33 +const { Options } = require('./Options.js');
     34 + 
     35 +/**
     36 + * Regex to see if a string is a hex color
     37 + *
     38 + * @type {RegExp}
     39 + */
     40 +const HEXTEST = RegExp('^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$');
     41 + 
     42 +/**
     43 + * Converts an RGB color value to HSV
     44 + *
     45 + * @author https://github.com/Gavin-YYC/colorconvert
     46 + *
     47 + * @param {object} options - Arguments
     48 + * @param {number} options.r - The red color value
     49 + * @param {number} options.g - The green color value
     50 + * @param {number} options.b - The blue color value
     51 + *
     52 + * @return {array} - The HSV representation
     53 + */
     54 +function Rgb2hsv({ r, g, b }) {
     55 + r /= 255;
     56 + g /= 255;
     57 + b /= 255;
     58 + 
     59 + const max = Math.max(r, g, b);
     60 + const min = Math.min(r, g, b);
     61 + const diff = max - min;
     62 + 
     63 + let h = 0;
     64 + let v = max;
     65 + let s = max === 0 ? 0 : diff / max;
     66 + 
     67 + // h
     68 + if (max === min) {
     69 + h = 0;
     70 + } else if (max === r && g >= b) {
     71 + h = 60 * ((g - b) / diff);
     72 + } else if (max === r && g < b) {
     73 + h = 60 * ((g - b) / diff) + 360;
     74 + } else if (max === g) {
     75 + h = 60 * ((b - r) / diff) + 120;
     76 + } else {
     77 + // if( max === b ) {
     78 + h = 60 * ((r - g) / diff) + 240;
     79 + }
     80 + 
     81 + return [h, s * 100, v * 100];
     82 +}
     83 + 
     84 +/**
     85 + * Converts an HSV color value to RGB
     86 + *
     87 + * @author https://github.com/Gavin-YYC/colorconvert
     88 + *
     89 + * @param {number} h - The hue
     90 + * @param {number} s - The saturation
     91 + * @param {number} v - The value
     92 + *
     93 + * @typedef {object} Hsv2rgbReturnObject
     94 + * @property {number} r - The red value
     95 + * @property {number} g - The green value
     96 + * @property {number} b - The blue value
     97 + *
     98 + * @return {Hsv2rgbReturnObject} - The RGB representation
     99 + */
     100 +function Hsv2rgb(h, s, v) {
     101 + h /= 60;
     102 + s /= 100;
     103 + v /= 100;
     104 + const hi = Math.floor(h) % 6;
     105 + 
     106 + const f = h - Math.floor(h);
     107 + const p = 255 * v * (1 - s);
     108 + const q = 255 * v * (1 - s * f);
     109 + const t = 255 * v * (1 - s * (1 - f));
     110 + v *= 255;
     111 + 
     112 + switch (hi) {
     113 + case 0:
     114 + return { r: v, g: t, b: p };
     115 + case 1:
     116 + return { r: q, g: v, b: p };
     117 + case 2:
     118 + return { r: p, g: v, b: t };
     119 + case 3:
     120 + return { r: p, g: q, b: v };
     121 + case 4:
     122 + return { r: t, g: p, b: v };
     123 + case 5:
     124 + return { r: v, g: p, b: q };
     125 + }
     126 +}
     127 + 
     128 +/**
     129 + * Converts RGB to HEX
     130 + *
     131 + * @param {number} r - The Red value
     132 + * @param {number} g - The Green value
     133 + * @param {number} b - The Blue value
     134 + *
     135 + * @return {string} - A HEX color
     136 + */
     137 +function Rgb2hex(r, g, b) {
     138 + const val = (b | (g << 8) | (r << 16) | (1 << 24)).toString(16).slice(1);
     139 + return '#' + val.toLowerCase();
     140 +}
     141 + 
     142 +/**
     143 + * Convert HEX to RGB
     144 + *
     145 + * @param {string} hex - The HEX color
     146 + *
     147 + * @return {array} - An object with RGB values
     148 + */
     149 +function Hex2rgb(hex) {
     150 + hex = hex.replace(/^#/, '');
     151 + 
     152 + if (hex.length > 6) {
     153 + hex = hex.slice(0, 6);
     154 + }
     155 + 
     156 + if (hex.length === 4) {
     157 + hex = hex.slice(0, 3);
     158 + }
     159 + 
     160 + if (hex.length === 3) {
     161 + hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
     162 + }
     163 + 
     164 + const num = parseInt(hex, 16);
     165 + const r = num >> 16;
     166 + const g = (num >> 8) & 255;
     167 + const b = num & 255;
     168 + const rgb = [r, g, b];
     169 + 
     170 + return rgb;
     171 +}
     172 + 
     173 +/**
     174 + * Convert HSV coordinate to HSVrad (degree to radian)
     175 + *
     176 + * @param {array} argument - The HSV representation of a color
     177 + *
     178 + * @return {array} - The HSVrad color
     179 + */
     180 +function Hsv2hsvRad([h, s, v]) {
     181 + return [(h * Math.PI) / 180, s, v];
     182 +}
     183 + 
     184 +/**
     185 + * Convert HSVrad color to HSV (radian to degree)
     186 + *
     187 + * @param {number} hRad - H in rad
     188 + * @param {number} s - S
     189 + * @param {number} v - V
     190 + *
     191 + * @return {array} - The HSV color
     192 + */
     193 +function HsvRad2hsv(hRad, s, v) {
     194 + const precision = 1000000000000;
     195 + const h = Math.round(((hRad * 180) / Math.PI) * precision) / precision;
     196 + return [h, s, v];
     197 +}
     198 + 
     199 +/**
     200 + * Convert HEX to HSVrad
     201 + *
     202 + * @param {string} hex - A HEX color
     203 + *
     204 + * @return {array} - The HSVrad color
     205 + */
     206 +function Hex2hsvRad(hex) {
     207 + const [r, g, b] = Hex2rgb(hex);
     208 + const hsv = Rgb2hsv({ r, g, b });
     209 + const hsvRad = Hsv2hsvRad(hsv);
     210 + 
     211 + return hsvRad;
     212 +}
     213 + 
     214 +/**
     215 + * Convert HSVrad to HEX
     216 + *
     217 + * @param {number} hRad - The hue in rad
     218 + * @param {number} s - The saturation
     219 + * @param {number} v - The value
     220 + *
     221 + * @return {string} - The HEX color
     222 + */
     223 +function HsvRad2hex(hRad, s, v) {
     224 + const [h] = HsvRad2hsv(hRad, s, v);
     225 + const { r, g, b } = Hsv2rgb(h, s, v);
     226 + const hex = Rgb2hex(r, g, b);
     227 + 
     228 + return hex;
     229 +}
     230 + 
     231 +/**
     232 + * Convert RGB values to ANSI16 million colors - truecolor
     233 + *
     234 + * @param {number} r - Red value
     235 + * @param {number} g - Green value
     236 + * @param {number} b - Blue value
     237 + * @param {boolean} bg - Is this a background color; default: false
     238 + *
     239 + * @return {string} - The opening ANSI escape sequence for the given color
     240 + */
     241 +function rgb2ansi_16m(r, g, b, bg = false) {
     242 + const layer_code = bg ? 48 : 38;
     243 + return `\u001b[${layer_code};2;${r};${g};${b}m`;
     244 +}
     245 + 
     246 +/**
     247 + * Convert RGB values to ANSI256 escape code
     248 + *
     249 + * @param {number} red - Red value
     250 + * @param {number} green - Green value
     251 + * @param {number} blue - Blue value
     252 + *
     253 + * @return {number} - The ANSI escape code for the given color
     254 + */
     255 +function rgb2ansi256Code(red, green, blue) {
     256 + if (red === green && green === blue) {
     257 + if (red < 8) {
     258 + return 16;
     259 + }
     260 + 
     261 + if (red > 248) {
     262 + return 231;
     263 + }
     264 + 
     265 + return Math.round(((red - 8) / 247) * 24) + 232;
     266 + }
     267 + 
     268 + return 16 + 36 * Math.round((red / 255) * 5) + 6 * Math.round((green / 255) * 5) + Math.round((blue / 255) * 5);
     269 +}
     270 + 
     271 +/**
     272 + * Convert RGB values to ANSI256
     273 + *
     274 + * @param {number} r - Red value
     275 + * @param {number} g - Green value
     276 + * @param {number} b - Blue value
     277 + * @param {boolean} bg - Is this a background color; default: false
     278 + *
     279 + * @return {string} - The opening ANSI escape sequence for the given color
     280 + */
     281 +function rgb2ansi_256(r, g, b, bg = false) {
     282 + const layer_code = bg ? 48 : 38;
     283 + const code = rgb2ansi256Code(r, g, b);
     284 + return `\u001b[${layer_code};5;${code}m`;
     285 +}
     286 + 
     287 +/**
     288 + * Convert ANSI256 code values to ANSI16
     289 + *
     290 + * @param {number} code - The code of the ANSI256 color
     291 + * @param {boolean} bg - Is this a background color; default: false
     292 + *
     293 + * @return {string} - The opening ANSI escape sequence for the given color
     294 + */
     295 +function ansi_2562ansi_16(code, bg = false) {
     296 + let ansi_16_code;
     297 + if (code <= 7) {
     298 + ansi_16_code = code + 10;
     299 + }
     300 + if (code >= 8 && code <= 15) {
     301 + ansi_16_code = code + 82;
     302 + }
     303 + if (code === 16) {
     304 + ansi_16_code = 0;
     305 + }
     306 + if (code >= 17 && code <= 19) {
     307 + ansi_16_code = 34;
     308 + }
     309 + if ((code >= 20 && code <= 21) || (code >= 25 && code <= 27)) {
     310 + ansi_16_code = 94;
     311 + }
     312 + if (
     313 + (code >= 22 && code <= 24) ||
     314 + (code >= 58 && code <= 60) ||
     315 + (code >= 64 && code <= 66) ||
     316 + (code >= 94 && code <= 95) ||
     317 + (code >= 100 && code <= 102) ||
     318 + (code >= 106 && code <= 108) ||
     319 + (code >= 130 && code <= 131) ||
     320 + (code >= 136 && code <= 138) ||
     321 + (code >= 142 && code <= 144) ||
     322 + (code >= 148 && code <= 151) ||
     323 + (code >= 172 && code <= 174) ||
     324 + (code >= 178 && code <= 181) ||
     325 + (code >= 184 && code <= 189)
     326 + ) {
     327 + ansi_16_code = 33;
     328 + }
     329 + if (
     330 + (code >= 28 && code <= 30) ||
     331 + (code >= 34 && code <= 36) ||
     332 + (code >= 70 && code <= 72) ||
     333 + (code >= 76 && code <= 79) ||
     334 + (code >= 112 && code <= 114)
     335 + ) {
     336 + ansi_16_code = 32;
     337 + }
     338 + if (
     339 + (code >= 31 && code <= 33) ||
     340 + (code >= 37 && code <= 39) ||
     341 + (code >= 44 && code <= 45) ||
     342 + (code >= 61 && code <= 63) ||
     343 + (code >= 67 && code <= 69) ||
     344 + (code >= 73 && code <= 75) ||
     345 + (code >= 80 && code <= 81) ||
     346 + (code >= 103 && code <= 111) ||
     347 + (code >= 115 && code <= 117) ||
     348 + (code >= 152 && code <= 153)
     349 + ) {
     350 + ansi_16_code = 36;
     351 + }
     352 + if (
     353 + (code >= 40 && code <= 43) ||
     354 + (code >= 46 && code <= 49) ||
     355 + (code >= 82 && code <= 85) ||
     356 + (code >= 118 && code <= 120) ||
     357 + (code >= 154 && code <= 157)
     358 + ) {
     359 + ansi_16_code = 92;
     360 + }
     361 + if (
     362 + (code >= 50 && code <= 51) ||
     363 + (code >= 86 && code <= 87) ||
     364 + (code >= 121 && code <= 123) ||
     365 + (code >= 158 && code <= 159)
     366 + ) {
     367 + ansi_16_code = 96;
     368 + }
     369 + if (
     370 + (code >= 52 && code <= 54) ||
     371 + (code >= 88 && code <= 90) ||
     372 + (code >= 124 && code <= 126) ||
     373 + (code >= 166 && code <= 168)
     374 + ) {
     375 + ansi_16_code = 31;
     376 + }
     377 + if (
     378 + (code >= 55 && code <= 57) ||
     379 + (code >= 91 && code <= 93) ||
     380 + (code >= 96 && code <= 99) ||
     381 + (code >= 127 && code <= 129) ||
     382 + (code >= 132 && code <= 135) ||
     383 + (code >= 139 && code <= 141) ||
     384 + (code >= 145 && code <= 147) ||
     385 + (code >= 196 && code <= 171) ||
     386 + (code >= 175 && code <= 177)
     387 + ) {
     388 + ansi_16_code = 35;
     389 + }
     390 + if ((code >= 160 && code <= 163) || (code >= 196 && code <= 199) || (code >= 202 && code <= 213)) {
     391 + ansi_16_code = 91;
     392 + }
     393 + if (
     394 + (code >= 164 && code <= 165) ||
     395 + (code >= 182 && code <= 183) ||
     396 + (code >= 200 && code <= 200) ||
     397 + (code >= 218 && code <= 219)
     398 + ) {
     399 + ansi_16_code = 95;
     400 + }
     401 + if ((code >= 190 && code <= 193) || (code >= 214 && code <= 217) || (code >= 220 && code <= 228)) {
     402 + ansi_16_code = 93;
     403 + }
     404 + if ((code >= 194 && code <= 195) || (code >= 229 && code <= 231) || (code >= 253 && code <= 255)) {
     405 + ansi_16_code = 97;
     406 + }
     407 + if (code >= 232 && code <= 239) {
     408 + ansi_16_code = 30;
     409 + }
     410 + if (code >= 240 && code <= 246) {
     411 + ansi_16_code = 90;
     412 + }
     413 + if (code >= 247 && code <= 252) {
     414 + ansi_16_code = 37;
     415 + }
     416 + 
     417 + if (bg) {
     418 + ansi_16_code = ansi_16_code + 10;
     419 + }
     420 + 
     421 + return `\u001b[${ansi_16_code}m`;
     422 +}
     423 + 
     424 +/**
     425 + * Detect the ANSI support for the current terminal taking into account env vars NO_COLOR and FORCE_COLOR
     426 + *
     427 + * @return {number} - 0 = no color support; 1 = 16 colors support; 2 = 256 colors support; 3 = 16 million colors support
     428 + */
     429 +function get_term_color_support() {
     430 + let term_support = supportsColor().level || 3;
     431 + 
     432 + if ('NO_COLOR' in process.env) {
     433 + term_support = 0;
     434 + }
     435 + 
     436 + if (process.env['FORCE_COLOR'] === '0') {
     437 + term_support = 0;
     438 + }
     439 + 
     440 + if (process.env['FORCE_COLOR'] === '1') {
     441 + term_support = 1;
     442 + }
     443 + 
     444 + if (process.env['FORCE_COLOR'] === '2') {
     445 + term_support = 2;
     446 + }
     447 + 
     448 + if (process.env['FORCE_COLOR'] === '3') {
     449 + term_support = 3;
     450 + }
     451 + 
     452 + return term_support;
     453 +}
     454 + 
     455 +/**
     456 + * Abstraction for coloring hex-, keyword- and background-colors
     457 + *
     458 + * @param {string} color - The color to be used
     459 + * @param {boolean} bg - Whether this is a background or not
     460 + *
     461 + * @typedef {object} ColorReturnObject
     462 + * @property {string} open - The open ansi code
     463 + * @property {string} close - The close ansi code
     464 + *
     465 + * @return {ColorReturnObject} - An object with open and close ansi codes
     466 + */
     467 +const Color = (color, bg = false) => {
     468 + const COLORS = {
     469 + black: '#000',
     470 + red: '#ea3223',
     471 + green: '#377d22',
     472 + yellow: '#fffd54',
     473 + blue: '#0020f5',
     474 + magenta: '#ea3df7',
     475 + cyan: '#74fbfd',
     476 + white: '#fff',
     477 + gray: '#808080',
     478 + redbright: '#ee776d',
     479 + greenbright: '#8cf57b',
     480 + yellowbright: '#fffb7f',
     481 + bluebright: '#6974f6',
     482 + magentabright: '#ee82f8',
     483 + cyanbright: '#8dfafd',
     484 + whitebright: '#fff',
     485 + };
     486 + 
     487 + const support = get_term_color_support();
     488 + 
     489 + // bail early if we use system color
     490 + if (color === 'system' || support === 0) {
     491 + return { open: '', close: '' };
     492 + }
     493 + 
     494 + const OPTIONS = Options.get;
     495 + 
     496 + if (OPTIONS.env === 'node') {
     497 + let open;
     498 + let close = bg ? '\u001b[49m' : '\u001b[39m';
     499 + 
     500 + switch (color.toLowerCase()) {
     501 + case 'transparent':
     502 + open = '\u001b[49m';
     503 + break;
     504 + case 'black':
     505 + open = bg ? '\u001b[40m' : '\u001b[30m';
     506 + break;
     507 + case 'red':
     508 + open = bg ? '\u001b[41m' : '\u001b[31m';
     509 + break;
     510 + case 'green':
     511 + open = bg ? '\u001b[42m' : '\u001b[32m';
     512 + break;
     513 + case 'yellow':
     514 + open = bg ? '\u001b[43m' : '\u001b[33m';
     515 + break;
     516 + case 'blue':
     517 + open = bg ? '\u001b[44m' : '\u001b[34m';
     518 + break;
     519 + case 'magenta':
     520 + open = bg ? '\u001b[45m' : '\u001b[35m';
     521 + break;
     522 + case 'cyan':
     523 + open = bg ? '\u001b[46m' : '\u001b[36m';
     524 + break;
     525 + case 'white':
     526 + open = bg ? '\u001b[47m' : '\u001b[37m';
     527 + break;
     528 + case 'gray':
     529 + open = bg ? '\u001b[100m' : '\u001b[90m';
     530 + break;
     531 + case 'redbright':
     532 + open = bg ? '\u001b[101m' : '\u001b[91m';
     533 + break;
     534 + case 'greenbright':
     535 + open = bg ? '\u001b[102m' : '\u001b[92m';
     536 + break;
     537 + case 'yellowbright':
     538 + open = bg ? '\u001b[103m' : '\u001b[93m';
     539 + break;
     540 + case 'bluebright':
     541 + open = bg ? '\u001b[104m' : '\u001b[94m';
     542 + break;
     543 + case 'magentabright':
     544 + open = bg ? '\u001b[105m' : '\u001b[95m';
     545 + break;
     546 + case 'cyanbright':
     547 + open = bg ? '\u001b[106m' : '\u001b[96m';
     548 + break;
     549 + case 'whitebright':
     550 + open = bg ? '\u001b[107m' : '\u001b[97m';
     551 + break;
     552 + case 'candy':
     553 + open = [
     554 + '\u001b[31m',
     555 + '\u001b[32m',
     556 + '\u001b[33m',
     557 + '\u001b[35m',
     558 + '\u001b[36m',
     559 + '\u001b[91m',
     560 + '\u001b[92m',
     561 + '\u001b[93m',
     562 + '\u001b[94m',
     563 + '\u001b[95m',
     564 + '\u001b[96m',
     565 + ][Math.floor(Math.random() * 11)];
     566 + break;
     567 + default: {
     568 + let hex = color;
     569 + if (!HEXTEST.test(color)) {
     570 + return { open: '', close: '' };
     571 + }
     572 + const rgb = Hex2rgb(hex);
     573 + 
     574 + if (support === 1) {
     575 + open = ansi_2562ansi_16(rgb2ansi256Code(rgb[0], rgb[1], rgb[2]), bg);
     576 + }
     577 + if (support === 2) {
     578 + open = rgb2ansi_256(rgb[0], rgb[1], rgb[2], bg);
     579 + }
     580 + if (support === 3) {
     581 + open = rgb2ansi_16m(rgb[0], rgb[1], rgb[2], bg);
     582 + }
     583 + }
     584 + }
     585 + return { open, close };
     586 + } else if (!OPTIONS.env) {
     587 + return { open: '', close: '' };
     588 + } else {
     589 + if (!HEXTEST.test(color)) {
     590 + color = COLORS[color.toLowerCase()];
     591 + if (!color) {
     592 + return { open: '', close: '' };
     593 + }
     594 + }
     595 + 
     596 + if (bg) {
     597 + return {
     598 + open: color,
     599 + close: '',
     600 + };
     601 + }
     602 + 
     603 + return {
     604 + open: `<span style="color:${color}">`,
     605 + close: '</span>',
     606 + };
     607 + }
     608 +};
     609 + 
     610 +module.exports = exports = {
     611 + HEXTEST,
     612 + Rgb2hsv,
     613 + Hsv2rgb,
     614 + Rgb2hex,
     615 + Hex2rgb,
     616 + Hsv2hsvRad,
     617 + HsvRad2hsv,
     618 + Hex2hsvRad,
     619 + HsvRad2hex,
     620 + rgb2ansi_16m,
     621 + rgb2ansi256Code,
     622 + rgb2ansi_256,
     623 + ansi_2562ansi_16,
     624 + get_term_color_support,
     625 + Color,
     626 +};
     627 + 
  • ■ ■ ■ ■ ■ ■
    nodejs/src/Colorize.js
     1 +/***************************************************************************************************************************************************************
     2 + *
     3 + * cfonts
     4 + *
     5 + * Sexy fonts for the console. (CLI output)
     6 + *
     7 + * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv3
     8 + * @author Dominik Wilkowski [email protected]
     9 + * @repository https://github.com/dominikwilkowski/cfonts
     10 + *
     11 + * Colorize
     12 + * Replace placeholders with color information
     13 + *
     14 + **************************************************************************************************************************************************************/
     15 + 
     16 +'use strict';
     17 + 
     18 +const { Debugging } = require('./Debugging.js');
     19 +const { Color } = require('./Color.js');
     20 + 
     21 +/**
     22 + * Replace placeholders with color information
     23 + *
     24 + * @param {string} character - The string to be converted
     25 + * @param {number} fontColors - The number of allowed colors for this font
     26 + * @param {array} optionColors - An array of user defined colors
     27 + *
     28 + * @return {string} - The character with color ansi escape sequences for CLI
     29 + */
     30 +const Colorize = (character, fontColors, optionColors) => {
     31 + Debugging.report(`Running Colorize`, 1);
     32 + 
     33 + if (character !== undefined) {
     34 + if (fontColors > 1) {
     35 + // we have to replace all color placeholder with ansi escape sequences
     36 + for (let i = 0; i < fontColors; i++) {
     37 + const color = optionColors[i] || 'system';
     38 + 
     39 + const { open: openNew, close: closeNew } = Color(color);
     40 + 
     41 + const open = new RegExp(`<c${i + 1}>`, 'g');
     42 + const close = new RegExp(`</c${i + 1}>`, 'g');
     43 + 
     44 + character = character.replace(open, openNew);
     45 + character = character.replace(close, closeNew);
     46 + }
     47 + }
     48 + 
     49 + // if only one color is allowed there won't be any color placeholders in the characters
     50 + if (fontColors === 1) {
     51 + const color = optionColors[0] || 'system';
     52 + 
     53 + const { open: openNew, close: closeNew } = Color(color);
     54 + 
     55 + character = openNew + character + closeNew;
     56 + }
     57 + }
     58 + 
     59 + return character;
     60 +};
     61 + 
     62 +module.exports = exports = {
     63 + Colorize,
     64 +};
     65 + 
  • ■ ■ ■ ■ ■ ■
    src/Debugging.js nodejs/src/Debugging.js
    skipped 3 lines
    4 4   *
    5 5   * Sexy fonts for the console. (CLI output)
    6 6   *
    7  - * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv2
     7 + * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv3
    8 8   * @author Dominik Wilkowski [email protected]
    9 9   * @repository https://github.com/dominikwilkowski/cfonts
    10 10   *
    skipped 4 lines
    15 15   
    16 16  'use strict';
    17 17   
    18  -const { Chalk } = require('./Chalk.js');
    19  - 
     18 +const { Color } = require('./Color.js');
    20 19   
    21 20  /**
    22 21   * DEBUG object for tracking debug mode and level
    skipped 6 lines
    29 28   level: 2,
    30 29   },
    31 30   
    32  - set enabled( value ) {
     31 + set enabled(value) {
    33 32   this.store.enabled = value;
    34 33   },
    35 34   
    skipped 1 lines
    37 36   return this.store.enabled;
    38 37   },
    39 38   
    40  - set level( value ) {
     39 + set level(value) {
    41 40   this.store.level = value;
    42 41   },
    43 42   
    skipped 16 lines
    60 59   * @param {boolean} debug - Global debug mode on/off
    61 60   * @param {number} debuglevel - Global debug level
    62 61   */
    63  - headline: ( text, level = 99, debug = DEBUG.enabled, debuglevel = DEBUG.level ) => {
    64  - if( debug && level >= debuglevel ) {
    65  - console.log(
    66  - Chalk.bgWhite(`\n${ Chalk.bold(' \u2611 ') } ${ text }`)
    67  - );
     62 + headline: (text, level = 99, debug = DEBUG.enabled, debuglevel = DEBUG.level) => {
     63 + if (debug && level >= debuglevel) {
     64 + const { open, close } = Color('black', true);
     65 + console.log(`${open}\n\u001b[1m \u2611 \u001b[22m ${text}${close}`);
    68 66   }
    69 67   },
    70 68   
    skipped 5 lines
    76 74   * @param {boolean} debug - Global debug mode on/off
    77 75   * @param {number} debuglevel - Global debug level
    78 76   */
    79  - report: ( text, level = 99, debug = DEBUG.enabled, debuglevel = DEBUG.level ) => {
    80  - if( debug && level >= debuglevel ) {
     77 + report: (text, level = 99, debug = DEBUG.enabled, debuglevel = DEBUG.level) => {
     78 + if (debug && level >= debuglevel) {
     79 + const { open: blackbg_open, close: blackbg_close } = Color('black', true);
     80 + const { open: green_open, close: green_close } = Color('green');
     81 + const { open: white_open, close: white_close } = Color('white');
    81 82   console.log(
    82  - Chalk.bgWhite(`\n${ Chalk.bold.green(' \u2611 ') } ${ Chalk.black(`${ text } `) }`)
     83 + `${blackbg_open}\n\u001b[1m${green_open} \u2611 ${green_close}\u001b[22m ${white_open}${text}${white_close}${blackbg_close}`
    83 84   );
    84 85   }
    85 86   },
    skipped 6 lines
    92 93   * @param {boolean} debug - Global debug mode on/off
    93 94   * @param {number} debuglevel - Global debug level
    94 95   */
    95  - error: ( text, level = 99, debug = DEBUG.enabled, debuglevel = DEBUG.level ) => {
    96  - if( debug && level >= debuglevel ) {
     96 + error: (text, level = 99, debug = DEBUG.enabled, debuglevel = DEBUG.level) => {
     97 + if (debug && level >= debuglevel) {
     98 + const { open: blackbg_open, close: blackbg_close } = Color('black', true);
     99 + const { open: red_open, close: red_close } = Color('red');
     100 + const { open: white_open, close: white_close } = Color('white');
    97 101   console.error(
    98  - Chalk.bgWhite(`\n${ Chalk.red(' \u2612 ') } ${ Chalk.black(`${ text } `) }`)
     102 + `${blackbg_open}\n${red_open} \u2612 ${red_close} ${white_open}${text}${white_close}${blackbg_close}`
    99 103   );
    100 104   }
    101 105   },
    102 106  };
    103  - 
    104 107   
    105 108  module.exports = exports = {
    106 109   DEBUG,
    skipped 3 lines
  • ■ ■ ■ ■ ■ ■
    nodejs/src/DisplayHelp.js
     1 +/***************************************************************************************************************************************************************
     2 + *
     3 + * cfonts
     4 + *
     5 + * Sexy fonts for the console. (CLI output)
     6 + *
     7 + * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv3
     8 + * @author Dominik Wilkowski [email protected]
     9 + * @repository https://github.com/dominikwilkowski/cfonts
     10 + *
     11 + * DisplayHelp
     12 + * Display the help generated from our CLIOPTIONS
     13 + *
     14 + **************************************************************************************************************************************************************/
     15 + 
     16 +'use strict';
     17 + 
     18 +const { CLIOPTIONS } = require('./constants.js');
     19 +const { Render } = require('./Render.js');
     20 +const { Color } = require('./Color.js');
     21 + 
     22 +/**
     23 + * Display the help generated from our CLIOPTIONS
     24 + */
     25 +const DisplayHelp = () => {
     26 + const { string: headline } = Render('cfonts', {
     27 + align: 'left',
     28 + gradient: ['red', 'green'],
     29 + });
     30 + 
     31 + console.log(
     32 + ` ${headline}` +
     33 + `This is a tool for sexy fonts in the console. Give your cli some love.\n\n` +
     34 + `Usage: cfonts "<value>" [option1] <input1> [option2] <input1>,<input2> [option3]\n` +
     35 + `Example: \u001b[1m$ cfonts "sexy font" -f chrome -a center -c red,green,gray\u001b[22m\n\n` +
     36 + `Options:\n`
     37 + );
     38 + 
     39 + const { open, close } = Color('green');
     40 + 
     41 + Object.keys(CLIOPTIONS).forEach((option) => {
     42 + console.log(`\u001b[1m${option}, ${CLIOPTIONS[option].short}\u001b[22m`);
     43 + console.log(CLIOPTIONS[option].description);
     44 + console.log(
     45 + `\u001b[1m$\u001b[22m cfonts ${CLIOPTIONS[option].example
     46 + .replace(/\[green-open\]/g, open)
     47 + .replace(/\[green-close\]/g, close)}\n`
     48 + );
     49 + });
     50 +};
     51 + 
     52 +module.exports = exports = {
     53 + DisplayHelp,
     54 +};
     55 + 
  • ■ ■ ■ ■ ■ ■
    src/DisplayVersion.js nodejs/src/DisplayVersion.js
    skipped 3 lines
    4 4   *
    5 5   * Sexy fonts for the console. (CLI output)
    6 6   *
    7  - * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv2
     7 + * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv3
    8 8   * @author Dominik Wilkowski [email protected]
    9 9   * @repository https://github.com/dominikwilkowski/cfonts
    10 10   *
    skipped 6 lines
    17 17   
    18 18  const { PACKAGE } = require('./constants.js');
    19 19   
    20  - 
    21 20  /**
    22 21   * Display the version of this package
    23 22   */
    24 23  const DisplayVersion = () => {
    25  - console.log( PACKAGE.version );
     24 + console.log(PACKAGE.version);
    26 25  };
    27  - 
    28 26   
    29 27  module.exports = exports = {
    30 28   DisplayVersion,
    skipped 2 lines
  • ■ ■ ■ ■ ■ ■
    src/GetFirstCharacterPosition.js nodejs/src/GetFirstCharacterPosition.js
    skipped 3 lines
    4 4   *
    5 5   * Sexy fonts for the console. (CLI output)
    6 6   *
    7  - * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv2
     7 + * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv3
    8 8   * @author Dominik Wilkowski [email protected]
    9 9   * @repository https://github.com/dominikwilkowski/cfonts
    10 10   *
    skipped 4 lines
    15 15   
    16 16  'use strict';
    17 17   
    18  - 
    19 18  /**
    20 19   * Get the position of the first character out of all strings inside an array
    21 20   *
    skipped 1 lines
    23 22   *
    24 23   * @return {number} - The position of the first character
    25 24   */
    26  -function GetFirstCharacterPosition( lines ) {
     25 +function GetFirstCharacterPosition(lines) {
    27 26   const earliest = lines.reduce(
    28  - ( prevLine, line ) => ( ( line.length - line.trimStart().length ) < ( prevLine.length - prevLine.trimStart().length ) && line !== '' ? line : prevLine )
    29  - , lines[ 0 ]
     27 + (prevLine, line) =>
     28 + line.length - line.trimStart().length < prevLine.length - prevLine.trimStart().length && line !== ''
     29 + ? line
     30 + : prevLine,
     31 + lines[0]
    30 32   );
    31 33   
    32  - return ( earliest.length - earliest.trimStart().length );
     34 + return earliest.length - earliest.trimStart().length;
    33 35  }
    34  - 
    35 36   
    36 37  module.exports = exports = {
    37 38   GetFirstCharacterPosition,
    skipped 2 lines
  • ■ ■ ■ ■ ■ ■
    src/GetFont.js nodejs/src/GetFont.js
    skipped 3 lines
    4 4   *
    5 5   * Sexy fonts for the console. (CLI output)
    6 6   *
    7  - * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv2
     7 + * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv3
    8 8   * @author Dominik Wilkowski [email protected]
    9 9   * @repository https://github.com/dominikwilkowski/cfonts
    10 10   *
    skipped 4 lines
    15 15   
    16 16  'use strict';
    17 17   
     18 +const path = require('path');
     19 + 
    18 20  const { Debugging } = require('./Debugging.js');
    19  - 
    20 21   
    21 22  /**
    22 23   * Get a selected JSON font-file object
    skipped 2 lines
    25 26   *
    26 27   * @return {object} - The font object of that file
    27 28   */
    28  -const GetFont = ( font ) => {
    29  - Debugging.report( `Running GetFont`, 1 );
     29 +const GetFont = (font) => {
     30 + Debugging.report(`Running GetFont`, 1);
    30 31   
    31 32   // try loading the font file
    32 33   try {
    33  - let FONTFACE = require(`../fonts/${ font }.json`); // read font file
     34 + let FONTFACE = require(path.normalize(`../fonts/${font}.json`)); // read font file
    34 35   
    35  - Debugging.report( `GetFont: Fontface path selected: "${ font }.json"`, 2 );
     36 + Debugging.report(`GetFont: Fontface path selected: "${font}.json"`, 2);
    36 37   
    37 38   return FONTFACE;
    38  - }
    39  - catch( error ) {
    40  - Debugging.error( `Font file for "${ font }" errored out: ${ error }`, 2 );
     39 + } catch (error) {
     40 + Debugging.error(`Font file for "${font}" errored out: ${error}`, 2);
    41 41   
    42 42   return false;
    43 43   }
    44 44  };
    45  - 
    46 45   
    47 46  module.exports = exports = {
    48 47   GetFont,
    skipped 2 lines
  • ■ ■ ■ ■ ■ ■
    src/GetLongestLine.js nodejs/src/GetLongestLine.js
    skipped 3 lines
    4 4   *
    5 5   * Sexy fonts for the console. (CLI output)
    6 6   *
    7  - * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv2
     7 + * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv3
    8 8   * @author Dominik Wilkowski [email protected]
    9 9   * @repository https://github.com/dominikwilkowski/cfonts
    10 10   *
    skipped 4 lines
    15 15   
    16 16  'use strict';
    17 17   
    18  - 
    19 18  /**
    20 19   * Return the longest line of an Array
    21 20   *
    skipped 1 lines
    23 22   *
    24 23   * @return {string} - The longest string from within the array
    25 24   */
    26  -const GetLongestLine = lines => lines.reduce( ( longestLine, line ) => ( line.length > longestLine.length && line.length !== 0 ? line : longestLine ), '' );
    27  - 
     25 +const GetLongestLine = (lines) =>
     26 + lines.reduce((longestLine, line) => (line.length > longestLine.length && line.length !== 0 ? line : longestLine), '');
    28 27   
    29 28  module.exports = exports = {
    30 29   GetLongestLine,
    skipped 2 lines
  • ■ ■ ■ ■ ■ ■
    nodejs/src/Gradient.js
     1 +/***************************************************************************************************************************************************************
     2 + *
     3 + * cfonts
     4 + *
     5 + * Sexy fonts for the console. (CLI output)
     6 + *
     7 + * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv3
     8 + * @author Dominik Wilkowski [email protected]
     9 + * @repository https://github.com/dominikwilkowski/cfonts
     10 + *
     11 + * GetLinear - Interpolate a linear path from a number to another number
     12 + * GetTheta - Interpolate a radial path from a number to another number
     13 + * GetGradientColors - Generate the most colorful delta between two colors
     14 + * PaintLines - Take a bunch of lines and color them in the colors provided
     15 + * Color2hex - Make sure a color is hex
     16 + * GetGaps - Calculate the gaps between an array of points
     17 + * TransitionBetweenHex - Generate colors between two given colors
     18 + * Transition - Generate n colors between x colors
     19 + * PaintGradient - Paint finished output in a gradient
     20 + *
     21 + **************************************************************************************************************************************************************/
     22 + 
     23 +'use strict';
     24 + 
     25 +const { GetFirstCharacterPosition } = require('./GetFirstCharacterPosition.js');
     26 +const { Color, Hex2rgb, Hex2hsvRad, HsvRad2hex, Rgb2hex } = require('./Color.js');
     27 +const { GetLongestLine } = require('./GetLongestLine.js');
     28 +const { GRADIENTS } = require('./constants.js');
     29 +const { Debugging } = require('./Debugging.js');
     30 + 
     31 +/**
     32 + * Interpolate a linear path from a number to another number
     33 + *
     34 + * @param {number} pointA - The number from which to start
     35 + * @param {number} pointB - The number to go to
     36 + * @param {number} n - The current step
     37 + * @param {number} steps - The amount of steps
     38 + *
     39 + * @return {number} - The number at step n
     40 + */
     41 +function GetLinear(pointA, pointB, n, steps) {
     42 + if (steps === 0) {
     43 + return pointB;
     44 + }
     45 + 
     46 + return pointA + n * ((pointB - pointA) / steps);
     47 +}
     48 + 
     49 +/**
     50 + * Interpolate a radial path from a number to another number
     51 + *
     52 + * @param {number} fromTheta - The radian from which to start
     53 + * @param {number} toTheta - The radian to go to
     54 + * @param {number} n - The current step
     55 + * @param {number} steps - The amount of steps
     56 + *
     57 + * @return {number} - The radian at step n
     58 + */
     59 +function GetTheta(fromTheta, toTheta, n, steps) {
     60 + const TAU = 2 * Math.PI;
     61 + let longDistance;
     62 + 
     63 + if (steps === 0) {
     64 + return toTheta;
     65 + }
     66 + 
     67 + if (fromTheta > toTheta) {
     68 + if (fromTheta - toTheta < Math.PI) {
     69 + longDistance = TAU - (fromTheta - toTheta);
     70 + } else {
     71 + longDistance = toTheta - fromTheta;
     72 + }
     73 + } else {
     74 + if (toTheta - fromTheta < Math.PI) {
     75 + longDistance = toTheta - fromTheta - TAU;
     76 + } else {
     77 + longDistance = -1 * (fromTheta - toTheta);
     78 + }
     79 + }
     80 + 
     81 + let result = fromTheta + n * (longDistance / steps);
     82 + 
     83 + if (result < 0) {
     84 + result += TAU;
     85 + }
     86 + 
     87 + if (result > TAU) {
     88 + result -= TAU;
     89 + }
     90 + 
     91 + return result;
     92 +}
     93 + 
     94 +/**
     95 + * Generate the most colorful delta between two colors
     96 + *
     97 + * @param {string} fromColor - The color from which to start
     98 + * @param {string} toColor - The color to go to
     99 + * @param {number} steps - The amount of colors of the gradient
     100 + *
     101 + * @return {array} - An array of colors
     102 + */
     103 +function GetGradientColors(fromColor, toColor, steps) {
     104 + const [fromHRad, fromS, fromV] = Hex2hsvRad(fromColor);
     105 + const [toHRad, toS, toV] = Hex2hsvRad(toColor);
     106 + 
     107 + const hexColors = [];
     108 + 
     109 + for (let n = 0; n < steps; n++) {
     110 + const hRad = GetTheta(fromHRad, toHRad, n, steps - 1);
     111 + const s = GetLinear(fromS, toS, n, steps - 1);
     112 + const v = GetLinear(fromV, toV, n, steps - 1);
     113 + 
     114 + hexColors.push(HsvRad2hex(hRad, s, v));
     115 + }
     116 + 
     117 + return hexColors;
     118 +}
     119 + 
     120 +/**
     121 + * Take a bunch of lines and color them in the colors provided
     122 + *
     123 + * @param {array} lines - The lines to be colored
     124 + * @param {array} colors - The colors in an array
     125 + * @param {number} firstCharacterPosition - We may have to cut something off from the start when text is aligned center, right
     126 + *
     127 + * @return {array} - The lines in color
     128 + */
     129 +function PaintLines(lines, colors, firstCharacterPosition) {
     130 + Debugging.report(`Running PaintLines`, 1);
     131 + 
     132 + Debugging.report(colors, 2);
     133 + 
     134 + const space = ' '.repeat(firstCharacterPosition);
     135 + 
     136 + return lines.map((line) => {
     137 + const coloredLine = line
     138 + .slice(firstCharacterPosition)
     139 + .split('')
     140 + .map((char, i) => {
     141 + const { open, close } = Color(colors[i]);
     142 + return `${open}${char}${close}`;
     143 + })
     144 + .join('');
     145 + 
     146 + return `${space}${coloredLine}`;
     147 + });
     148 +}
     149 + 
     150 +/**
     151 + * Make sure a color is hex
     152 + *
     153 + * @param {string} color - The color
     154 + *
     155 + * @return {string} - The hex color
     156 + */
     157 +function Color2hex(color) {
     158 + const colorMap = {
     159 + black: '#000000',
     160 + red: '#ff0000',
     161 + green: '#00ff00',
     162 + yellow: '#ffff00',
     163 + blue: '#0000ff',
     164 + magenta: '#ff00ff',
     165 + cyan: '#00ffff',
     166 + white: '#ffffff',
     167 + gray: '#808080',
     168 + grey: '#808080',
     169 + };
     170 + 
     171 + return colorMap[color] || color;
     172 +}
     173 + 
     174 +/**
     175 + * Calculate the gaps between an array of points
     176 + *
     177 + * @param {array} points - An array of points, it's not important what's in the array for this function
     178 + * @param {number} steps - The amount of steps we have to distribute between the above points
     179 + *
     180 + * @return {array} - An array of steps per gap
     181 + */
     182 +function GetGaps(points, steps) {
     183 + // steps per gap
     184 + const gapSteps = Math.floor((steps - points.length) / (points.length - 1));
     185 + // steps left over to be distributed
     186 + const rest = steps - (points.length + gapSteps * (points.length - 1));
     187 + // the gaps array has one less items than our points (cause it's gaps between each of the points)
     188 + const gaps = Array(points.length - 1).fill(gapSteps);
     189 + 
     190 + // let's fill in the rest from the right
     191 + for (let i = 0; i < rest; i++) {
     192 + gaps[gaps.length - 1 - i]++;
     193 + }
     194 + 
     195 + return gaps;
     196 +}
     197 + 
     198 +/**
     199 + * Generate colors between two given colors
     200 + *
     201 + * @param {string} fromHex - The color we start from in hex
     202 + * @param {string} toHex - The color we end up at in hex
     203 + * @param {number} steps - How many colors should be returned
     204 + *
     205 + * @return {array} - An array for colors
     206 + */
     207 +function TransitionBetweenHex(fromHex, toHex, steps) {
     208 + const fromRgb = Hex2rgb(fromHex);
     209 + const toRgb = Hex2rgb(toHex);
     210 + const hexColors = [];
     211 + steps++;
     212 + 
     213 + for (let n = 1; n < steps; n++) {
     214 + const red = GetLinear(fromRgb[0], toRgb[0], n, steps);
     215 + const green = GetLinear(fromRgb[1], toRgb[1], n, steps);
     216 + const blue = GetLinear(fromRgb[2], toRgb[2], n, steps);
     217 + 
     218 + hexColors.push(Rgb2hex(red, green, blue));
     219 + }
     220 + 
     221 + return hexColors;
     222 +}
     223 + 
     224 +/**
     225 + * Generate n colors between x colors
     226 + *
     227 + * @param {array} colors - An array of colors in hex
     228 + * @param {number} steps - The amount of colors to generate
     229 + * @param {object} gradients - An object of pre-packaged gradient colors
     230 + *
     231 + * @return {array} - An array of colors
     232 + */
     233 +function Transition(colors, steps, gradients = GRADIENTS) {
     234 + let hexColors = [];
     235 + if (colors.length === 1) {
     236 + colors = gradients[colors[0].toLowerCase()];
     237 + } else {
     238 + colors = colors.map((color) => Color2hex(color));
     239 + }
     240 + const gaps = GetGaps(colors, steps);
     241 + 
     242 + if (steps <= 1) {
     243 + return [colors[colors.length - 1]];
     244 + }
     245 + 
     246 + for (let i = 0; i < colors.length; i++) {
     247 + const gap = gaps[i - 1];
     248 + 
     249 + if (colors[i - 1]) {
     250 + const gapColors = TransitionBetweenHex(colors[i - 1], colors[i], gap);
     251 + hexColors = [...hexColors, ...gapColors];
     252 + }
     253 + 
     254 + if (gap !== -1) {
     255 + hexColors.push(colors[i]);
     256 + }
     257 + }
     258 + 
     259 + return hexColors;
     260 +}
     261 + 
     262 +/**
     263 + * Paint finished output in a gradient
     264 + *
     265 + * @param {object} options - Arguments
     266 + * @param {array} options.output - The output to be painted
     267 + * @param {array} options.gradient - An array of two colors for start and end of gradient
     268 + * @param {number} options.lines - How many lines the output contains
     269 + * @param {number} options.lineHeight - The line height between lines
     270 + * @param {number} options.fontLines - The line height (line breaks) of a single font line
     271 + * @param {boolean} options.independentGradient - A switch to calculate gradient per line or not
     272 + * @param {boolean} options.transitionGradient - A switch for transition gradients
     273 + *
     274 + * @return {array} - The output array painted in ANSI colors
     275 + */
     276 +function PaintGradient({ output, gradient, lines, lineHeight, fontLines, independentGradient, transitionGradient }) {
     277 + Debugging.report(`Running PaintGradient`, 1);
     278 + let newOutput = [];
     279 + 
     280 + if (transitionGradient) {
     281 + Debugging.report(`Gradient transition with colors: ${JSON.stringify(gradient)}`, 2);
     282 + } else {
     283 + Debugging.report(`Gradient start: ${gradient[0]} | Gradient end: ${gradient[1]}`, 2);
     284 + }
     285 + 
     286 + let firstCharacterPosition = GetFirstCharacterPosition(output);
     287 + let longestLine = GetLongestLine(output).length;
     288 + 
     289 + for (let i = 0; i < lines; i++) {
     290 + const start = i * (fontLines + lineHeight);
     291 + const end = fontLines + start;
     292 + const thisLine = output.slice(start, end);
     293 + 
     294 + if (independentGradient) {
     295 + firstCharacterPosition = GetFirstCharacterPosition(thisLine);
     296 + longestLine = GetLongestLine(thisLine).length;
     297 + }
     298 + 
     299 + const colorsNeeded = longestLine - firstCharacterPosition;
     300 + const linesInbetween = i === 0 ? [] : Array(lineHeight).fill('');
     301 + 
     302 + Debugging.report(`longestLine: ${longestLine} | firstCharacterPosition: ${firstCharacterPosition}`, 2);
     303 + 
     304 + const colors = transitionGradient
     305 + ? Transition(gradient, colorsNeeded)
     306 + : GetGradientColors(Color2hex(gradient[0]), Color2hex(gradient[1]), colorsNeeded);
     307 + 
     308 + newOutput = [...newOutput, ...linesInbetween, ...PaintLines(thisLine, colors, firstCharacterPosition)];
     309 + }
     310 + 
     311 + return newOutput;
     312 +}
     313 + 
     314 +module.exports = exports = {
     315 + GetLinear,
     316 + GetTheta,
     317 + GetGradientColors,
     318 + PaintLines,
     319 + Color2hex,
     320 + GetGaps,
     321 + TransitionBetweenHex,
     322 + Transition,
     323 + PaintGradient,
     324 +};
     325 + 
  • ■ ■ ■ ■ ■ ■
    src/Log.js nodejs/src/Log.js
    skipped 3 lines
    4 4   *
    5 5   * Sexy fonts for the console. (CLI output)
    6 6   *
    7  - * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv2
     7 + * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv3
    8 8   * @author Dominik Wilkowski [email protected]
    9 9   * @repository https://github.com/dominikwilkowski/cfonts
    10 10   *
    skipped 4 lines
    15 15   
    16 16  'use strict';
    17 17   
    18  -const { Chalk } = require('./Chalk.js');
    19  - 
     18 +const { Color } = require('./Color.js');
    20 19   
    21 20  /**
    22 21   * Logging prettiness
    skipped 6 lines
    29 28   *
    30 29   * @param {string} text - The sting you want to log
    31 30   */
    32  - error: ( text ) => {
    33  - text = text.replace( /(?:\r\n|\r|\n)/g, '\n ' ); // indent each line
    34  - 
    35  - console.error(`\n ${ Chalk.bold.red('Ouch:') } ${ text }\n`);
     31 + error: (text) => {
     32 + text = text.replace(/(?:\r\n|\r|\n)/g, '\n '); // indent each line
     33 + const { open, close } = Color('red');
     34 + console.error(`\n \u001b[1m${open}Ouch:${close}\u001b[22m ${text}\n`);
    36 35   },
    37 36  };
    38  - 
    39 37   
    40 38  module.exports = exports = {
    41 39   Log,
    skipped 2 lines
  • ■ ■ ■ ■ ■ ■
    src/Options.js nodejs/src/Options.js
    skipped 3 lines
    4 4   *
    5 5   * Sexy fonts for the console. (CLI output)
    6 6   *
    7  - * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv2
     7 + * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv3
    8 8   * @author Dominik Wilkowski [email protected]
    9 9   * @repository https://github.com/dominikwilkowski/cfonts
    10 10   *
    skipped 4 lines
    15 15   
    16 16  'use strict';
    17 17   
    18  -const {
    19  - COLORS,
    20  - BGCOLORS,
    21  - FONTFACES,
    22  -} = require('./constants.js');
    23  - 
     18 +const { COLORS, BGCOLORS, FONTFACES } = require('./constants.js');
    24 19   
    25 20  /**
    26 21   * The options store with getter and setter methods
    skipped 38 lines
    65 60   * @param {string} options.font - Font face, Default 'block'
    66 61   * @param {string} options.align - Text alignment, Default: 'left'
    67 62   * @param {array} options.colors - Colors for font, Default: []
    68  - * @param {string} options.background - Chalk color string for background, Default 'Black'
     63 + * @param {string} options.background - Color string for background, Default 'Black'
    69 64   * @param {string} options.backgroundColor - Alias for background
    70 65   * @param {number} options.letterSpacing - Space between letters, Default: set by selected font face
    71 66   * @param {number} options.lineHeight - Space between lines, Default: 1
    skipped 25 lines
    97 92   allowedBG = BGCOLORS,
    98 93   allowedFont = FONTFACES,
    99 94   }) {
    100  - this.store.font = font !== ''
    101  - ? allowedFont[ font.toLowerCase() ] || font
    102  - : this.store.font;
     95 + this.store.font = font !== '' ? allowedFont[font.toLowerCase()] || font : this.store.font;
    103 96   
    104  - this.store.align = align !== undefined
    105  - ? align.toLowerCase()
    106  - : this.store.align;
     97 + this.store.align = align !== undefined ? align.toLowerCase() : this.store.align;
    107 98   
    108  - this.store.colors = Array.isArray( colors )
    109  - ? colors.map( color => allowedColors[ color.toLowerCase() ] || color )
     99 + this.store.colors = Array.isArray(colors)
     100 + ? colors.map((color) => allowedColors[color.toLowerCase()] || color)
    110 101   : this.store.colors;
    111 102   
    112 103   const bg = backgroundColor || background;
    113  - this.store.background = bg !== undefined
    114  - ? allowedBG[ bg.toLowerCase() ] || bg
    115  - : this.store.background;
     104 + this.store.background = bg !== undefined ? allowedBG[bg.toLowerCase()] || bg : this.store.background;
    116 105   
    117  - this.store.letterSpacing = letterSpacing !== undefined
    118  - ? parseInt( letterSpacing.toString() )
    119  - : font.toLowerCase() === 'console'
     106 + this.store.letterSpacing =
     107 + letterSpacing !== undefined
     108 + ? parseInt(letterSpacing.toString())
     109 + : font.toLowerCase() === 'console'
    120 110   ? 0
    121 111   : this.store.letterSpacing;
    122 112   
    123  - this.store.lineHeight = lineHeight !== undefined
    124  - ? parseInt( lineHeight.toString() )
    125  - : font.toLowerCase() === 'console'
     113 + this.store.lineHeight =
     114 + lineHeight !== undefined
     115 + ? parseInt(lineHeight.toString())
     116 + : font.toLowerCase() === 'console'
    126 117   ? 0
    127 118   : this.store.lineHeight;
    128 119   
    129  - this.store.space = typeof space === 'boolean'
    130  - ? space
    131  - : this.store.space;
     120 + this.store.space = typeof space === 'boolean' ? space : this.store.space;
    132 121   
    133  - this.store.maxLength = maxLength !== undefined
    134  - ? maxLength
    135  - : this.store.maxLength;
     122 + this.store.maxLength = maxLength !== undefined ? maxLength : this.store.maxLength;
    136 123   
    137  - this.store.gradient = gradient !== undefined && typeof gradient !== 'boolean'
    138  - ? Array.isArray( gradient )
    139  - ? gradient
    140  - : gradient.split(',')
    141  - : gradient === false
     124 + this.store.gradient =
     125 + gradient !== undefined && typeof gradient !== 'boolean'
     126 + ? Array.isArray(gradient)
     127 + ? gradient
     128 + : gradient.split(',')
     129 + : gradient === false
    142 130   ? false
    143 131   : this.store.gradient;
    144 132   
    145  - this.store.independentGradient = independentGradient !== undefined
    146  - ? independentGradient
    147  - : this.store.independentGradient;
     133 + this.store.independentGradient =
     134 + independentGradient !== undefined ? independentGradient : this.store.independentGradient;
    148 135   
    149  - this.store.transitionGradient = transitionGradient !== undefined
    150  - ? transitionGradient
    151  - : this.store.transitionGradient;
     136 + this.store.transitionGradient =
     137 + transitionGradient !== undefined ? transitionGradient : this.store.transitionGradient;
    152 138   
    153  - this.store.env = env !== undefined
    154  - ? env
    155  - : this.store.env;
     139 + this.store.env = env !== undefined ? env : this.store.env;
    156 140   },
    157 141  };
    158  - 
    159 142   
    160 143  module.exports = exports = {
    161 144   Options,
    skipped 2 lines
  • ■ ■ ■ ■ ■ ■
    nodejs/src/ParseArgs.js
     1 +/***************************************************************************************************************************************************************
     2 + *
     3 + * cfonts
     4 + *
     5 + * Sexy fonts for the console. (CLI output)
     6 + *
     7 + * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv3
     8 + * @author Dominik Wilkowski [email protected]
     9 + * @repository https://github.com/dominikwilkowski/cfonts
     10 + *
     11 + * ParseArgs
     12 + * Parse cli arguments into a nice object
     13 + *
     14 + **************************************************************************************************************************************************************/
     15 + 
     16 +'use strict';
     17 + 
     18 +const { AddShortcuts } = require('./AddShortcuts.js');
     19 +const { CLIOPTIONS } = require('./constants.js');
     20 +const { Debugging } = require('./Debugging.js');
     21 + 
     22 +/**
     23 + * Parse cli arguments into a nice object
     24 + *
     25 + * @param {object} inputOptions - All possible options registered for this app
     26 + * @param {array} inputArgs - The arguments given to us in our cli, default: process.argv
     27 + *
     28 + * @return {object} - An object of all options with at least their default values
     29 + */
     30 +const ParseArgs = (inputOptions = CLIOPTIONS, inputArgs = process.argv) => {
     31 + const parsedArgs = {
     32 + text: inputArgs[2],
     33 + };
     34 + 
     35 + // create defaults
     36 + Object.keys(inputOptions).forEach((option) => {
     37 + const name = option.replace('--', '');
     38 + 
     39 + parsedArgs[name] = inputOptions[option].default;
     40 + });
     41 + 
     42 + if (inputArgs[2] === '--help' || inputArgs[2] === '-h') {
     43 + parsedArgs.help = true;
     44 + }
     45 + 
     46 + if (inputArgs[2] === '--version' || inputArgs[2] === '-v') {
     47 + parsedArgs.version = true;
     48 + }
     49 + 
     50 + const args = inputArgs.splice(3); // the first two are node specific, the third is our text
     51 + 
     52 + const options = AddShortcuts(inputOptions);
     53 + 
     54 + for (let index = 0; args.length > index; index++) {
     55 + const option = options[args[index]];
     56 + 
     57 + if (option) {
     58 + const name = option._name.replace('--', '');
     59 + 
     60 + if (option.options !== undefined) {
     61 + index++;
     62 + const value = args[index];
     63 + 
     64 + parsedArgs[name] = value;
     65 + } else {
     66 + parsedArgs[name] = true;
     67 + }
     68 + } else {
     69 + Debugging.report(`The cli argument ${args[index]} was not found and ignored`, 2);
     70 + }
     71 + }
     72 + 
     73 + return parsedArgs;
     74 +};
     75 + 
     76 +module.exports = exports = {
     77 + ParseArgs,
     78 +};
     79 + 
  • ■ ■ ■ ■ ■ ■
    nodejs/src/Render.js
     1 +/***************************************************************************************************************************************************************
     2 + *
     3 + * cfonts
     4 + *
     5 + * Sexy fonts for the console. (CLI output)
     6 + *
     7 + * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv3
     8 + * @author Dominik Wilkowski [email protected]
     9 + * @repository https://github.com/dominikwilkowski/cfonts
     10 + *
     11 + * Render
     12 + * Main method to get the ANSI output for a string
     13 + *
     14 + **************************************************************************************************************************************************************/
     15 + 
     16 +'use strict';
     17 + 
     18 +const { AddLetterSpacing } = require('./AddLetterSpacing.js');
     19 +const { Debugging, DEBUG } = require('./Debugging.js');
     20 +const { PaintGradient } = require('./Gradient.js');
     21 +const { CharLength } = require('./CharLength.js');
     22 +const { CheckInput } = require('./CheckInput.js');
     23 +const { CleanInput } = require('./CleanInput.js');
     24 +const { AlignText } = require('./AlignText.js');
     25 +const { AddLine } = require('./AddLine.js');
     26 +const { AddChar } = require('./AddChar.js');
     27 +const { Options } = require('./Options.js');
     28 +const { GetFont } = require('./GetFont.js');
     29 +const { CHARS } = require('./constants.js');
     30 +const { Color } = require('./Color.js');
     31 +const { Size } = require('./Size.js');
     32 +const { Log } = require('./Log.js');
     33 + 
     34 +/**
     35 + * Main method to get the ANSI output for a string
     36 + *
     37 + * @param {string} input - The string you want to write out
     38 + * @param {object} SETTINGS - Settings object
     39 + * @param {boolean} debug - A flag to enable debug mode
     40 + * @param {number} debuglevel - The debug level we want to show
     41 + * @param {object} size - The size of the terminal as an object, default: Size
     42 + * @param {number} size.width - The width of the terminal
     43 + * @param {number} size.height - The height of the terminal
     44 + *
     45 + * @typedef {(object|boolean)} ReturnObject
     46 + * @property {string} string - The pure string for output with all line breaks
     47 + * @property {array} array - Each line of output in an array
     48 + * @property {number} lines - The number of lines
     49 + * @property {object} options - All options used
     50 + *
     51 + * @return {ReturnObject} - CLI output of INPUT to be consoled out
     52 + */
     53 +const Render = (input, SETTINGS = {}, debug = DEBUG.enabled, debuglevel = DEBUG.level, size = Size) => {
     54 + Debugging.report(`Running render`, 1);
     55 + 
     56 + DEBUG.enabled = debug;
     57 + DEBUG.level = debuglevel;
     58 + 
     59 + const INPUT = CleanInput(input, CHARS);
     60 + Options.reset();
     61 + Options.set = SETTINGS;
     62 + const OPTIONS = Options.get;
     63 + 
     64 + let output = []; // for output where each line is an output line
     65 + let lines = 0; // for counting each line
     66 + let FONTFACE = {}; // scoping the fontface object higher for fonts with just one color
     67 + 
     68 + const _isGoodHuman = CheckInput(
     69 + INPUT,
     70 + OPTIONS.font,
     71 + OPTIONS.colors,
     72 + OPTIONS.background,
     73 + OPTIONS.align,
     74 + OPTIONS.gradient,
     75 + OPTIONS.transitionGradient,
     76 + OPTIONS.env
     77 + );
     78 + if (!_isGoodHuman.pass) {
     79 + Log.error(_isGoodHuman.message);
     80 + 
     81 + return false;
     82 + }
     83 + 
     84 + // the gradient option supersedes the color options
     85 + if (OPTIONS.gradient) {
     86 + OPTIONS.colors = [];
     87 + }
     88 + 
     89 + // display an overview of options if debug flag is enabled
     90 + if (DEBUG.enabled) {
     91 + let outOption = `OPTIONS:\n Text: ${INPUT}`;
     92 + 
     93 + for (let key in OPTIONS) {
     94 + outOption += `\n Options.${key}: ${OPTIONS[key]}`;
     95 + }
     96 + 
     97 + Debugging.report(outOption, 3);
     98 + }
     99 + 
     100 + if (OPTIONS.env === 'browser') {
     101 + size = { ...size }; // we clone so we don't make changes to this object across multiple instances
     102 + size.width = OPTIONS.maxLength === 0 ? 999999999999 : OPTIONS.maxLength;
     103 + }
     104 + 
     105 + FONTFACE = GetFont(OPTIONS.font);
     106 + if (!FONTFACE) {
     107 + Log.error(`Font file for the font "${OPTIONS.font}" could not be found.\nTry reinstalling this package.`);
     108 + 
     109 + return false;
     110 + }
     111 + 
     112 + // setting the letterspacing preference from font face if there is no user overwrite
     113 + if (SETTINGS.letterSpacing === undefined) {
     114 + Debugging.report(`Looking up letter spacing from font face`, 1);
     115 + 
     116 + let width = 0;
     117 + 
     118 + FONTFACE.letterspace.forEach((item) => {
     119 + let char = item.replace(/(<([^>]+)>)/gi, ''); // get character and strip color infos
     120 + 
     121 + if (width < char.length) {
     122 + width = char.length;
     123 + }
     124 + });
     125 + 
     126 + Debugging.report(`Letter spacing set to font face default: "${width}"`, 2);
     127 + OPTIONS.letterSpacing = width;
     128 + }
     129 + 
     130 + let lineLength = CharLength(FONTFACE.buffer, FONTFACE.lines, OPTIONS); // count each output character per line and start with the buffer
     131 + let maxChars = 0; // count each character we print for maxLength option
     132 + 
     133 + output = AddLine([], FONTFACE.lines, FONTFACE.buffer, OPTIONS.lineHeight); // create first lines with buffer
     134 + lines++;
     135 + 
     136 + for (let i = 0; i < INPUT.length; i++) {
     137 + // iterate through the message
     138 + let CHAR = INPUT.charAt(i).toUpperCase(); // the current character we convert, only upper case is supported at this time
     139 + let lastLineLength = lineLength; // we need the lineLength for alignment before we look up if the next char fits
     140 + 
     141 + Debugging.report(`Character found in font: "${CHAR}"`, 2);
     142 + 
     143 + if (CHAR !== `|`) {
     144 + // what will the line length be if we add the next char?
     145 + lineLength += CharLength(FONTFACE.chars[CHAR], FONTFACE.lines, OPTIONS); // get the length of this character
     146 + lineLength += CharLength(FONTFACE.letterspace, FONTFACE.lines, OPTIONS) * OPTIONS.letterSpacing; // new line, new line length
     147 + }
     148 + 
     149 + // jump to next line after OPTIONS.maxLength characters or when line break is found or the console windows would have ran out of space
     150 + if ((maxChars >= OPTIONS.maxLength && OPTIONS.maxLength != 0) || CHAR === `|` || lineLength > size.width) {
     151 + lines++;
     152 + 
     153 + Debugging.report(
     154 + `NEWLINE: maxChars: ${maxChars}, ` +
     155 + `OPTIONS.maxLength: ${OPTIONS.maxLength}, ` +
     156 + `CHAR: ${CHAR}, ` +
     157 + `lineLength: ${lineLength}, ` +
     158 + `Size.width: ${size.width} `,
     159 + 2
     160 + );
     161 + 
     162 + if (OPTIONS.env === 'node') {
     163 + output = AlignText(output, lastLineLength, FONTFACE.lines, OPTIONS.align, size); // calculate alignment based on lineLength
     164 + }
     165 + 
     166 + lineLength += CharLength(FONTFACE.letterspace, FONTFACE.lines, OPTIONS) * OPTIONS.letterSpacing; // each new line starts with letter spacing
     167 + lineLength = CharLength(FONTFACE.buffer, FONTFACE.lines, OPTIONS); // new line: new line length
     168 + 
     169 + if (CHAR !== `|`) {
     170 + // if this is a character and not a line break
     171 + lineLength += CharLength(FONTFACE.letterspace, FONTFACE.lines, OPTIONS) * OPTIONS.letterSpacing; // add letter spacing at the end
     172 + lineLength += CharLength(FONTFACE.chars[CHAR], FONTFACE.lines, OPTIONS); // get the length of this character
     173 + }
     174 + 
     175 + maxChars = 0; // new line, new maxLength goal
     176 + 
     177 + output = AddLine(output, FONTFACE.lines, FONTFACE.buffer, OPTIONS.lineHeight); // adding new line
     178 + // add letter spacing to the beginning
     179 + }
     180 + 
     181 + Debugging.report(`lineLength at: "${lineLength}"`, 2);
     182 + 
     183 + if (CHAR !== `|`) {
     184 + maxChars++; // counting all printed characters
     185 + output = AddLetterSpacing(
     186 + output,
     187 + FONTFACE.lines,
     188 + FONTFACE.letterspace,
     189 + FONTFACE.colors,
     190 + OPTIONS.colors,
     191 + OPTIONS.letterSpacing
     192 + );
     193 + output = AddChar(CHAR, output, FONTFACE.lines, FONTFACE.chars, FONTFACE.colors, OPTIONS.colors); // add new character
     194 + }
     195 + }
     196 + 
     197 + if (OPTIONS.env === 'node') {
     198 + output = AlignText(output, lineLength, FONTFACE.lines, OPTIONS.align, size); // alignment last line
     199 + }
     200 + 
     201 + if (OPTIONS.gradient) {
     202 + output = PaintGradient({
     203 + output,
     204 + gradient: OPTIONS.gradient,
     205 + lines,
     206 + lineHeight: OPTIONS.lineHeight,
     207 + fontLines: FONTFACE.lines,
     208 + independentGradient: OPTIONS.independentGradient,
     209 + transitionGradient: OPTIONS.transitionGradient,
     210 + });
     211 + }
     212 + 
     213 + if (OPTIONS.space) {
     214 + // add space
     215 + if (OPTIONS.align === 'top') {
     216 + output[output.length - 1] = `${output[output.length - 1]}\n\n\n\n`;
     217 + } else if (OPTIONS.align === 'bottom') {
     218 + output[0] = `\n\n\n\n${output[0]}`;
     219 + } else {
     220 + output[0] = `\n\n${output[0]}`;
     221 + output[output.length - 1] = `${output[output.length - 1]}\n\n`;
     222 + }
     223 + }
     224 + 
     225 + if (OPTIONS.background !== 'transparent' && OPTIONS.env === 'node') {
     226 + const { open: openNew, close: closeNew } = Color(OPTIONS.background, true);
     227 + 
     228 + output[0] = `${openNew}\n${output[0]}`;
     229 + output[output.length - 1] = `${output[output.length - 1]}${closeNew}`;
     230 + }
     231 + 
     232 + let write = output.join(OPTIONS.env === 'node' ? `\n` : '<br>\n');
     233 + 
     234 + if (OPTIONS.env === 'browser') {
     235 + const { open: bgColor } = Color(OPTIONS.background, true);
     236 + 
     237 + write =
     238 + `<div style="font-family:monospace;white-space:pre;text-align:${
     239 + OPTIONS.align
     240 + };max-width:100%;overflow:scroll;background:${bgColor ? bgColor : 'transparent'}">` +
     241 + `${write}` +
     242 + `</div>`;
     243 + }
     244 + 
     245 + return {
     246 + string: write,
     247 + array: output,
     248 + lines: lines,
     249 + options: OPTIONS,
     250 + };
     251 +};
     252 + 
     253 +module.exports = exports = {
     254 + Render,
     255 +};
     256 + 
  • ■ ■ ■ ■ ■ ■
    src/Say.js nodejs/src/Say.js
    skipped 3 lines
    4 4   *
    5 5   * Sexy fonts for the console. (CLI output)
    6 6   *
    7  - * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv2
     7 + * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv3
    8 8   * @author Dominik Wilkowski [email protected]
    9 9   * @repository https://github.com/dominikwilkowski/cfonts
    10 10   *
    skipped 7 lines
    18 18  const { Debugging, DEBUG } = require('./Debugging.js');
    19 19  const { Render } = require('./Render.js');
    20 20  const { Size } = require('./Size.js');
    21  - 
    22 21   
    23 22  /**
    24 23   * Print to console
    skipped 6 lines
    31 30   * @param {number} size.width - The width of the terminal
    32 31   * @param {number} size.height - The height of the terminal
    33 32   */
    34  -const Say = ( INPUT, SETTINGS = {}, debug = DEBUG.enabled, debuglevel = DEBUG.level, size = Size ) => {
     33 +const Say = (INPUT, SETTINGS = {}, debug = DEBUG.enabled, debuglevel = DEBUG.level, size = Size) => {
    35 34   Debugging.report(`Running say`, 1);
    36 35   
    37 36   DEBUG.enabled = debug;
    38 37   DEBUG.level = debuglevel;
    39 38   
    40  - const write = Render( INPUT, SETTINGS, debug, debuglevel, size );
     39 + const write = Render(INPUT, SETTINGS, debug, debuglevel, size);
    41 40   
    42  - if( write ) {
    43  - console.log( write.string ); // write out
     41 + if (write) {
     42 + console.log(write.string); // write out
    44 43   }
    45 44  };
    46  - 
    47 45   
    48 46  module.exports = exports = {
    49 47   Say,
    skipped 2 lines
  • ■ ■ ■ ■ ■
    src/Size.js nodejs/src/Size.js
    skipped 3 lines
    4 4   *
    5 5   * Sexy fonts for the console. (CLI output)
    6 6   *
    7  - * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv2
     7 + * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv3
    8 8   * @author Dominik Wilkowski [email protected]
    9 9   * @repository https://github.com/dominikwilkowski/cfonts
    10 10   *
    skipped 6 lines
    17 17   
    18 18  const WinSize = require('window-size');
    19 19   
    20  - 
    21 20  /**
    22 21   * Abstraction for windows size
    23 22   *
    24 23   * @type {object}
    25 24   */
    26 25  const Size = {
    27  - width: WinSize
    28  - ? WinSize.width > 0
    29  - ? WinSize.width
    30  - : 80
    31  - : 80,
    32  - height: WinSize
    33  - ? WinSize.height > 0
    34  - ? WinSize.height
    35  - : 24
    36  - : 24,
     26 + width: WinSize ? (WinSize.width > 0 ? WinSize.width : 80) : 80,
     27 + height: WinSize ? (WinSize.height > 0 ? WinSize.height : 24) : 24,
    37 28  };
    38  - 
    39 29   
    40 30  module.exports = exports = {
    41 31   Size,
    skipped 2 lines
  • ■ ■ ■ ■ ■ ■
    src/UpperCaseFirst.js nodejs/src/UpperCaseFirst.js
    skipped 3 lines
    4 4   *
    5 5   * Sexy fonts for the console. (CLI output)
    6 6   *
    7  - * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv2
     7 + * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv3
    8 8   * @author Dominik Wilkowski [email protected]
    9 9   * @repository https://github.com/dominikwilkowski/cfonts
    10 10   *
    skipped 4 lines
    15 15   
    16 16  'use strict';
    17 17   
    18  - 
    19 18  /**
    20 19   * Upper case the first character of an input string.
    21 20   *
    skipped 3 lines
    25 24   *
    26 25   * @return {string} - A string with the first letter in upper case
    27 26   */
    28  -const UpperCaseFirst = input => typeof input === 'string'
    29  - ? input.charAt(0).toUpperCase() + input.substr(1)
    30  - : input;
    31  - 
     27 +const UpperCaseFirst = (input) => (typeof input === 'string' ? input.charAt(0).toUpperCase() + input.substr(1) : input);
    32 28   
    33 29  module.exports = exports = {
    34 30   UpperCaseFirst,
    skipped 2 lines
  • ■ ■ ■ ■
    src/bin.js nodejs/src/bin.js
    skipped 4 lines
    5 5   *
    6 6   * Sexy fonts for the console. (CLI output)
    7 7   *
    8  - * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv2
     8 + * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv3
    9 9   * @author Dominik Wilkowski [email protected]
    10 10   * @repository https://github.com/dominikwilkowski/cfonts
    11 11   *
    skipped 6 lines
  • ■ ■ ■ ■ ■ ■
    src/constants.js nodejs/src/constants.js
    skipped 3 lines
    4 4   *
    5 5   * Sexy fonts for the console. (CLI output)
    6 6   *
    7  - * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv2
     7 + * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv3
    8 8   * @author Dominik Wilkowski [email protected]
    9 9   * @repository https://github.com/dominikwilkowski/cfonts
    10 10   *
    skipped 6 lines
    17 17   * FONTFACES
    18 18   * CLIOPTIONS
    19 19   * PACKAGE
    20  - * HEXTEST
    21 20   *
    22 21   **************************************************************************************************************************************************************/
    23 22   
    24 23  'use strict';
    25  - 
    26  -const { Chalk } = require('./Chalk.js');
    27  - 
    28 24   
    29 25  // global defaults
    30 26  const CHARS = [
    31  - "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
    32  - "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "|",
    33  - "!", "?", ".", "+", "-", "_", "=", "@", "#", "$", "%", "&", "(", ")", "/", ":", ";", ",", " ", "'", "\"",
     27 + 'A',
     28 + 'B',
     29 + 'C',
     30 + 'D',
     31 + 'E',
     32 + 'F',
     33 + 'G',
     34 + 'H',
     35 + 'I',
     36 + 'J',
     37 + 'K',
     38 + 'L',
     39 + 'M',
     40 + 'N',
     41 + 'O',
     42 + 'P',
     43 + 'Q',
     44 + 'R',
     45 + 'S',
     46 + 'T',
     47 + 'U',
     48 + 'V',
     49 + 'W',
     50 + 'X',
     51 + 'Y',
     52 + 'Z',
     53 + '0',
     54 + '1',
     55 + '2',
     56 + '3',
     57 + '4',
     58 + '5',
     59 + '6',
     60 + '7',
     61 + '8',
     62 + '9',
     63 + '|',
     64 + '!',
     65 + '?',
     66 + '.',
     67 + '+',
     68 + '-',
     69 + '_',
     70 + '=',
     71 + '@',
     72 + '#',
     73 + '$',
     74 + '%',
     75 + '&',
     76 + '(',
     77 + ')',
     78 + '/',
     79 + ':',
     80 + ';',
     81 + ',',
     82 + ' ',
     83 + "'",
     84 + '"',
    34 85  ];
    35 86   
    36 87  const COLORS = {
    skipped 49 lines
    86 137  };
    87 138   
    88 139  const GRADIENTS = {
    89  - lgbt: [ '#750787', '#004dff', '#008026', '#ffed00', '#ff8c00', '#e40303' ],
    90  - lgbtq: [ '#750787', '#004dff', '#008026', '#ffed00', '#ff8c00', '#e40303' ],
    91  - pride: [ '#750787', '#004dff', '#008026', '#ffed00', '#ff8c00', '#e40303' ],
    92  - agender: [ '#000000', '#b9b9b9', '#ffffff', '#b8f483', '#ffffff', '#b9b9b9', '#000000' ],
    93  - aromantic: [ '#3da542', '#a7d379', '#ffffff', '#a9a9a9', '#000000' ],
    94  - asexual: [ '#000000', '#a3a3a3', '#ffffff', '#800080' ],
    95  - bisexual: [ '#d60270', '#d60270', '#9b4f96', '#0038a8', '#0038a8' ],
    96  - genderfluid: [ '#ff75a2', '#ffffff', '#be18d6', '#000000', '#333ebd' ],
    97  - genderqueer: [ '#b57edc', '#ffffff', '#4a8123' ],
    98  - intersex: [ '#ffd800', '#ffd800', '#7902aa', '#ffd800', '#ffd800' ],
    99  - lesbian: [ '#d52d00', '#ff9a56', '#ffffff', '#d362a4', '#a30262' ],
    100  - nonbinary: [ '#fcf434', '#ffffff', '#9c5cd4', '#2c2c2c' ],
    101  - pansexual: [ '#ff218c', '#ffd800', '#21b1ff' ],
    102  - polysexual: [ '#f61cb9', '#07d569', '#1c92f6' ],
    103  - transgender: [ '#5bcefa', '#f5a9b8', '#ffffff', '#f5a9b8', '#5bcefa' ],
     140 + lgbt: ['#750787', '#004dff', '#008026', '#ffed00', '#ff8c00', '#e40303'],
     141 + lgbtq: ['#750787', '#004dff', '#008026', '#ffed00', '#ff8c00', '#e40303'],
     142 + pride: ['#750787', '#004dff', '#008026', '#ffed00', '#ff8c00', '#e40303'],
     143 + agender: ['#000000', '#b9b9b9', '#ffffff', '#b8f483', '#ffffff', '#b9b9b9', '#000000'],
     144 + aromantic: ['#3da542', '#a7d379', '#ffffff', '#a9a9a9', '#000000'],
     145 + asexual: ['#000000', '#a3a3a3', '#ffffff', '#800080'],
     146 + bisexual: ['#d60270', '#d60270', '#9b4f96', '#0038a8', '#0038a8'],
     147 + genderfluid: ['#ff75a2', '#ffffff', '#be18d6', '#000000', '#333ebd'],
     148 + genderqueer: ['#b57edc', '#ffffff', '#4a8123'],
     149 + intersex: ['#ffd800', '#ffd800', '#7902aa', '#ffd800', '#ffd800'],
     150 + lesbian: ['#d52d00', '#ff9a56', '#ffffff', '#d362a4', '#a30262'],
     151 + nonbinary: ['#fcf434', '#ffffff', '#9c5cd4', '#2c2c2c'],
     152 + pansexual: ['#ff218c', '#ffd800', '#21b1ff'],
     153 + polysexual: ['#f61cb9', '#07d569', '#1c92f6'],
     154 + transgender: ['#5bcefa', '#f5a9b8', '#ffffff', '#f5a9b8', '#5bcefa'],
    104 155  };
    105 156   
    106  -const ALIGNMENT = [
    107  - 'left',
    108  - 'center',
    109  - 'right',
    110  - 'top',
    111  - 'bottom',
    112  -];
     157 +const ALIGNMENT = ['left', 'center', 'right', 'top', 'bottom'];
    113 158   
    114 159  const FONTFACES = {
    115 160   console: 'console',
    skipped 26 lines
    142 187   },
    143 188   '--font': {
    144 189   description: 'Use to define the font face',
    145  - example: `--font block ${ Chalk.green(`( ${ Object.keys( FONTFACES ).map( font => FONTFACES[ font ] ).join(', ') } )`) }`,
     190 + example: `--font block [green-open][ ${Object.keys(FONTFACES)
     191 + .map((font) => FONTFACES[font])
     192 + .join(', ')} ][green-close]`,
    146 193   short: '-f',
    147  - options: Object.keys( FONTFACES ).map( color => FONTFACES[ color ] ),
     194 + options: Object.keys(FONTFACES).map((color) => FONTFACES[color]),
    148 195   default: 'block',
    149 196   },
    150 197   '--colors': {
    151 198   description: 'Use to define the font color',
    152  - example: `--colors red ${ Chalk.green(`( ${ Object.keys( COLORS ).map( color => COLORS[ color ] ).join(', ') }, #ff8800, hex-colors etc... )`) }`,
     199 + example: `--colors red [green-open][ ${Object.keys(COLORS)
     200 + .map((color) => COLORS[color])
     201 + .join(', ')}, #ff8800, hex-colors etc... ][green-close]`,
    153 202   short: '-c',
    154 203   options: true,
    155 204   default: 'system',
    156 205   },
    157 206   '--background': {
    158 207   description: 'Use to define background color',
    159  - example: `--background blue ${ Chalk.green(`( ${ Object.keys( BGCOLORS ).map( bgcolor => BGCOLORS[ bgcolor ] ).join(', ') } )`) }`,
     208 + example: `--background blue [green-open][ ${Object.keys(BGCOLORS)
     209 + .map((bgcolor) => BGCOLORS[bgcolor])
     210 + .join(', ')} ][green-close]`,
    160 211   short: '-b',
    161  - options: Object.keys( BGCOLORS ).map( color => BGCOLORS[ color ] ),
     212 + options: Object.keys(BGCOLORS).map((color) => BGCOLORS[color]),
    162 213   default: 'transparent',
    163 214   },
    164 215   '--align': {
    165 216   description: 'Use to align your text output',
    166  - example: `--align ${ Chalk.green(`( ${ ALIGNMENT.join(', ') } )`) }`,
     217 + example: `--align [green-open][ ${ALIGNMENT.join(', ')} ][green-close]`,
    167 218   short: '-a',
    168 219   options: ALIGNMENT,
    169 220   default: 'left',
    skipped 27 lines
    197 248   },
    198 249   '--gradient': {
    199 250   description: 'Use to define a start and end color of a gradient',
    200  - example: '--gradient red,blue',
     251 + example: '--gradient red,blue,green',
    201 252   short: '-g',
    202 253   options: true,
    203 254   default: false,
    skipped 12 lines
    216 267   },
    217 268   '--env': {
    218 269   description: 'Use to define what environment you run CFonts in.',
    219  - example: `--env ${ Chalk.green('"node", "browser"') }`,
     270 + example: `--env [green-open][ "node", "browser" ][green-close]`,
    220 271   short: '-e',
    221 272   options: true,
    222 273   default: 'node',
    skipped 15 lines
    238 289   
    239 290  const PACKAGE = require('../package.json');
    240 291   
    241  -const HEXTEST = RegExp('^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$');
    242  - 
    243  - 
    244 292  module.exports = exports = {
    245 293   CHARS,
    246 294   COLORS,
    skipped 4 lines
    251 299   FONTFACES,
    252 300   CLIOPTIONS,
    253 301   PACKAGE,
    254  - HEXTEST,
    255 302  };
    256 303   
  • ■ ■ ■ ■ ■ ■
    nodejs/src/index.js
     1 +/***************************************************************************************************************************************************************
     2 + *
     3 + * cfonts
     4 + *
     5 + * Sexy fonts for the console. (CLI output)
     6 + *
     7 + * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv3
     8 + * @author Dominik Wilkowski [email protected]
     9 + * @repository https://github.com/dominikwilkowski/cfonts
     10 + *
     11 + * Cli
     12 + * Run cli commands
     13 + *
     14 + **************************************************************************************************************************************************************/
     15 + 
     16 +'use strict';
     17 + 
     18 +const { DisplayVersion } = require('./DisplayVersion.js');
     19 +const { DisplayHelp } = require('./DisplayHelp.js');
     20 +const { CLIOPTIONS } = require('./constants.js');
     21 +const { Debugging } = require('./Debugging.js');
     22 +const { ParseArgs } = require('./ParseArgs.js');
     23 +const { Render } = require('./Render.js');
     24 +const { Color } = require('./Color.js');
     25 +const { Log } = require('./Log.js');
     26 +const { Say } = require('./Say.js');
     27 + 
     28 +/**
     29 + * Run cli commands
     30 + *
     31 + * @param {object} inputOptions - All possible options registered for this app
     32 + * @param {array} inputArgs - The arguments given to us in our cli, default: process.argv
     33 + */
     34 +const Cli = (inputOptions = CLIOPTIONS, inputArgs = process.argv) => {
     35 + const args = ParseArgs(inputOptions, inputArgs);
     36 + 
     37 + Debugging.report(
     38 + `OPTIONS:\n` +
     39 + ` CFonts.say("${args.text}", {\n` +
     40 + ` font: "${args.font}",\n` +
     41 + ` align: "${args.align}",\n` +
     42 + ` colors: ${args.colors ? JSON.stringify(args.colors.split(',')) : []},\n` +
     43 + ` background: "${args.background}",\n` +
     44 + ` letterSpacing: ${args['letter-spacing']},\n` +
     45 + ` lineHeight: ${args['line-height']},\n` +
     46 + ` space: ${!args.spaceless},\n` +
     47 + ` maxLength: ${args['max-length']},\n` +
     48 + ` gradient: ${args.gradient},\n` +
     49 + ` independentGradient: ${args['independent-gradient']},\n` +
     50 + ` transitionGradient: ${args['transition-gradient']},\n` +
     51 + ` env: ${args.env},\n` +
     52 + ` }, ${args.debug}, ${args.debugLevel} );`,
     53 + 3,
     54 + args.debug,
     55 + args.debugLevel
     56 + );
     57 + 
     58 + if (args.help) {
     59 + DisplayHelp();
     60 + return;
     61 + }
     62 + 
     63 + if (args.version) {
     64 + DisplayVersion();
     65 + return;
     66 + }
     67 + 
     68 + if (!args.text) {
     69 + const { open: green_open, close: green_close } = Color('green');
     70 + Log.error(
     71 + `Please provide text to convert with ${green_open}cfonts "Text"${green_close}\n` +
     72 + `Run ${green_open}cfonts --help${green_close} for more infos`
     73 + );
     74 + return;
     75 + }
     76 + 
     77 + Say(
     78 + args.text,
     79 + {
     80 + font: args.font,
     81 + align: args.align,
     82 + colors: args.colors ? args.colors.split(',') : [],
     83 + background: args.background,
     84 + letterSpacing: args['letter-spacing'],
     85 + lineHeight: args['line-height'],
     86 + space: !args.spaceless,
     87 + maxLength: args['max-length'],
     88 + gradient: args.gradient,
     89 + independentGradient: args['independent-gradient'],
     90 + transitionGradient: args['transition-gradient'],
     91 + env: args.env,
     92 + },
     93 + args.debug,
     94 + args.debugLevel
     95 + );
     96 +};
     97 + 
     98 +module.exports = exports = {
     99 + render: Render,
     100 + say: Say,
     101 + Cli,
     102 +};
     103 + 
  • ■ ■ ■ ■ ■
    test/env.js nodejs/test/env.js
    1 1  // we force color detection in tests to make them reproducible in different environments like ci
    2 2  process.env.FORCE_COLOR = 3;
    3 3   
    4  - 
    5 4  const { Options } = require('../src/Options.js');
    6 5  Options.reset();
    7 6   
  • ■ ■ ■ ■ ■ ■
    test/examples.js nodejs/test/examples.js
    skipped 3 lines
    4 4   *
    5 5   * Testing the API side of things.
    6 6   *
    7  - * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv2
     7 + * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv3
    8 8   * @author Dominik Wilkowski [email protected]
    9 9   * @repository https://github.com/dominikwilkowski/cfonts
    10 10   *
    skipped 39 lines
    50 50   colors: ['red'],
    51 51  });
    52 52   
    53  -CFonts.say(`Hello
    54  -world\nagain|!`, {
    55  - font: 'simple',
    56  - align: 'center',
    57  - colors: ['red'],
    58  -});
     53 +CFonts.say(
     54 + `Hello
     55 +world\nagain|!`,
     56 + {
     57 + font: 'simple',
     58 + align: 'center',
     59 + colors: ['red'],
     60 + }
     61 +);
    59 62   
    60 63  CFonts.say('Hi|world!', {
    61  - gradient: ['red','green'],
     64 + gradient: ['red', 'green'],
    62 65  });
    63 66   
    64 67  CFonts.say('Hi|world!', {
    65  - gradient: ['red','green'],
     68 + gradient: ['red', 'green'],
    66 69   independentGradient: true,
    67 70  });
    68 71   
    69 72  CFonts.say('Hi|world!', {
    70  - gradient: ['red','green'],
     73 + gradient: ['red', 'green'],
    71 74   transitionGradient: true,
    72 75  });
    73 76   
    74 77  CFonts.say('Hi|world!', {
    75  - gradient: ['red','green'],
     78 + gradient: ['red', 'green'],
    76 79   independentGradient: true,
    77 80   transitionGradient: true,
    78 81  });
    skipped 50 lines
    129 132  <body style="background:#f1f1f1">
    130 133  <h1>CFonts browser test</h1>
    131 134  <h2>Font one</h2>
    132  -${ prettyFont2.string }
     135 +${prettyFont2.string}
    133 136  <h2>Font two</h2>
    134  -${ prettyFont3.string }
     137 +${prettyFont3.string}
    135 138  <h2>Font three</h2>
    136  -${ prettyFont4.string }
     139 +${prettyFont4.string}
    137 140  <h2>Font four</h2>
    138  -${ prettyFont5.string }
     141 +${prettyFont5.string}
    139 142  </body>
    140 143  </html>
    141 144  `;
    142 145   
    143  -const check = fs.writeFileSync( path.normalize(`${ __dirname }/test.html`), html, { encoding: 'utf8' } );
    144  - 
     146 +const check = fs.writeFileSync(path.normalize(`${__dirname}/test.html`), html, { encoding: 'utf8' });
    145 147   
    146 148  // for issue #13
    147  -Array.prototype.foo = () => { return 0; };
    148  -CFonts.say('Hello', { colors: [ 'green' ] });
     149 +Array.prototype.foo = () => {
     150 + return 0;
     151 +};
     152 +CFonts.say('Hello', { colors: ['green'] });
    149 153   
  • ■ ■ ■ ■ ■ ■
    nodejs/test/fonttest.js
     1 +/***************************************************************************************************************************************************************
     2 + *
     3 + * cfonts, Sexy fonts for the console. (CLI output)
     4 + *
     5 + * Testing the each font file:
     6 + * - Font file has all font attributes?
     7 + * - All characters included?
     8 + * - All characters have the correct width?
     9 + * - All characters have consistent lines?
     10 + *
     11 + * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv3
     12 + * @author Dominik Wilkowski [email protected]
     13 + * @repository https://github.com/dominikwilkowski/cfonts
     14 + *
     15 + **************************************************************************************************************************************************************/
     16 + 
     17 +'use strict';
     18 + 
     19 +// Dependencies
     20 +const { CHARS: CFontsChars, FONTFACES: CFontsFontfaces } = require('../src/constants.js');
     21 +const { Size } = require('../src/Size.js');
     22 +const Readline = require('readline');
     23 +const Chalk = require(`chalk`);
     24 +const Path = require('path');
     25 +const Fs = require(`fs`);
     26 + 
     27 +// global defaults
     28 +const DEBUG = true;
     29 +const DEBUGLEVEL = 2;
     30 +const CHARS = CFontsChars.filter((font) => font !== '|'); // we don’t need the pipe in the char-set
     31 +const FONTFACES = Object.keys(CFontsFontfaces).map((font) => CFontsFontfaces[font]); // console is a font but not a font-file
     32 + 
     33 +/**
     34 + * Test each font for common issues
     35 + *
     36 + * @param {array} FONTFACES - All font faces to be checked in an array
     37 + * @param {array} CHARS - All characters that should be included
     38 + */
     39 +const FontTest = (FONTFACES, CHARS) => {
     40 + Debugging.report(`Running FontTest`, 1);
     41 + 
     42 + let font = '';
     43 + let fontFile = '';
     44 + let FONTFACE = {};
     45 + 
     46 + for (let i in FONTFACES) {
     47 + font = FONTFACES[i];
     48 + fontFile = Path.normalize(`${__dirname}/../../fonts/${font}.json`);
     49 + 
     50 + Log.headline(`${font}`);
     51 + Log.check(`Checking: "${font}" existence`);
     52 + 
     53 + try {
     54 + FONTFACE = JSON.parse(Fs.readFileSync(fontFile, 'utf8'));
     55 + 
     56 + Log.subdone(`FOUND!`);
     57 + } catch (e) {
     58 + Log.suberror(`NOT FOUND: "${fontFile}"`);
     59 + }
     60 + 
     61 + Attributes(FONTFACE);
     62 + Letterspace_size(FONTFACE);
     63 + Chars(FONTFACE, CHARS);
     64 + Width(FONTFACE, CHARS);
     65 + Lines(FONTFACE, CHARS);
     66 + }
     67 + 
     68 + console.log(`\n`);
     69 + if (Log.errors > 0) {
     70 + process.exit(1);
     71 + }
     72 +};
     73 + 
     74 +/**
     75 + * Test the font has all attributes
     76 + *
     77 + * @param {object} FONTFACE - The font object for this font
     78 + */
     79 +const Attributes = (FONTFACE) => {
     80 + Debugging.report(`Running Attributes`, 1);
     81 + Log.check(`Checking font attributes of "${FONTFACE.name}"`);
     82 + let fails = [];
     83 + 
     84 + if (FONTFACE.name === undefined) {
     85 + fails.push(`name`);
     86 + }
     87 + 
     88 + if (FONTFACE.version === undefined) {
     89 + fails.push(`version`);
     90 + }
     91 + 
     92 + if (FONTFACE.homepage === undefined) {
     93 + fails.push(`homepage`);
     94 + }
     95 + 
     96 + if (FONTFACE.colors === undefined) {
     97 + fails.push(`colors`);
     98 + }
     99 + 
     100 + if (FONTFACE.lines === undefined) {
     101 + fails.push(`lines`);
     102 + }
     103 + 
     104 + if (FONTFACE.buffer === undefined) {
     105 + fails.push(`buffer`);
     106 + }
     107 + 
     108 + if (FONTFACE.letterspace === undefined) {
     109 + fails.push(`letterspace`);
     110 + }
     111 + 
     112 + if (FONTFACE.letterspace_size === undefined) {
     113 + fails.push(`letterspace_size`);
     114 + }
     115 + 
     116 + if (FONTFACE.chars === undefined) {
     117 + fails.push(`chars`);
     118 + }
     119 + 
     120 + if (fails.length > 0) {
     121 + Log.suberror(`Font has missing attributes: "${fails.join(' ')}" in font: "${FONTFACE.name}"`);
     122 + } else {
     123 + Log.subdone(`All THERE!`);
     124 + }
     125 +};
     126 + 
     127 +/**
     128 + * Test the font to include all characters
     129 + *
     130 + * @param {object} FONTFACE - The font object for this font
     131 + * @param {array} CHARS - All characters that should be included
     132 + */
     133 +const Letterspace_size = (FONTFACE) => {
     134 + Debugging.report(`Running Letterspace_size`, 1);
     135 + Log.check(`Checking letterspace_size in "${FONTFACE.name}"`);
     136 + 
     137 + let width = 0;
     138 + FONTFACE.letterspace.forEach((item) => {
     139 + let char = item.replace(/(<([^>]+)>)/gi, ''); // get character and strip color infos
     140 + 
     141 + if (width < char.length) {
     142 + width = char.length;
     143 + }
     144 + });
     145 + 
     146 + if (FONTFACE.letterspace_size !== width) {
     147 + Log.suberror(
     148 + `Font has wrong letterspace_size attribute. Is: "${FONTFACE.letterspace_size}" but should be "${width}" in font: "${FONTFACE.name}"`
     149 + );
     150 + } else {
     151 + Log.subdone(`All CORRECT!`);
     152 + }
     153 +};
     154 + 
     155 +/**
     156 + * Test the font to include all characters
     157 + *
     158 + * @param {object} FONTFACE - The font object for this font
     159 + * @param {array} CHARS - All characters that should be included
     160 + */
     161 +const Chars = (FONTFACE, CHARS) => {
     162 + Debugging.report(`Running Chars`, 1);
     163 + Log.check(`Checking all characters in "${FONTFACE.name}"`);
     164 + let fails = [];
     165 + 
     166 + for (let i in CHARS) {
     167 + let char = CHARS[i];
     168 + 
     169 + if (FONTFACE.chars[char] === undefined) {
     170 + fails.push(char);
     171 + }
     172 + }
     173 + 
     174 + if (fails.length > 0) {
     175 + Log.suberror(`Character could not be found: "${fails.join(' ')}" in font: "${FONTFACE.name}"`);
     176 + } else {
     177 + Log.subdone(`All THERE!`);
     178 + }
     179 +};
     180 + 
     181 +/**
     182 + * Test each character has the right amount of lines
     183 + *
     184 + * @param {object} FONTFACE - The font object for this font
     185 + * @param {array} CHARS - All characters that should be included
     186 + */
     187 +const Lines = (FONTFACE, CHARS) => {
     188 + Debugging.report(`Running Lines`, 1);
     189 + Log.check(`Checking all character lines in "${FONTFACE.name}"`);
     190 + let fails = [];
     191 + 
     192 + if (FONTFACE.buffer.length !== FONTFACE.lines) {
     193 + fails.push(`buffer`);
     194 + }
     195 + 
     196 + if (FONTFACE.letterspace.length !== FONTFACE.lines) {
     197 + fails.push(`letterspace`);
     198 + }
     199 + 
     200 + for (let i in CHARS) {
     201 + let char = CHARS[i];
     202 + 
     203 + if (FONTFACE.chars[char] !== undefined) {
     204 + if (FONTFACE.chars[char].length !== FONTFACE.lines) {
     205 + fails.push(char);
     206 + }
     207 + }
     208 + }
     209 + 
     210 + if (fails.length > 0) {
     211 + Log.suberror(`Character lines are not correct in "${fails.join(' ')}" in font: "${FONTFACE.name}"`);
     212 + } else {
     213 + Log.subdone(`All CORRECT!`);
     214 + }
     215 +};
     216 + 
     217 +/**
     218 + * Test each character to have the same width
     219 + *
     220 + * @param {object} FONTFACE - The font object for this font
     221 + * @param {array} CHARS - All characters that should be included
     222 + */
     223 +const Width = (FONTFACE, CHARS) => {
     224 + Debugging.report(`Running Width`, 1);
     225 + Log.check(`Checking all character widths in "${FONTFACE.name}"`);
     226 + let fails = [];
     227 + 
     228 + for (let i in CHARS) {
     229 + let char = CHARS[i];
     230 + 
     231 + if (FONTFACE.chars[char] !== undefined) {
     232 + let character = FONTFACE.chars[char];
     233 + let width = 0;
     234 + 
     235 + for (let i = 0; i < character.length; i++) {
     236 + character[i] = character[i].replace(/(<([^>]+)>)/gi, '');
     237 + 
     238 + if (i === 0) {
     239 + width = character[i].length;
     240 + }
     241 + 
     242 + if (width !== character[i].length) {
     243 + fails.push(`${char}((${width}) ${i}=${character[i].length})`);
     244 + // break; // if we break here we fail on the first issue rather than collecting them all
     245 + }
     246 + }
     247 + }
     248 + }
     249 + 
     250 + if (fails.length > 0) {
     251 + Log.suberror(`Character width is not consistent in "${fails.join(' ')}" in font: "${FONTFACE.name}"`);
     252 + } else {
     253 + Log.subdone(`All CONSISTENT!`);
     254 + }
     255 +};
     256 + 
     257 +/**
     258 + * A collection of methods to print debug message that will be logged to console if debug mode is enabled
     259 + *
     260 + * @type {Object}
     261 + */
     262 +const Debugging = {
     263 + /**
     264 + * Print a headline preferably at the beginning of your app
     265 + *
     266 + * @param [text] {string} - The sting you want to log
     267 + * @param [level] {integer} - (optional) The debug level. Show equal and greater levels. Default: 99
     268 + */
     269 + headline: (text, level = 99) => {
     270 + if (DEBUG && level >= DEBUGLEVEL) {
     271 + console.log(Chalk.bgWhite(`\n${Chalk.bold(' \u2611 ')} ${text}`));
     272 + }
     273 + },
     274 + 
     275 + /**
     276 + * Print a message to report starting a process
     277 + *
     278 + * @param [text] {string} - The sting you want to log
     279 + * @param [level] {integer} - (optional) The debug level. Show equal and greater levels. Default: 99
     280 + */
     281 + report: (text, level = 99) => {
     282 + if (DEBUG && level >= DEBUGLEVEL) {
     283 + console.log(Chalk.bgWhite(`\n${Chalk.bold.green(' \u2611 ')} ${Chalk.black(`${text} `)}`));
     284 + }
     285 + },
     286 + 
     287 + /**
     288 + * Print a message to report an error
     289 + *
     290 + * @param [text] {string} - The sting you want to log
     291 + * @param [level] {integer} - (optional) The debug level. Show equal and greater levels. Default: 99
     292 + */
     293 + error: (text, level = 99) => {
     294 + if (DEBUG && level >= DEBUGLEVEL) {
     295 + console.log(Chalk.bgWhite(`\n${Chalk.red(' \u2612 ')} ${Chalk.black(`${text} `)}`));
     296 + }
     297 + },
     298 + 
     299 + /**
     300 + * Print a message to report an interaction
     301 + *
     302 + * @param [text] {string} - The sting you want to log
     303 + * @param [level] {integer} - (optional) The debug level. Show equal and greater levels. Default: 99
     304 + */
     305 + interaction: (text, level = 99) => {
     306 + if (DEBUG && level >= DEBUGLEVEL) {
     307 + console.log(Chalk.bgWhite(`\n${Chalk.blue(' \u261C ')} ${Chalk.black(`${text} `)}`));
     308 + }
     309 + },
     310 + 
     311 + /**
     312 + * Print a message to report data has been sent
     313 + *
     314 + * @param [text] {string} - The sting you want to log
     315 + * @param [level] {integer} - (optional) The debug level. Show equal and greater levels. Default: 99
     316 + */
     317 + send: (text, level = 99) => {
     318 + if (DEBUG && level >= DEBUGLEVEL) {
     319 + console.log(Chalk.bgWhite(`\n${Chalk.bold.cyan(' \u219D ')} ${Chalk.black(`${text} `)}`));
     320 + }
     321 + },
     322 + 
     323 + /**
     324 + * Print a message to report data has been received
     325 + *
     326 + * @param [text] {string} - The sting you want to log
     327 + * @param [level] {integer} - (optional) The debug level. Show equal and greater levels. Default: 99
     328 + */
     329 + received: (text, level = 99) => {
     330 + if (DEBUG && level >= DEBUGLEVEL) {
     331 + console.log(Chalk.bgWhite(`\n${Chalk.bold.cyan(' \u219C ')} ${Chalk.black(`${text} `)}`));
     332 + }
     333 + },
     334 +};
     335 + 
     336 +/**
     337 + * A collection of methods to print messages to console
     338 + *
     339 + * @type {Object}
     340 + */
     341 +const Log = {
     342 + errors: 0,
     343 + 
     344 + /**
     345 + * Start a test category
     346 + *
     347 + * @param {string} text - The name of the test
     348 + */
     349 + headline: (text) => {
     350 + let space = Math.floor((Size.width - text.length - 6) / 2);
     351 + if (space < 0) {
     352 + space = 1;
     353 + }
     354 + 
     355 + console.log(`\n${Chalk.bgWhite.black(`\n${' '.repeat(space)}══ ${text} ══`)}`);
     356 + },
     357 + 
     358 + /**
     359 + * Log a check and keep space for the result
     360 + *
     361 + * @param {string} text - The sting you want to log
     362 + */
     363 + check: (text) => {
     364 + let prefix = `${Chalk.bold.green(' \u231B ')} ${Chalk.bold.black('Testing:')} `;
     365 + 
     366 + text = text.replace(/(?:\r\n|\r|\n)/g, `\n${' '.repeat(prefix.length)}`);
     367 + process.stdout.write(`\n${Chalk.bgWhite(`${prefix}${Chalk.black(text)}`)}`);
     368 + },
     369 + 
     370 + /**
     371 + * Note positive outcome for previously run check method
     372 + *
     373 + * @param {string} text - Success message (not logged)
     374 + */
     375 + subdone: (text) => {
     376 + let prefix = ` ${Chalk.bold.black('OK')} `;
     377 + text = text.replace(/(?:\r\n|\r|\n)/g, `\n ${' '.repeat(prefix.length)}`);
     378 + 
     379 + Readline.cursorTo(process.stdout, 0);
     380 + console.log(`${Chalk.bgGreen(` ${prefix}`)}`);
     381 + // console.log(`${ Chalk.bgGreen(` ${ Chalk.black( text ) }`) }`); // not outputting message will keep things cleaner
     382 + },
     383 + 
     384 + /**
     385 + * Note negative outcome for previously run check method
     386 + *
     387 + * @param {string} text - Error message
     388 + */
     389 + suberror: (text) => {
     390 + Log.errors++;
     391 + 
     392 + let prefix = ` ${Chalk.bold.black('FAIL')} `;
     393 + text = text.replace(/(?:\r\n|\r|\n)/g, `\n ${' '.repeat(prefix.length)}`);
     394 + 
     395 + Readline.cursorTo(process.stdout, 0);
     396 + console.log(`${Chalk.bgRed(` ${prefix}`)}`);
     397 + console.log(`${Chalk.bgRed(` ${Chalk.black(text)}`)}`);
     398 + },
     399 +};
     400 + 
     401 +FontTest(FONTFACES, CHARS);
     402 + 
  • test/test.html nodejs/test/test.html
    Unable to diff as some line is too long.
  • ■ ■ ■ ■ ■ ■
    nodejs/test/unit/AddChar.spec.js
     1 +/***************************************************************************************************************************************************************
     2 + *
     3 + * AddChar unit tests
     4 + *
     5 + **************************************************************************************************************************************************************/
     6 + 
     7 +const { AddChar } = require('../../src/AddChar.js');
     8 + 
     9 +test(`AddChar - Add a single line letter without color`, () => {
     10 + const fontChars = {
     11 + A: ['A'],
     12 + };
     13 + 
     14 + expect(AddChar('A', [''], 1, fontChars, 1, [])).toEqual(['A']);
     15 +});
     16 + 
     17 +test(`AddChar - Add a single line letter with color`, () => {
     18 + const fontChars = {
     19 + A: ['A'],
     20 + };
     21 + 
     22 + expect(AddChar('A', [''], 1, fontChars, 1, ['red'])).toEqual(['\u001b[31mA\u001b[39m']);
     23 +});
     24 + 
     25 +test(`AddChar - Add a multi line letter without color`, () => {
     26 + const fontChars = {
     27 + A: [',-,', '|-|', '| |'],
     28 + };
     29 + 
     30 + expect(AddChar('A', ['', '', ''], 3, fontChars, 1, [])).toEqual(fontChars.A);
     31 +});
     32 + 
     33 +test(`AddChar - Add a multi line letter with color`, () => {
     34 + const fontChars = {
     35 + A: [',-,', '|-|', '| |'],
     36 + };
     37 + 
     38 + const result = ['\u001b[31m,-,\u001b[39m', '\u001b[31m|-|\u001b[39m', '\u001b[31m| |\u001b[39m'];
     39 + 
     40 + expect(AddChar('A', ['', '', ''], 3, fontChars, 1, ['red'])).toEqual(result);
     41 +});
     42 + 
     43 +test(`AddChar - Add a multi line letter with multiple colors`, () => {
     44 + const fontChars = {
     45 + A: [',<c1>-</c1>,', '|-|', '| <c2>|</c2>'],
     46 + };
     47 + 
     48 + const result = [',\u001b[31m-\u001b[39m,', '|-|', '| \u001b[31m|\u001b[39m'];
     49 + 
     50 + expect(AddChar('A', ['', '', ''], 3, fontChars, 2, ['red', 'red'])).toEqual(result);
     51 +});
     52 + 
  • ■ ■ ■ ■ ■ ■
    nodejs/test/unit/AddLetterSpacing.spec.js
     1 +/***************************************************************************************************************************************************************
     2 + *
     3 + * AddLetterSpacing unit tests
     4 + *
     5 + **************************************************************************************************************************************************************/
     6 + 
     7 +const { AddLetterSpacing } = require('../../src/AddLetterSpacing.js');
     8 + 
     9 +test(`AddLetterSpacing - Add a letter space to the last line for single line font`, () => {
     10 + expect(AddLetterSpacing(['', '', ''], 1, [' '], 1, [], 1)).toEqual(['', '', ' ']);
     11 +});
     12 + 
     13 +test(`AddLetterSpacing - Add a letter space even when the font doesn't have it specified`, () => {
     14 + expect(AddLetterSpacing(['', '', ''], 1, [''], 1, [], 1)).toEqual(['', '', ' ']);
     15 + expect(AddLetterSpacing(['', '', ''], 1, [''], 1, [], 2)).toEqual(['', '', ' ']);
     16 +});
     17 + 
     18 +test(`AddLetterSpacing - Add a letter space to the last line for single line font with one color`, () => {
     19 + expect(AddLetterSpacing(['', '', ''], 1, [' '], 1, ['red'], 1)).toEqual(['', '', '\u001b[31m \u001b[39m']);
     20 +});
     21 + 
     22 +test(`AddLetterSpacing - Add a letter space to the last line for single line font with multiple colors`, () => {
     23 + expect(AddLetterSpacing(['', '', ''], 1, ['<c1> </c1>'], 2, ['red', 'red'], 1)).toEqual([
     24 + '',
     25 + '',
     26 + '\u001b[31m \u001b[39m',
     27 + ]);
     28 + expect(AddLetterSpacing(['', '', ''], 1, ['<c2>#</c2>'], 2, ['red', 'red'], 1)).toEqual([
     29 + '',
     30 + '',
     31 + '\u001b[31m#\u001b[39m',
     32 + ]);
     33 +});
     34 + 
     35 +test(`AddLetterSpacing - Add a letter space to the last line for multiple line font`, () => {
     36 + expect(AddLetterSpacing(['', '', '', '', '', ''], 3, [' ', ' ', ' '], 1, [], 1)).toEqual(['', '', '', ' ', ' ', ' ']);
     37 + expect(AddLetterSpacing(['', '', '', '', '', ''], 3, ['_', '_', '_'], 1, [], 1)).toEqual(['', '', '', '_', '_', '_']);
     38 +});
     39 + 
     40 +test(`AddLetterSpacing - Add a letter space to the last line for multiple line font with one color`, () => {
     41 + expect(AddLetterSpacing(['', '', '', '', '', ''], 3, [' ', ' ', ' '], 1, ['red'], 1)).toEqual([
     42 + '',
     43 + '',
     44 + '',
     45 + '\u001b[31m \u001b[39m',
     46 + '\u001b[31m \u001b[39m',
     47 + '\u001b[31m \u001b[39m',
     48 + ]);
     49 + expect(AddLetterSpacing(['', '', '', '', '', ''], 3, ['_', '_', '_'], 1, ['red'], 1)).toEqual([
     50 + '',
     51 + '',
     52 + '',
     53 + '\u001b[31m_\u001b[39m',
     54 + '\u001b[31m_\u001b[39m',
     55 + '\u001b[31m_\u001b[39m',
     56 + ]);
     57 +});
     58 + 
     59 +test(`AddLetterSpacing - Add a letter space to the last line for multiple line font with multiple colors`, () => {
     60 + expect(
     61 + AddLetterSpacing(['', '', '', '', '', ''], 3, ['<c1> </c1>', '<c1> </c1>', '<c1> </c1>'], 2, ['red', 'red'], 1)
     62 + ).toEqual(['', '', '', '\u001b[31m \u001b[39m', '\u001b[31m \u001b[39m', '\u001b[31m \u001b[39m']);
     63 + expect(
     64 + AddLetterSpacing(['', '', '', '', '', ''], 3, ['<c2> </c2>', '<c2> </c2>', '<c2> </c2>'], 2, ['red', 'red'], 1)
     65 + ).toEqual(['', '', '', '\u001b[31m \u001b[39m', '\u001b[31m \u001b[39m', '\u001b[31m \u001b[39m']);
     66 + 
     67 + expect(
     68 + AddLetterSpacing(['', '', '', '', '', ''], 3, ['<c1>_</c1>', '<c1>_</c1>', '<c1>_</c1>'], 2, ['red', 'red'], 1)
     69 + ).toEqual(['', '', '', '\u001b[31m_\u001b[39m', '\u001b[31m_\u001b[39m', '\u001b[31m_\u001b[39m']);
     70 + expect(
     71 + AddLetterSpacing(['', '', '', '', '', ''], 3, ['<c2>_</c2>', '<c2>_</c2>', '<c2>_</c2>'], 2, ['red', 'red'], 1)
     72 + ).toEqual(['', '', '', '\u001b[31m_\u001b[39m', '\u001b[31m_\u001b[39m', '\u001b[31m_\u001b[39m']);
     73 +});
     74 + 
  • ■ ■ ■ ■ ■ ■
    nodejs/test/unit/AddLine.spec.js
     1 +/***************************************************************************************************************************************************************
     2 + *
     3 + * AddLine unit tests
     4 + *
     5 + **************************************************************************************************************************************************************/
     6 + 
     7 +const { AddLine } = require('../../src/AddLine.js');
     8 + 
     9 +test(`AddLine - Adding a line to a single-line font`, () => {
     10 + const input = ['line 1', 'line 2'];
     11 + 
     12 + expect(AddLine([...input], 1, [''], 0)).toEqual([...input, '']);
     13 + expect(AddLine([...input], 1, [''], 1)).toEqual([...input, '', '']);
     14 + expect(AddLine([...input], 1, [''], 5)).toEqual([...input, '', '', '', '', '', '']);
     15 +});
     16 + 
     17 +test(`AddLine - Adding a line to a multi-line font`, () => {
     18 + const input = [',-, ,-,', '|-| |-}', '| | |_}'];
     19 + 
     20 + expect(AddLine([...input], 3, ['', '', ''], 0)).toEqual([...input, '', '', '']);
     21 + expect(AddLine([...input], 3, ['', '', ''], 1)).toEqual([...input, '', '', '', '']);
     22 + expect(AddLine([...input], 3, ['', '', ''], 10)).toEqual([
     23 + ...input,
     24 + '',
     25 + '',
     26 + '',
     27 + '',
     28 + '',
     29 + '',
     30 + '',
     31 + '',
     32 + '',
     33 + '',
     34 + '',
     35 + '',
     36 + '',
     37 + ]);
     38 +});
     39 + 
  • ■ ■ ■ ■ ■ ■
    test/unit/AddShortcuts.spec.js nodejs/test/unit/AddShortcuts.spec.js
    skipped 3 lines
    4 4   *
    5 5   **************************************************************************************************************************************************************/
    6 6   
    7  - 
    8 7  const { AddShortcuts } = require('../../src/AddShortcuts.js');
    9  - 
    10 8   
    11 9  test(`AddShortcuts - Should flatten shortcuts into object`, () => {
    12 10   const input = {
    13  - 'one': {
     11 + one: {
    14 12   description: 'desc value',
    15 13   short: 'oneshort',
    16 14   },
    17  - 'two': {
     15 + two: {
    18 16   description: 'desc value',
    19 17   short: 'twoshort',
    20 18   },
    21 19   };
    22 20   
    23 21   const output = {
    24  - 'one': {
     22 + one: {
    25 23   _name: 'one',
    26 24   description: 'desc value',
    27 25   short: 'oneshort',
    28 26   },
    29  - 'oneshort': {
     27 + oneshort: {
    30 28   _name: 'one',
    31 29   description: 'desc value',
    32 30   short: 'oneshort',
    33 31   },
    34  - 'two': {
     32 + two: {
    35 33   _name: 'two',
    36 34   description: 'desc value',
    37 35   short: 'twoshort',
    38 36   },
    39  - 'twoshort': {
     37 + twoshort: {
    40 38   _name: 'two',
    41 39   description: 'desc value',
    42 40   short: 'twoshort',
    43 41   },
    44 42   };
    45 43   
    46  - expect( AddShortcuts( input ) ).toEqual( output );
     44 + expect(AddShortcuts(input)).toEqual(output);
    47 45  });
    48 46   
  • ■ ■ ■ ■ ■ ■
    nodejs/test/unit/AlignText.spec.js
     1 +/***************************************************************************************************************************************************************
     2 + *
     3 + * AlignText unit tests
     4 + *
     5 + **************************************************************************************************************************************************************/
     6 + 
     7 +const { AlignText } = require('../../src/AlignText.js');
     8 + 
     9 +test(`AlignText - Should align text in the center`, () => {
     10 + expect(AlignText(['x'], 1, 1, 'center', { width: 21 })).toEqual([' x']);
     11 + expect(AlignText(['x'], 1, 1, 'center', { width: 1 })).toEqual(['x']);
     12 +});
     13 + 
     14 +test(`AlignText - Should align text on the right`, () => {
     15 + expect(AlignText(['x'], 1, 1, 'right', { width: 11 })).toEqual([' x']);
     16 + expect(AlignText(['x'], 1, 1, 'right', { width: 1 })).toEqual(['x']);
     17 +});
     18 + 
     19 +test(`AlignText - Should do nothing on left alignment`, () => {
     20 + expect(AlignText(['x'], 1, 1, 'left', { width: 11 })).toEqual(['x']);
     21 +});
     22 + 
     23 +test(`AlignText - Should do nothing when using Size default value`, () => {
     24 + expect(AlignText(['x'], 1, 1, 'left')).toEqual(['x']);
     25 +});
     26 + 
     27 +test(`AlignText - Should do nothing when align top or bottom`, () => {
     28 + expect(AlignText(['x'], 1, 1, 'top', { width: 21 })).toEqual(['x']);
     29 + expect(AlignText(['x'], 1, 1, 'top', { width: 1 })).toEqual(['x']);
     30 + expect(AlignText(['x'], 1, 1, 'bottom', { width: 21 })).toEqual(['x']);
     31 + expect(AlignText(['x'], 1, 1, 'bottom', { width: 1 })).toEqual(['x']);
     32 +});
     33 + 
  • ■ ■ ■ ■ ■ ■
    nodejs/test/unit/CharLength.spec.js
     1 +/***************************************************************************************************************************************************************
     2 + *
     3 + * CharLength unit tests
     4 + *
     5 + **************************************************************************************************************************************************************/
     6 + 
     7 +const { CharLength } = require('../../src/CharLength.js');
     8 + 
     9 +test(`CharLength - Should return the largest character length`, () => {
     10 + const character1 = [''];
     11 + const character2 = ['', ' '];
     12 + const character3 = [' ', ''];
     13 + const character4 = ['', ' ', ''];
     14 + const character5 = [' ', '', ' ', '', ' ', ' '];
     15 + 
     16 + expect(CharLength(character1, character1.length, 0)).toEqual(0);
     17 + expect(CharLength(character2, character2.length, 0)).toEqual(2);
     18 + expect(CharLength(character3, character3.length, 0)).toEqual(6);
     19 + expect(CharLength(character4, character4.length, 0)).toEqual(3);
     20 + expect(CharLength(character5, character5.length, 0)).toEqual(12);
     21 + 
     22 + expect(CharLength(character1, character1.length, 5)).toEqual(1);
     23 + expect(CharLength(character2, character2.length, 5)).toEqual(2);
     24 + expect(CharLength(character3, character3.length, 5)).toEqual(6);
     25 + expect(CharLength(character4, character4.length, 5)).toEqual(3);
     26 + expect(CharLength(character5, character5.length, 5)).toEqual(12);
     27 + 
     28 + expect(CharLength(character1, character1.length, 1)).toEqual(1);
     29 +});
     30 + 
Please wait...
Page is in error, reload to recover