├── .gitignore ├── .yarnrc ├── LICENSE.md ├── README.md ├── lerna.json ├── package.json ├── packages └── ink-use-stdout-dimensions │ ├── .npmignore │ ├── LICENSE.md │ ├── README.md │ ├── demo.gif │ ├── demo │ └── index.tsx │ ├── package.json │ └── src │ └── index.ts ├── tsconfig.json └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | node_modules/ 3 | -------------------------------------------------------------------------------- /.yarnrc: -------------------------------------------------------------------------------- 1 | --workspace.silent true 2 | --run.silent true 3 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Cameron Hunter 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ink-monorepo 2 | 3 | > Monorepo for [Ink](https://github.com/vadimdemedes/ink) related packages. 4 | -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/lerna", 3 | "npmClient": "yarn", 4 | "useWorkspaces": true, 5 | "packages": [ 6 | "packages/*" 7 | ], 8 | "version": "independent" 9 | } 10 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "name": "ink-monorepo", 4 | "version": "0.0.0", 5 | "description": "Monorepo for Ink related packages", 6 | "main": "index.js", 7 | "author": "Cameron Hunter ", 8 | "license": "MIT", 9 | "scripts": { 10 | "build": "lerna run build", 11 | "verify": "tsc --noEmit", 12 | "preversion": "yarn build" 13 | }, 14 | "devDependencies": { 15 | "lerna": "^3.20.2", 16 | "typescript": "^3.7.5" 17 | }, 18 | "repository": { 19 | "type": "git", 20 | "url": "git@github.com:cameronhunter/ink-monorepo.git" 21 | }, 22 | "workspaces": [ 23 | "./packages/*" 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /packages/ink-use-stdout-dimensions/.npmignore: -------------------------------------------------------------------------------- 1 | demo/ 2 | demo.gif 3 | -------------------------------------------------------------------------------- /packages/ink-use-stdout-dimensions/LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Cameron Hunter 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/ink-use-stdout-dimensions/README.md: -------------------------------------------------------------------------------- 1 | # ink-use-stdout-dimensions 2 | 3 | > React hook for subscribing to stdout dimensions in [Ink](https://github.com/vadimdemedes/ink) 4 | 5 | ## Install 6 | 7 | ``` 8 | $ npm install ink-use-stdout-dimensions 9 | ``` 10 | 11 | ``` 12 | $ yarn add ink-use-stdout-dimensions 13 | ``` 14 | 15 | ## Usage 16 | 17 | ```js 18 | import React from 'react'; 19 | import { render } from 'ink'; 20 | import useStdoutDimensions from 'ink-use-stdout-dimensions'; 21 | 22 | function Application() { 23 | const [columns, rows] = useStdoutDimensions(); 24 | return ( 25 | 26 | {columns}×{rows} 27 | 28 | ); 29 | } 30 | 31 | render(); 32 | ``` 33 | 34 | ![Demo of ink-use-stdout-dimensions](https://github.com/cameronhunter/ink-monorepo/blob/master/packages/ink-use-stdout-dimensions/demo.gif?raw=true) 35 | 36 | ## API 37 | 38 | ### `useStdoutDimensions(): [number, number]` 39 | 40 | Returns initial `stdout` columns and rows and updates values on `resize` events. 41 | 42 | ## License 43 | 44 | MIT © [Cameron Hunter](https://cameronhunter.co.uk) 45 | -------------------------------------------------------------------------------- /packages/ink-use-stdout-dimensions/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cameronhunter/ink-monorepo/99a99e7bb13bee76c0eace3ff3fc2ce2611ea3a7/packages/ink-use-stdout-dimensions/demo.gif -------------------------------------------------------------------------------- /packages/ink-use-stdout-dimensions/demo/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { render, Text } from 'ink'; 3 | import useStdoutDimensions from '../src/index'; 4 | 5 | function Application() { 6 | const [columns, rows] = useStdoutDimensions(); 7 | return ( 8 | 9 | {columns}×{rows} 10 | 11 | ); 12 | } 13 | 14 | const { unmount } = render(); 15 | 16 | setTimeout(() => unmount(), 30_000); 17 | -------------------------------------------------------------------------------- /packages/ink-use-stdout-dimensions/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ink-use-stdout-dimensions", 3 | "version": "1.0.5", 4 | "license": "MIT", 5 | "description": "React hook for subscribing to stdout dimensions in Ink", 6 | "main": "./build/index.js", 7 | "repository": { 8 | "type": "git", 9 | "url": "git@github.com:cameronhunter/ink-monorepo.git", 10 | "directory": "packages/ink-use-stdout-dimensions" 11 | }, 12 | "scripts": { 13 | "prebuild": "rm -rf ./build", 14 | "build": "tsc --outDir ./build", 15 | "demo": "ts-node --transpile-only ./demo/index.tsx" 16 | }, 17 | "peerDependencies": { 18 | "ink": ">=2.0.0", 19 | "react": ">=16.0.0" 20 | }, 21 | "devDependencies": { 22 | "@types/react": "^16.9.17", 23 | "ink": "^2.6.0", 24 | "react": "^16.12.0", 25 | "ts-node": "^8.6.2" 26 | }, 27 | "keywords": [ 28 | "ink-hook", 29 | "ink", 30 | "hook", 31 | "react", 32 | "terminal", 33 | "term", 34 | "console", 35 | "command-line", 36 | "stdout", 37 | "dimensions" 38 | ] 39 | } 40 | -------------------------------------------------------------------------------- /packages/ink-use-stdout-dimensions/src/index.ts: -------------------------------------------------------------------------------- 1 | import { useEffect, useState } from 'react'; 2 | import { useStdout } from 'ink'; 3 | 4 | function useStdoutDimensions(): [number, number] { 5 | const { stdout } = useStdout(); 6 | const [dimensions, setDimensions] = useState<[number, number]>([stdout.columns, stdout.rows]); 7 | 8 | useEffect(() => { 9 | const handler = () => setDimensions([stdout.columns, stdout.rows]); 10 | stdout.on('resize', handler); 11 | return () => { 12 | stdout.off('resize', handler); 13 | }; 14 | }, [stdout]); 15 | 16 | return dimensions; 17 | } 18 | 19 | export = useStdoutDimensions; 20 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "include": ["packages/**/*.ts", "packages/**/*.tsx"], 3 | "exclude": ["node_modules", "packages/**/demo/*.ts", "packages/**/demo/*.tsx"], 4 | "compilerOptions": { 5 | "declaration": true, 6 | "esModuleInterop": true, 7 | "module": "commonjs", 8 | "strict": true, 9 | "target": "es2015", 10 | "skipLibCheck": true, 11 | "jsx": "react" 12 | } 13 | } 14 | --------------------------------------------------------------------------------