├── .eslintrc.js
├── .github
└── workflows
│ ├── deploy-preview.yaml
│ ├── deploy-prod.yaml
│ ├── release.yaml
│ └── test.yaml
├── .gitignore
├── .licensee.json
├── .npmignore
├── .prettierrc.js
├── .releaserc.json
├── LICENSE
├── README.md
├── assets
└── license_header.txt
├── css
└── styles.css
├── examples
└── create-react-app
│ ├── .gitignore
│ ├── README.md
│ ├── package.json
│ ├── public
│ ├── favicon.ico
│ ├── index.html
│ ├── logo192.png
│ ├── logo512.png
│ ├── manifest.json
│ └── robots.txt
│ ├── src
│ ├── App.css
│ ├── App.js
│ ├── App.test.js
│ ├── index.css
│ ├── index.js
│ ├── logo.svg
│ ├── reportWebVitals.js
│ ├── setupTests.js
│ └── terminals
│ │ ├── basic.js
│ │ ├── color.js
│ │ ├── custom-element.js
│ │ ├── custom-prompt.js
│ │ ├── progress.js
│ │ └── spinner.js
│ └── yarn.lock
├── jest.config.js
├── licenseconfig.json
├── media
├── demo-basic.gif
├── demo-frames.gif
├── demo-progress.gif
├── demo-spinner.gif
├── demo.gif
└── white-terminal.png
├── package.json
├── src
├── Code.tsx
├── Renderer.tsx
├── Terminal.tsx
├── __snapshots__
│ └── contentHandler.spec.ts.snap
├── contentHandler.spec.ts
├── contentHandler.ts
└── index.ts
├── tsconfig.json
└── yarn.lock
/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | parser: '@typescript-eslint/parser',
3 | env: {
4 | node: true,
5 | },
6 | extends: [
7 | 'plugin:@typescript-eslint/eslint-recommended',
8 | 'plugin:@typescript-eslint/recommended',
9 | ],
10 | rules: {
11 | '@typescript-eslint/explicit-function-return-type': 'off',
12 | '@typescript-eslint/ban-ts-ignore': 'off',
13 | '@typescript-eslint/no-explicit-any': 'off',
14 | },
15 | };
16 |
--------------------------------------------------------------------------------
/.github/workflows/deploy-preview.yaml:
--------------------------------------------------------------------------------
1 | name: Deploy to vercel preview
2 |
3 | on:
4 | pull_request:
5 | branches:
6 | - 'develop'
7 | push:
8 | branches:
9 | - 'develop'
10 |
11 | concurrency:
12 | group: ci-${{ github.ref }}
13 | cancel-in-progress: true
14 |
15 | jobs:
16 | deploy:
17 | runs-on: ubuntu-latest
18 | steps:
19 | - uses: actions/checkout@v2
20 | # deploy app to vercel
21 | - name: deploy site to vercel
22 | uses: amondnet/vercel-action@v20
23 | with:
24 | scope: ${{ secrets.VERCEL_TEAM_ID }} # Required
25 | vercel-token: ${{ secrets.VERCEL_TOKEN }} # Required
26 | github-token: ${{ secrets.GITHUB_TOKEN }} #Optional
27 | # vercel-args: "--prod" #Optional
28 | vercel-org-id: ${{ secrets.VERCEL_ORG_ID}} #Required
29 | vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID}} #Required
30 |
--------------------------------------------------------------------------------
/.github/workflows/deploy-prod.yaml:
--------------------------------------------------------------------------------
1 | name: Deploy to vercel prod
2 |
3 | on:
4 | pull_request:
5 | types: [closed]
6 | branches:
7 | - 'main'
8 |
9 | concurrency:
10 | group: ci-${{ github.ref }}
11 | cancel-in-progress: true
12 |
13 | jobs:
14 | deploy:
15 | runs-on: ubuntu-latest
16 | steps:
17 | - uses: actions/checkout@v2
18 | # deploy app to vercel
19 | - name: deploy site to vercel
20 | uses: amondnet/vercel-action@v20
21 | with:
22 | scope: ${{ secrets.VERCEL_TEAM_ID }} # Required
23 | vercel-token: ${{ secrets.VERCEL_TOKEN }} # Required
24 | github-token: ${{ secrets.GITHUB_TOKEN }} #Optional
25 | vercel-args: '--prod' #Optional
26 | vercel-org-id: ${{ secrets.VERCEL_ORG_ID}} #Required
27 | vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID}} #Required
28 |
--------------------------------------------------------------------------------
/.github/workflows/release.yaml:
--------------------------------------------------------------------------------
1 | name: Release
2 | on:
3 | push:
4 | branches:
5 | - main
6 | - develop
7 | jobs:
8 | release:
9 | name: Release
10 | runs-on: ubuntu-latest
11 | steps:
12 | - name: Checkout
13 | uses: actions/checkout@v2
14 | with:
15 | fetch-depth: 0
16 | - name: Cache Yarn Cache
17 | uses: actions/cache@v2
18 | with:
19 | path: "node_modules"
20 | key: ${{ runner.os }}-modules-${{ hashFiles('yarn.lock') }}
21 | - name: Install dependencies
22 | run: yarn install --frozen-lockfile
23 | - name: Build
24 | run: yarn build
25 | - name: Release
26 | env:
27 | GITHUB_TOKEN: ${{ secrets.NITRIC_BOT_TOKEN }}
28 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
29 | run: npx semantic-release
30 |
--------------------------------------------------------------------------------
/.github/workflows/test.yaml:
--------------------------------------------------------------------------------
1 | name: Tests
2 |
3 | on:
4 | push:
5 | branches:
6 | - main
7 | pull_request:
8 |
9 | jobs:
10 | build:
11 | runs-on: ubuntu-latest
12 | steps:
13 | - name: Checkout
14 | uses: actions/checkout@v2
15 |
16 | - name: Cache Yarn Cache
17 | uses: actions/cache@v2
18 | with:
19 | path: 'node_modules'
20 | key: ${{ runner.os }}-modules-${{ hashFiles('yarn.lock') }}
21 | - name: Install modules
22 | run: yarn --frozen-lockfile
23 | - name: License Header Check
24 | run: yarn license:header:check
25 | - name: OSS License Whitelist Check
26 | run: yarn license:check
27 | - name: Build
28 | run: yarn build
29 | - name: Lint
30 | run: yarn lint
31 | - name: Test
32 | run: yarn coverage:upload
33 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Ignore tmp directory
2 | tmp/
3 |
4 | # Logs
5 | logs
6 | *.log
7 | npm-debug.log*
8 | yarn-debug.log*
9 | yarn-error.log*
10 | lerna-debug.log*
11 |
12 | # Diagnostic reports (https://nodejs.org/api/report.html)
13 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
14 |
15 | # Runtime data
16 | pids
17 | *.pid
18 | *.seed
19 | *.pid.lock
20 |
21 | # Directory for instrumented libs generated by jscoverage/JSCover
22 | lib-cov
23 |
24 | # Coverage directory used by tools like istanbul
25 | coverage
26 | *.lcov
27 |
28 | # nyc test coverage
29 | .nyc_output
30 |
31 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
32 | .grunt
33 |
34 | # Bower dependency directory (https://bower.io/)
35 | bower_components
36 |
37 | # node-waf configuration
38 | .lock-wscript
39 |
40 | # Compiled binary addons (https://nodejs.org/api/addons.html)
41 | build/Release
42 |
43 | # Dependency directories
44 | node_modules/
45 | jspm_packages/
46 |
47 | # TypeScript v1 declaration files
48 | typings/
49 |
50 | # TypeScript cache
51 | *.tsbuildinfo
52 |
53 | # Optional npm cache directory
54 | .npm
55 |
56 | # Optional eslint cache
57 | .eslintcache
58 |
59 | # Optional REPL history
60 | .node_repl_history
61 |
62 | # Output of 'npm pack'
63 | *.tgz
64 |
65 | # Yarn Integrity file
66 | .yarn-integrity
67 |
68 | # dotenv environment variables file
69 | .env
70 | .env.test
71 |
72 | # parcel-bundler cache (https://parceljs.org/)
73 | .cache
74 |
75 | # next.js build output
76 | .next
77 |
78 | # nuxt.js build output
79 | .nuxt
80 |
81 | # vuepress build output
82 | .vuepress/dist
83 |
84 | # Serverless directories
85 | .serverless/
86 |
87 | # FuseBox cache
88 | .fusebox/
89 |
90 | # DynamoDB Local files
91 | .dynamodb/
92 |
93 | lib/
94 | dist/
95 |
96 | *_pb.*
--------------------------------------------------------------------------------
/.licensee.json:
--------------------------------------------------------------------------------
1 | {
2 | "licenses": {
3 | "spdx": ["MIT", "BSD-3-Clause", "Apache-2.0", "ISC", "0BSD"]
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | src/
2 | .git/
3 | .github/
4 | .gitmodules
5 | tests/
6 | coverage/
7 | node_modules/
8 | docs/
9 | jest.config.js
10 | tsconfig.json
11 | yarn.lock
12 | README.md
--------------------------------------------------------------------------------
/.prettierrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | semi: true,
3 | trailingComma: 'es5',
4 | singleQuote: true,
5 | printWidth: 80,
6 | tabWidth: 2,
7 | useTabs: false,
8 | };
9 |
--------------------------------------------------------------------------------
/.releaserc.json:
--------------------------------------------------------------------------------
1 | {
2 | "branches": ["main", { "name": "develop", "prerelease": true }],
3 | "plugins": [
4 | "@semantic-release/commit-analyzer",
5 | "@semantic-release/release-notes-generator",
6 | "@semantic-release/npm",
7 | [
8 | "@semantic-release/github",
9 | {
10 | "assets": ["dist/**"]
11 | }
12 | ]
13 | ]
14 | }
15 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | https://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | https://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # @nitric/react-animated-term
2 |
3 | 
4 | 
5 | 
6 | 
7 |
8 | > Animated terminal component for [React](https://reactjs.org/)
9 | >
10 | > Rewrite of [react-animated-term](https://github.com/dongy7/react-animated-term) in Typescript with added features
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 | ## Installation
20 |
21 | ```
22 | npm install @nitric/react-animated-term
23 | ```
24 |
25 | OR
26 |
27 | ```bash
28 | yarn add @nitric/react-animated-term
29 | ```
30 |
31 | You can then import `react-animated-term` and its styles.
32 |
33 | ```js
34 | import Terminal from '@nitric/react-animated-term';
35 | import '@nitric/react-animated-term/css/styles.css';
36 | ```
37 |
38 | ## Usage
39 |
40 | The terminal commands and output lines are specified as an array of objects. The `text` field specifies the content of the line and `cmd` is used to specify whether the line is a command or an output. The `interval` prop specifies how often the terminal should be updated.
41 |
42 | ```js
43 | import React from 'react';
44 | import Terminal from '@nitric/react-animated-term';
45 |
46 | const termLines = [
47 | {
48 | text: 'ls',
49 | color: 'blue', // you can add colors
50 | cmd: true,
51 | },
52 | {
53 | text: 'index.js package.json node_modules',
54 | cmd: false,
55 | },
56 | {
57 | text: '',
58 | cmd: true,
59 | },
60 | ];
61 |
62 | const MyComponent = () => {
63 | return ;
64 | };
65 | ```
66 |
67 | ### Framed Animation
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 | You can also render output that consists of frames by specifying the individual frames. With a framed output, the `text` field specifies the final output that should be rendered after all the frames have been rendered. Delays can also be specified for individual frames and commands.
77 |
78 | ```jsx
79 | import React from 'react';
80 | import Terminal from '@nitric/react-animated-term';
81 | const spinner = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
82 | const termLines = [
83 | {
84 | text: 'node example.js',
85 | cmd: true,
86 | delay: 80,
87 | },
88 | {
89 | text: '✔ Loaded app',
90 | element: <>✔ Loaded app<>,
91 | cmd: false,
92 | repeat: true,
93 | repeatCount: 5,
94 | frames: spinner.map(function (spinner) {
95 | return {
96 | text: spinner + ' Loading app',
97 | delay: 40,
98 | };
99 | }),
100 | },
101 | {
102 | text: '',
103 | cmd: true,
104 | },
105 | ];
106 |
107 | const MyComponent = () => {
108 | return ;
109 | };
110 | ```
111 |
112 | ### Themes
113 |
114 | A white themed terminal is specified using the `white` prop.
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 | ```js
124 | import React from 'react';
125 | import Terminal from '@nitric/react-animated-term';
126 |
127 | const MyComponent = () => {
128 | return ;
129 | };
130 | ```
131 |
132 | ### Props
133 |
134 | | Property | Type | Default | Description |
135 | | :---------- | :------ | :-------- | :----------------------------------------------------------------------------- |
136 | | lines | array | undefined | array of terminal lines |
137 | | interval | number | 100 | interval at which terminal output is updated in milliseconds |
138 | | white | boolean | false | whether to render a white themed terminal |
139 | | height | number | 240 | the height of the terminal |
140 | | onCompleted | func | undefined | a function callback that gets called when the terminal animation has completed |
141 | | replay | boolean | true | Shows or hides the replay button |
142 |
143 | ### Examples
144 |
145 | You can view the deployed example from `examples/create-react-app` here: [react-animated-term.vercel.app](https://react-animated-term.vercel.app).
146 |
147 | To run the examples, clone and install the dependencies:
148 |
149 | ```bash
150 | git clone https://github.com/nitrictech/react-animated-term.git
151 | yarn install
152 | ```
153 |
154 | Then, run the `start` script and open up `http://localhost:3000`.
155 |
156 | ```bash
157 | yarn start
158 | ```
159 |
160 | ## Credits
161 |
162 | The original code was written by [dongy7](https://github.com/dongy7) under the [react-animated-term](https://github.com/dongy7/react-animated-term) repo.
163 |
164 | The styling for the terminal was adapted from the [Hyper](https://hyper.is/) terminal.
165 |
--------------------------------------------------------------------------------
/assets/license_header.txt:
--------------------------------------------------------------------------------
1 | Copyright 2022, Nitric Technologies Pty Ltd.
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License");
4 | you may not use this file except in compliance with the License.
5 | You may obtain a copy of the License at
6 |
7 | http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | Unless required by applicable law or agreed to in writing, software
10 | distributed under the License is distributed on an "AS IS" BASIS,
11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | See the License for the specific language governing permissions and
13 | limitations under the License.
--------------------------------------------------------------------------------
/css/styles.css:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2022, Nitric Technologies Pty Ltd.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 | .Terminal-window {
17 | position: relative;
18 | width: 100%;
19 | height: 100%;
20 | border: 1px solid var(--nitric-terminal-window-border-color, rgb(51, 51, 51));
21 | border-radius: 5px;
22 | box-shadow: rgba(0, 0, 0, 0.12) 0px 1px 6px, rgba(0, 0, 0, 0.12) 0px 1px 4px;
23 | background: var(--nitric-terminal-window, rgb(0, 0, 0));
24 | }
25 |
26 | .Terminal-window-white {
27 | background: #fff;
28 | border-style: solid;
29 | border-color: transparent;
30 | }
31 |
32 | .Terminal-term {
33 | width: 100%;
34 | height: 240px;
35 | }
36 |
37 | .Terminal-term-code {
38 | height: 100%;
39 | }
40 |
41 | .Terminal-header {
42 | position: absolute;
43 | width: 100%;
44 | top: 18px;
45 | }
46 |
47 | .Terminal-body {
48 | width: 100%;
49 | height: 100%;
50 | margin-top: 45px;
51 | }
52 |
53 | .Terminal-body-animated {
54 | position: absolute;
55 | }
56 |
57 | .Terminal-console {
58 | font-size: 12px;
59 | font-family: Menlo, DejaVu Sans Mono, Consolas, Lucida Console, monospace;
60 | line-height: 24px;
61 | color: rgb(255, 255, 255);
62 | margin: 0px 16px;
63 | }
64 |
65 | .Terminal-console-code {
66 | margin: 40px 16px;
67 | }
68 |
69 | .Terminal-console-white {
70 | color: #000;
71 | }
72 |
73 | .Terminal-btn {
74 | display: inline-block;
75 | position: absolute;
76 | border-radius: 50%;
77 | width: 12px;
78 | height: 12px;
79 | top: 50%;
80 | transform: translateY(-50%);
81 | }
82 |
83 | .Terminal-btn-close {
84 | background-color: var(--nitric-btn-close, rgb(255, 95, 86));
85 | left: 13px;
86 | }
87 |
88 | .Terminal-btn-minimize {
89 | background-color: var(--nitric-btn-minimize, rgb(255, 189, 46));
90 | left: 33px;
91 | }
92 |
93 | .Terminal-btn-maximize {
94 | background-color: var(--nitric-btn-maximize, rgb(39, 201, 63));
95 | left: 53px;
96 | }
97 |
98 | .Terminal-prompt {
99 | color: rgb(204, 204, 204);
100 | }
101 |
102 | .Terminal-cursor {
103 | display: inline-block;
104 | width: 6px;
105 | height: 15px;
106 | background: var(--nitric-term-cursor, rgb(248, 28, 229));
107 | vertical-align: middle;
108 | }
109 |
110 | .Terminal-code {
111 | margin: 0;
112 | font-size: 12px;
113 | font-family: Menlo, DejaVu Sans Mono, Consolas, Lucida Console, monospace;
114 | line-height: 20px;
115 | white-space: pre-wrap;
116 | }
117 |
118 | .Terminal-control-btn {
119 | position: absolute;
120 | bottom: 52px;
121 | right: 8px;
122 | display: inline-block;
123 | border-radius: 3px;
124 | padding: 5px 10px;
125 | background: transparent;
126 | color: white;
127 | border: 2px solid white;
128 | font-family: 'Avenir Next', -apple-system, BlinkMacSystemFont, 'Segoe UI',
129 | Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji',
130 | 'Segoe UI Symbol';
131 | cursor: pointer;
132 | }
133 |
134 | .Terminal-control-btn-white {
135 | color: black;
136 | border: 2px solid black;
137 | }
138 |
--------------------------------------------------------------------------------
/examples/create-react-app/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 |
14 | # misc
15 | .DS_Store
16 | .env.local
17 | .env.development.local
18 | .env.test.local
19 | .env.production.local
20 |
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 |
25 | .vercel
26 |
--------------------------------------------------------------------------------
/examples/create-react-app/README.md:
--------------------------------------------------------------------------------
1 | # Getting Started with Create React App
2 |
3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
4 |
5 | ## Available Scripts
6 |
7 | In the project directory, you can run:
8 |
9 | ### `npm start`
10 |
11 | Runs the app in the development mode.\
12 | Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
13 |
14 | The page will reload when you make changes.\
15 | You may also see any lint errors in the console.
16 |
17 | ### `npm test`
18 |
19 | Launches the test runner in the interactive watch mode.\
20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
21 |
22 | ### `npm run build`
23 |
24 | Builds the app for production to the `build` folder.\
25 | It correctly bundles React in production mode and optimizes the build for the best performance.
26 |
27 | The build is minified and the filenames include the hashes.\
28 | Your app is ready to be deployed!
29 |
30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
31 |
32 | ### `npm run eject`
33 |
34 | **Note: this is a one-way operation. Once you `eject`, you can't go back!**
35 |
36 | If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
37 |
38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.
39 |
40 | You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.
41 |
42 | ## Learn More
43 |
44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
45 |
46 | To learn React, check out the [React documentation](https://reactjs.org/).
47 |
48 | ### Code Splitting
49 |
50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
51 |
52 | ### Analyzing the Bundle Size
53 |
54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
55 |
56 | ### Making a Progressive Web App
57 |
58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
59 |
60 | ### Advanced Configuration
61 |
62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
63 |
64 | ### Deployment
65 |
66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
67 |
68 | ### `npm run build` fails to minify
69 |
70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
71 |
--------------------------------------------------------------------------------
/examples/create-react-app/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "create-react-app",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "@testing-library/jest-dom": "^5.16.2",
7 | "@testing-library/react": "^12.1.2",
8 | "@testing-library/user-event": "^13.5.0",
9 | "react": "^17.0.2",
10 | "react-dom": "^17.0.2",
11 | "react-scripts": "5.0.0",
12 | "web-vitals": "^2.1.4"
13 | },
14 | "scripts": {
15 | "start": "react-scripts start",
16 | "build": "react-scripts build",
17 | "test": "react-scripts test",
18 | "eject": "react-scripts eject"
19 | },
20 | "eslintConfig": {
21 | "extends": [
22 | "react-app",
23 | "react-app/jest"
24 | ]
25 | },
26 | "browserslist": {
27 | "production": [
28 | ">0.2%",
29 | "not dead",
30 | "not op_mini all"
31 | ],
32 | "development": [
33 | "last 1 chrome version",
34 | "last 1 firefox version",
35 | "last 1 safari version"
36 | ]
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/examples/create-react-app/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitrictech/react-animated-term/58c0f8b944d881048d39f53145c306c6012be719/examples/create-react-app/public/favicon.ico
--------------------------------------------------------------------------------
/examples/create-react-app/public/index.html:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
27 |
28 |
32 |
33 |
42 | React App
43 |
44 |
45 |
46 |
47 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/examples/create-react-app/public/logo192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitrictech/react-animated-term/58c0f8b944d881048d39f53145c306c6012be719/examples/create-react-app/public/logo192.png
--------------------------------------------------------------------------------
/examples/create-react-app/public/logo512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitrictech/react-animated-term/58c0f8b944d881048d39f53145c306c6012be719/examples/create-react-app/public/logo512.png
--------------------------------------------------------------------------------
/examples/create-react-app/public/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "React App",
3 | "name": "Create React App Sample",
4 | "icons": [
5 | {
6 | "src": "favicon.ico",
7 | "sizes": "64x64 32x32 24x24 16x16",
8 | "type": "image/x-icon"
9 | },
10 | {
11 | "src": "logo192.png",
12 | "type": "image/png",
13 | "sizes": "192x192"
14 | },
15 | {
16 | "src": "logo512.png",
17 | "type": "image/png",
18 | "sizes": "512x512"
19 | }
20 | ],
21 | "start_url": ".",
22 | "display": "standalone",
23 | "theme_color": "#000000",
24 | "background_color": "#ffffff"
25 | }
26 |
--------------------------------------------------------------------------------
/examples/create-react-app/public/robots.txt:
--------------------------------------------------------------------------------
1 | Copyright 2022, Nitric Technologies Pty Ltd.
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License");
4 | you may not use this file except in compliance with the License.
5 | You may obtain a copy of the License at
6 |
7 | http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | Unless required by applicable law or agreed to in writing, software
10 | distributed under the License is distributed on an "AS IS" BASIS,
11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | See the License for the specific language governing permissions and
13 | limitations under the License.
14 | # https://www.robotstxt.org/robotstxt.html
15 | User-agent: *
16 | Disallow:
17 |
--------------------------------------------------------------------------------
/examples/create-react-app/src/App.css:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2022, Nitric Technologies Pty Ltd.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 | .App {
17 | text-align: center;
18 | }
19 |
20 | .App-logo {
21 | height: 40vmin;
22 | pointer-events: none;
23 | }
24 |
25 | @media (prefers-reduced-motion: no-preference) {
26 | .App-logo {
27 | animation: App-logo-spin infinite 20s linear;
28 | }
29 | }
30 |
31 | .App-header {
32 | background-color: #282c34;
33 | min-height: 100vh;
34 | display: flex;
35 | flex-direction: column;
36 | align-items: center;
37 | justify-content: center;
38 | font-size: calc(10px + 2vmin);
39 | color: white;
40 | }
41 |
42 | .App-link {
43 | color: #61dafb;
44 | }
45 |
46 | @keyframes App-logo-spin {
47 | from {
48 | transform: rotate(0deg);
49 | }
50 | to {
51 | transform: rotate(360deg);
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/examples/create-react-app/src/App.js:
--------------------------------------------------------------------------------
1 | // Copyright 2022, Nitric Technologies Pty Ltd.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | import Renderer, { Code } from '@nitric/react-animated-term';
15 | import basicLines from './terminals/basic';
16 | import customPrompt from './terminals/custom-prompt';
17 | import spinnerLines from './terminals/spinner';
18 | import colorLines from './terminals/color';
19 | import progressLines from './terminals/progress';
20 | import customElement from './terminals/custom-element';
21 | import '@nitric/react-animated-term/css/styles.css';
22 |
23 | function App() {
24 | return (
25 |
26 |
React Animated Terminal
27 |
Basic Example
28 |
29 |
30 |
31 |
32 |
No replay
33 |
34 |
35 |
36 |
37 |
Custom Prompt
38 |
39 |
40 |
41 |
42 |
Custom React Element
43 |
44 |
45 |
46 |
47 |
Repeated Frames Example
48 |
49 |
50 |
51 |
52 |
Progress Bar Example
53 |
54 |
55 |
56 |
57 |
Custom JSX Example
58 |
59 |
60 |
61 |
62 |
Code Example
63 |
64 |
65 | {`import mod from 'mod';
66 | export default mod;`}
67 |
68 |
69 |
70 | );
71 | }
72 |
73 | export default App;
74 |
--------------------------------------------------------------------------------
/examples/create-react-app/src/App.test.js:
--------------------------------------------------------------------------------
1 | // Copyright 2022, Nitric Technologies Pty Ltd.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | import { render, screen } from '@testing-library/react';
15 | import App from './App';
16 |
17 | test('renders learn react link', () => {
18 | render();
19 | const linkElement = screen.getByText(/learn react/i);
20 | expect(linkElement).toBeInTheDocument();
21 | });
22 |
--------------------------------------------------------------------------------
/examples/create-react-app/src/index.css:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2022, Nitric Technologies Pty Ltd.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 | body {
17 | margin: 0;
18 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
19 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
20 | sans-serif;
21 | -webkit-font-smoothing: antialiased;
22 | -moz-osx-font-smoothing: grayscale;
23 | }
24 |
25 | code {
26 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
27 | monospace;
28 | }
29 |
--------------------------------------------------------------------------------
/examples/create-react-app/src/index.js:
--------------------------------------------------------------------------------
1 | // Copyright 2022, Nitric Technologies Pty Ltd.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | import React from 'react';
15 | import ReactDOM from 'react-dom';
16 | import './index.css';
17 | import App from './App';
18 | import reportWebVitals from './reportWebVitals';
19 |
20 | ReactDOM.render(
21 |
22 |
23 | ,
24 | document.getElementById('root')
25 | );
26 |
27 | // If you want to start measuring performance in your app, pass a function
28 | // to log results (for example: reportWebVitals(console.log))
29 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
30 | reportWebVitals();
31 |
--------------------------------------------------------------------------------
/examples/create-react-app/src/logo.svg:
--------------------------------------------------------------------------------
1 |
16 |
--------------------------------------------------------------------------------
/examples/create-react-app/src/reportWebVitals.js:
--------------------------------------------------------------------------------
1 | // Copyright 2022, Nitric Technologies Pty Ltd.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | const reportWebVitals = onPerfEntry => {
15 | if (onPerfEntry && onPerfEntry instanceof Function) {
16 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
17 | getCLS(onPerfEntry);
18 | getFID(onPerfEntry);
19 | getFCP(onPerfEntry);
20 | getLCP(onPerfEntry);
21 | getTTFB(onPerfEntry);
22 | });
23 | }
24 | };
25 |
26 | export default reportWebVitals;
27 |
--------------------------------------------------------------------------------
/examples/create-react-app/src/setupTests.js:
--------------------------------------------------------------------------------
1 | // Copyright 2022, Nitric Technologies Pty Ltd.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | // jest-dom adds custom jest matchers for asserting on DOM nodes.
15 | // allows you to do things like:
16 | // expect(element).toHaveTextContent(/react/i)
17 | // learn more: https://github.com/testing-library/jest-dom
18 | import '@testing-library/jest-dom';
19 |
--------------------------------------------------------------------------------
/examples/create-react-app/src/terminals/basic.js:
--------------------------------------------------------------------------------
1 | // Copyright 2022, Nitric Technologies Pty Ltd.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | const basic = [
15 | {
16 | text: 'ls',
17 | cmd: true,
18 | },
19 | {
20 | text: 'index.js package.json node_modules',
21 | },
22 | {
23 | text: '',
24 | cmd: true,
25 | },
26 | ];
27 |
28 | export default basic;
29 |
--------------------------------------------------------------------------------
/examples/create-react-app/src/terminals/color.js:
--------------------------------------------------------------------------------
1 | // Copyright 2022, Nitric Technologies Pty Ltd.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
15 | const spinner = [
16 | {
17 | text: 'node color.js',
18 | color: 'lightblue',
19 | cmd: true,
20 | delay: 80,
21 | },
22 | {
23 | text: '✔ Loaded app',
24 | color: 'lightgreen',
25 | cmd: false,
26 | repeat: true,
27 | repeatCount: 5,
28 | frames: spinnerFrames.map(function (spinner) {
29 | return {
30 | text: spinner + ' Loading app',
31 | delay: 40,
32 | };
33 | }),
34 | },
35 | {
36 | text: '',
37 | cmd: true,
38 | },
39 | ];
40 |
41 | export default spinner;
42 |
--------------------------------------------------------------------------------
/examples/create-react-app/src/terminals/custom-element.js:
--------------------------------------------------------------------------------
1 | // Copyright 2022, Nitric Technologies Pty Ltd.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
15 | const spinner = [
16 | {
17 | text: 'node example.js',
18 | element: (
19 | <>
20 |
26 | node
27 | {' '}
28 | Loaded app
29 | >
30 | ),
31 | cmd: true,
32 | delay: 80,
33 | },
34 | {
35 | text: '✔ Loaded app',
36 | element: (
37 | <>
38 |
43 | ✔
44 | {' '}
45 | Loaded app
46 | >
47 | ),
48 | cmd: false,
49 | repeat: true,
50 | repeatCount: 1,
51 | frames: spinnerFrames.map(function (spinner) {
52 | return {
53 | text: spinner + ' Loading app',
54 | delay: 80,
55 | };
56 | }),
57 | },
58 | {
59 | text: '',
60 | cmd: true,
61 | },
62 | ];
63 |
64 | export default spinner;
65 |
--------------------------------------------------------------------------------
/examples/create-react-app/src/terminals/custom-prompt.js:
--------------------------------------------------------------------------------
1 | // Copyright 2022, Nitric Technologies Pty Ltd.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | const basic = [
15 | {
16 | text: 'ls',
17 | cmd: true,
18 | prompt: '⯈',
19 | },
20 | {
21 | text: 'index.js package.json node_modules',
22 | },
23 | {
24 | text: '',
25 | cmd: true,
26 | prompt: '⯈',
27 | },
28 | ];
29 |
30 | export default basic;
31 |
--------------------------------------------------------------------------------
/examples/create-react-app/src/terminals/progress.js:
--------------------------------------------------------------------------------
1 | // Copyright 2022, Nitric Technologies Pty Ltd.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | const createProgressFrames = (frameCount, progressCount, maxWidth, delay) => {
15 | const frames = [];
16 | const step = Math.ceil(progressCount / frameCount);
17 |
18 | for (let i = 0; i < progressCount; i += step) {
19 | const progressText = ` ${i}/${progressCount}`;
20 | const filledLen = progressText.length + 2;
21 | const intervalCount = maxWidth - filledLen;
22 |
23 | const filledCount = Math.ceil((i / progressCount) * intervalCount);
24 | const unfilledCount = intervalCount - filledCount;
25 | const frame = `[${'#'.repeat(filledCount)}${'-'.repeat(
26 | unfilledCount
27 | )}] ${progressText}`;
28 |
29 | frames.push({
30 | text: frame,
31 | delay,
32 | });
33 | }
34 |
35 | return frames;
36 | };
37 |
38 | const progress = [
39 | {
40 | text: 'yarn',
41 | cmd: true,
42 | delay: 80,
43 | },
44 | {
45 | text: 'yarn install v1.6.0',
46 | cmd: false,
47 | delay: 80,
48 | },
49 | {
50 | text: '[1/4] 🔍 Resolving packages...',
51 | cmd: false,
52 | delay: 80,
53 | },
54 | {
55 | text: '[2/4] 🚚 Fetching packages...',
56 | cmd: false,
57 | },
58 | {
59 | text: '[3/4] 🔗 Linking dependencies...',
60 | cmd: false,
61 | frames: createProgressFrames(250, 1000, 60, 5),
62 | },
63 | {
64 | text: '[4/4] 📃 Building fresh packages...',
65 | cmd: false,
66 | frames: createProgressFrames(100, 2000, 60, 5),
67 | },
68 | {
69 | text: '✨ Done in 4.01s.',
70 | cmd: false,
71 | },
72 | {
73 | text: '',
74 | cmd: true,
75 | },
76 | ];
77 |
78 | export default progress;
79 |
--------------------------------------------------------------------------------
/examples/create-react-app/src/terminals/spinner.js:
--------------------------------------------------------------------------------
1 | // Copyright 2022, Nitric Technologies Pty Ltd.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
15 | const spinner = [
16 | {
17 | text: 'node example.js',
18 | cmd: true,
19 | delay: 80,
20 | },
21 | {
22 | text: '✔ Loaded app',
23 | cmd: false,
24 | repeat: true,
25 | repeatCount: 5,
26 | frames: spinnerFrames.map(function (spinner) {
27 | return {
28 | text: spinner + ' Loading app',
29 | delay: 40,
30 | };
31 | }),
32 | },
33 | {
34 | text: '',
35 | cmd: true,
36 | },
37 | ];
38 |
39 | export default spinner;
40 |
--------------------------------------------------------------------------------
/jest.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | preset: 'ts-jest',
3 | testEnvironment: 'node',
4 | modulePathIgnorePatterns: ['/examples/'],
5 | };
6 |
--------------------------------------------------------------------------------
/licenseconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "ignoreFile": ".gitignore",
3 | "ignore": [
4 | "README",
5 | ".*",
6 | "**/__snapshots__/**",
7 | "**/*.config.*",
8 | "**/.gitignore",
9 | "lib/**/*",
10 | "examples/**/*",
11 | ".yarn/",
12 | ".github/",
13 | "**/*.md",
14 | "*.lock",
15 | "*.html",
16 | "**/.eslintignore"
17 | ],
18 | "license": "./assets/license_header.txt",
19 | "licenseFormats": {
20 | "js|ts": {
21 | "eachLine": {
22 | "prepend": "// "
23 | }
24 | },
25 | "dotfile|^Dockerfile": {
26 | "eachLine": {
27 | "prepend": "# "
28 | }
29 | }
30 | },
31 | "trailingWhitespace": "TRIM"
32 | }
33 |
--------------------------------------------------------------------------------
/media/demo-basic.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitrictech/react-animated-term/58c0f8b944d881048d39f53145c306c6012be719/media/demo-basic.gif
--------------------------------------------------------------------------------
/media/demo-frames.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitrictech/react-animated-term/58c0f8b944d881048d39f53145c306c6012be719/media/demo-frames.gif
--------------------------------------------------------------------------------
/media/demo-progress.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitrictech/react-animated-term/58c0f8b944d881048d39f53145c306c6012be719/media/demo-progress.gif
--------------------------------------------------------------------------------
/media/demo-spinner.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitrictech/react-animated-term/58c0f8b944d881048d39f53145c306c6012be719/media/demo-spinner.gif
--------------------------------------------------------------------------------
/media/demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitrictech/react-animated-term/58c0f8b944d881048d39f53145c306c6012be719/media/demo.gif
--------------------------------------------------------------------------------
/media/white-terminal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitrictech/react-animated-term/58c0f8b944d881048d39f53145c306c6012be719/media/white-terminal.png
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@nitric/react-animated-term",
3 | "version": "1.0.0",
4 | "description": "React component for rendering animated terminals",
5 | "license": "Apache-2.0",
6 | "files": [
7 | "css/**",
8 | "dist/**"
9 | ],
10 | "repository": "https://github.com/nitrictech/react-animated-term",
11 | "author": "Nitric ",
12 | "contributors": [
13 | "David Moore "
14 | ],
15 | "keywords": [
16 | "react",
17 | "terminal",
18 | "console",
19 | "animation",
20 | "animated"
21 | ],
22 | "main": "dist/index.js",
23 | "module": "dist/index.mjs",
24 | "types": "dist/index.d.ts",
25 | "scripts": {
26 | "build": "tsup ./src/index.ts --clean --format cjs,esm --dts",
27 | "dev": "tsup ./src/index.ts --clean --format cjs,esm --dts --watch",
28 | "license:header:remove": "license-check-and-add remove -f ./licenseconfig.json",
29 | "license:header:add": "license-check-and-add add -f ./licenseconfig.json",
30 | "license:header:check": "license-check-and-add check -f ./licenseconfig.json",
31 | "license:check": "licensee --production",
32 | "test": "jest",
33 | "test:coverage": "jest --coverage",
34 | "coverage:upload": "yarn run test:coverage && codecov",
35 | "prettier:check": "prettier --check src",
36 | "prettier:fix": "prettier --write src",
37 | "lint": "eslint \"src/**/*.ts\"",
38 | "lint:fix": "yarn lint --fix",
39 | "start": "yarn --cwd examples/create-react-app start",
40 | "build-example": "yarn --cwd examples/create-react-app build",
41 | "install-example": "yarn --cwd examples/create-react-app install",
42 | "link-example": "yarn --cwd examples/create-react-app link \"@nitric/react-animated-term\""
43 | },
44 | "peerDependencies": {
45 | "react": "^17.0.2",
46 | "react-dom": "^17.0.2"
47 | },
48 | "dependencies": {
49 | "classnames": "^2.3.1",
50 | "tslib": "^2.3.1"
51 | },
52 | "devDependencies": {
53 | "@semantic-release/git": "^10.0.1",
54 | "@types/jest": "^27.4.0",
55 | "@types/react": "^17.0.39",
56 | "@typescript-eslint/eslint-plugin": "^5.10.1",
57 | "@typescript-eslint/parser": "^5.10.1",
58 | "codecov": "^3.8.3",
59 | "eslint": "^8.8.0",
60 | "husky": "^6.0.0",
61 | "jest": "^27.4.7",
62 | "license-check-and-add": "^4.0.2",
63 | "licensee": "^8.2.0",
64 | "lint-staged": "^12.3.2",
65 | "prettier": "^2.5.1",
66 | "ts-jest": "^27.1.3",
67 | "tsup": "^5.11.11",
68 | "typescript": "^4.5.5"
69 | },
70 | "lint-staged": {
71 | "src/**/*.{ts}": "yarn prettier:fix && lint:fix"
72 | },
73 | "husky": {
74 | "hooks": {
75 | "pre-commit": "lint-staged"
76 | }
77 | },
78 | "license-check-config": {
79 | "src": [
80 | "src/**/*.ts",
81 | "!./examples/**/*",
82 | "!./node_modules/**/*"
83 | ],
84 | "path": "assets/license_header.txt",
85 | "blocking": true,
86 | "logInfo": false,
87 | "logError": true
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/src/Code.tsx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2022, Nitric Technologies Pty Ltd.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 | import * as React from 'react';
17 | import Terminal, { TerminalProps } from './Terminal';
18 |
19 | const Code: React.FC> = ({ children, ...rest }) => {
20 | return (
21 |
22 | {children}
23 |
24 | );
25 | };
26 |
27 | export default Code;
28 |
--------------------------------------------------------------------------------
/src/Renderer.tsx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2022, Nitric Technologies Pty Ltd.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 | import * as React from 'react';
17 | import Terminal, { TerminalProps } from './Terminal';
18 | import termContent from './contentHandler';
19 |
20 | export interface Line {
21 | delay?: number;
22 | text?: string;
23 | element?: React.ReactElement;
24 | color?: string;
25 | cmd?: boolean;
26 | repeat?: boolean;
27 | repeatCount?: number;
28 | frames?: Line[];
29 | prompt?: string | React.ReactNode;
30 | replay?: boolean;
31 | }
32 |
33 | export interface RendererProps
34 | extends Omit {
35 | lines: Line[];
36 | interval?: number;
37 | onCompleted?: (replay: () => void) => void;
38 | }
39 |
40 | export interface RendererRef {
41 | replay: () => void;
42 | }
43 |
44 | const Renderer = React.forwardRef(
45 | ({ lines: initialLines = [], interval = 100, onCompleted, ...rest }, ref) => {
46 | const [lines, setLines] = React.useState([]);
47 | const [completed, setCompleted] = React.useState(false);
48 | let intervalRef = React.useRef();
49 | let contentRef = React.useRef();
50 |
51 | React.useEffect(() => {
52 | contentRef.current = termContent(initialLines);
53 |
54 | intervalRef.current = setInterval(() => {
55 | const { value, done } = contentRef.current.next();
56 | if (value) {
57 | setLines([...lines, ...value]);
58 | }
59 |
60 | if (done) {
61 | clearTimeout(intervalRef.current);
62 | setCompleted(true);
63 | }
64 | }, interval);
65 |
66 | return () => clearTimeout(intervalRef.current);
67 | }, []);
68 |
69 | const replay = () => {
70 | contentRef.current = termContent(initialLines);
71 | setCompleted(false);
72 |
73 | intervalRef.current = setInterval(() => {
74 | if (contentRef.current) {
75 | const { value, done } = contentRef.current.next();
76 | setLines([...value]);
77 | if (done) {
78 | clearInterval(intervalRef.current);
79 | setCompleted(true);
80 | }
81 | }
82 | }, interval);
83 | };
84 |
85 | React.useImperativeHandle(ref, () => ({
86 | replay,
87 | }));
88 |
89 | React.useEffect(() => {
90 | if (completed && typeof onCompleted !== 'undefined') {
91 | onCompleted(replay);
92 | }
93 | }, [completed]);
94 |
95 | return (
96 | replay()} completed={completed}>
97 | {lines}
98 |
99 | );
100 | }
101 | );
102 |
103 | export default Renderer;
104 |
--------------------------------------------------------------------------------
/src/Terminal.tsx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2022, Nitric Technologies Pty Ltd.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 | import * as React from 'react';
17 | import classNames from 'classnames';
18 |
19 | const cursor = ;
20 | const prompt = (prefix) => (
21 | {prefix || '$'}
22 | );
23 |
24 | const renderLines = (lines) => {
25 | return lines.map((line) => {
26 | return (
27 |
28 | {line.cmd ? prompt(line.prompt) : ''}
29 | {line.element ? (
30 | line.element
31 | ) : line.text ? (
32 | {line.text}
33 | ) : (
34 | line.text
35 | )}
36 | {line.current && line.cmd ? cursor : ''}
37 |
38 |
39 | );
40 | });
41 | };
42 |
43 | const getWindowStyle = (white: boolean) => {
44 | return classNames({
45 | 'Terminal-window': true,
46 | 'Terminal-window-white': white,
47 | });
48 | };
49 |
50 | const getTerminalStyle = (code: boolean) => {
51 | return classNames({
52 | 'Terminal-term': true,
53 | 'Terminal-term-code': code,
54 | });
55 | };
56 |
57 | const getButtonStyle = (type: string) => {
58 | return classNames({
59 | 'Terminal-btn': true,
60 | 'Terminal-btn-close': type === 'close',
61 | 'Terminal-btn-minimize': type === 'minimize',
62 | 'Terminal-btn-maximize': type === 'maximize',
63 | });
64 | };
65 |
66 | const getBodyStyle = (code: boolean) => {
67 | return classNames({
68 | 'Terminal-body': true,
69 | 'Terminal-body-animated': !code,
70 | });
71 | };
72 |
73 | const getConsoleStyle = (code: boolean, white: boolean) => {
74 | return classNames({
75 | 'Terminal-console': true,
76 | 'Terminal-console-code': code,
77 | 'Terminal-console-white': white,
78 | });
79 | };
80 |
81 | export interface TerminalProps {
82 | white?: boolean;
83 | height?: number;
84 | code?: boolean;
85 | onReplay?: () => void;
86 | completed?: boolean;
87 | replay?: boolean;
88 | }
89 |
90 | const Terminal: React.FC = ({
91 | children,
92 | white,
93 | height,
94 | code,
95 | onReplay,
96 | completed,
97 | replay = true,
98 | }) => {
99 | const btnClassName = white
100 | ? 'Terminal-control-btn Terminal-control-btn-white'
101 | : 'Terminal-control-btn';
102 |
103 | return (
104 |