ink 4.0.0 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/components/Box.d.ts +2 -76
- package/build/components/Box.js +6 -13
- package/build/components/Box.js.map +1 -1
- package/build/dom.d.ts +3 -3
- package/build/dom.js +2 -5
- package/build/dom.js.map +1 -1
- package/build/get-max-width.d.ts +2 -2
- package/build/get-max-width.js +2 -1
- package/build/get-max-width.js.map +1 -1
- package/build/hooks/use-input.js +29 -33
- package/build/hooks/use-input.js.map +1 -1
- package/build/ink.d.ts +2 -0
- package/build/ink.js +29 -7
- package/build/ink.js.map +1 -1
- package/build/output.d.ts +9 -1
- package/build/output.js +87 -20
- package/build/output.js.map +1 -1
- package/build/parse-keypress.d.ts +14 -0
- package/build/parse-keypress.js +225 -0
- package/build/parse-keypress.js.map +1 -0
- package/build/reconciler.js +58 -57
- package/build/reconciler.js.map +1 -1
- package/build/render-border.js +47 -10
- package/build/render-border.js.map +1 -1
- package/build/render-node-to-output.js +28 -1
- package/build/render-node-to-output.js.map +1 -1
- package/build/renderer.d.ts +1 -1
- package/build/renderer.js +1 -4
- package/build/renderer.js.map +1 -1
- package/build/styles.d.ts +107 -4
- package/build/styles.js +56 -7
- package/build/styles.js.map +1 -1
- package/package.json +11 -5
- package/readme.md +234 -29
package/readme.md
CHANGED
|
@@ -127,6 +127,7 @@ Feel free to play around with the code and fork this repl at [https://repl.it/@v
|
|
|
127
127
|
- [lrn](https://github.com/krychu/lrn) - Learning by repetition.
|
|
128
128
|
- [turdle](https://github.com/mynameisankit/turdle) - Wordle game.
|
|
129
129
|
- [Shopify CLI](https://github.com/Shopify/cli) - Build apps, themes, and storefronts for Shopify.
|
|
130
|
+
- [ToDesktop CLI](https://www.todesktop.com/electron) - An all-in-one platform for building Electron apps.
|
|
130
131
|
|
|
131
132
|
## Contents
|
|
132
133
|
|
|
@@ -167,7 +168,7 @@ Alternatively, create a TypeScript project:
|
|
|
167
168
|
npx create-ink-app --typescript my-ink-cli
|
|
168
169
|
```
|
|
169
170
|
|
|
170
|
-
<details><summary>Manual setup</summary>
|
|
171
|
+
<details><summary>Manual JavaScript setup</summary>
|
|
171
172
|
<p>
|
|
172
173
|
Ink requires the same Babel setup as you would do for regular React-based apps in the browser.
|
|
173
174
|
|
|
@@ -180,17 +181,7 @@ npm install --save-dev @babel/preset-react
|
|
|
180
181
|
|
|
181
182
|
```json
|
|
182
183
|
{
|
|
183
|
-
"presets": [
|
|
184
|
-
"@babel/preset-react",
|
|
185
|
-
[
|
|
186
|
-
"@babel/preset-env",
|
|
187
|
-
{
|
|
188
|
-
"targets": {
|
|
189
|
-
"node": true
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
]
|
|
193
|
-
]
|
|
184
|
+
"presets": ["@babel/preset-react"]
|
|
194
185
|
}
|
|
195
186
|
```
|
|
196
187
|
|
|
@@ -580,6 +571,58 @@ Margin on all sides. Equivalent to setting `marginTop`, `marginBottom`, `marginL
|
|
|
580
571
|
<Box margin={2}>Top, bottom, left and right</Box>
|
|
581
572
|
```
|
|
582
573
|
|
|
574
|
+
#### Gap
|
|
575
|
+
|
|
576
|
+
#### gap
|
|
577
|
+
|
|
578
|
+
Type: `number`\
|
|
579
|
+
Default: `0`
|
|
580
|
+
|
|
581
|
+
Size of the gap between an element's columns and rows. Shorthand for `columnGap` and `rowGap`.
|
|
582
|
+
|
|
583
|
+
```jsx
|
|
584
|
+
<Box gap={1} width={3} flexWrap="wrap">
|
|
585
|
+
<Text>A</Text>
|
|
586
|
+
<Text>B</Text>
|
|
587
|
+
<Text>C</Text>
|
|
588
|
+
</Box>
|
|
589
|
+
// A B
|
|
590
|
+
//
|
|
591
|
+
// C
|
|
592
|
+
```
|
|
593
|
+
|
|
594
|
+
#### columnGap
|
|
595
|
+
|
|
596
|
+
Type: `number`\
|
|
597
|
+
Default: `0`
|
|
598
|
+
|
|
599
|
+
Size of the gap between an element's columns.
|
|
600
|
+
|
|
601
|
+
```jsx
|
|
602
|
+
<Box columnGap={1}>
|
|
603
|
+
<Text>A</Text>
|
|
604
|
+
<Text>B</Text>
|
|
605
|
+
</Box>
|
|
606
|
+
// A B
|
|
607
|
+
```
|
|
608
|
+
|
|
609
|
+
#### rowGap
|
|
610
|
+
|
|
611
|
+
Type: `number`\
|
|
612
|
+
Default: `0`
|
|
613
|
+
|
|
614
|
+
Size of the gap between element's rows.
|
|
615
|
+
|
|
616
|
+
```jsx
|
|
617
|
+
<Box flexDirection="column" rowGap={1}>
|
|
618
|
+
<Text>A</Text>
|
|
619
|
+
<Text>B</Text>
|
|
620
|
+
</Box>
|
|
621
|
+
// A
|
|
622
|
+
//
|
|
623
|
+
// B
|
|
624
|
+
```
|
|
625
|
+
|
|
583
626
|
#### Flex
|
|
584
627
|
|
|
585
628
|
##### flexGrow
|
|
@@ -681,6 +724,32 @@ See [flex-direction](https://css-tricks.com/almanac/properties/f/flex-direction/
|
|
|
681
724
|
// X
|
|
682
725
|
```
|
|
683
726
|
|
|
727
|
+
##### flexWrap
|
|
728
|
+
|
|
729
|
+
Type: `string`\
|
|
730
|
+
Allowed values: `nowrap` `wrap` `wrap-reverse`
|
|
731
|
+
|
|
732
|
+
See [flex-wrap](https://css-tricks.com/almanac/properties/f/flex-wrap/).
|
|
733
|
+
|
|
734
|
+
```jsx
|
|
735
|
+
<Box width={2} flexWrap="wrap">
|
|
736
|
+
<Text>A</Text>
|
|
737
|
+
<Text>BC</Text>
|
|
738
|
+
</Box>
|
|
739
|
+
// A
|
|
740
|
+
// B C
|
|
741
|
+
```
|
|
742
|
+
|
|
743
|
+
```jsx
|
|
744
|
+
<Box flexDirection="column" height={2} flexWrap="wrap">
|
|
745
|
+
<Text>A</Text>
|
|
746
|
+
<Text>B</Text>
|
|
747
|
+
<Text>C</Text>
|
|
748
|
+
</Box>
|
|
749
|
+
// A C
|
|
750
|
+
// B
|
|
751
|
+
```
|
|
752
|
+
|
|
684
753
|
##### alignItems
|
|
685
754
|
|
|
686
755
|
Type: `string`\
|
|
@@ -821,12 +890,36 @@ Default: `flex`
|
|
|
821
890
|
|
|
822
891
|
Set this property to `none` to hide the element.
|
|
823
892
|
|
|
893
|
+
##### overflowX
|
|
894
|
+
|
|
895
|
+
Type: `string`\
|
|
896
|
+
Allowed values: `visible` `hidden`\
|
|
897
|
+
Default: `visible`
|
|
898
|
+
|
|
899
|
+
Behavior for an element's overflow in horizontal direction.
|
|
900
|
+
|
|
901
|
+
##### overflowY
|
|
902
|
+
|
|
903
|
+
Type: `string`\
|
|
904
|
+
Allowed values: `visible` `hidden`\
|
|
905
|
+
Default: `visible`
|
|
906
|
+
|
|
907
|
+
Behavior for an element's overflow in vertical direction.
|
|
908
|
+
|
|
909
|
+
##### overflow
|
|
910
|
+
|
|
911
|
+
Type: `string`\
|
|
912
|
+
Allowed values: `visible` `hidden`\
|
|
913
|
+
Default: `visible`
|
|
914
|
+
|
|
915
|
+
Shortcut for setting `overflowX` and `overflowY` at the same time.
|
|
916
|
+
|
|
824
917
|
#### Borders
|
|
825
918
|
|
|
826
919
|
##### borderStyle
|
|
827
920
|
|
|
828
921
|
Type: `string`\
|
|
829
|
-
Allowed values: `single` `double` `round` `bold` `singleDouble` `doubleSingle` `classic`
|
|
922
|
+
Allowed values: `single` `double` `round` `bold` `singleDouble` `doubleSingle` `classic` | `BoxStyle`
|
|
830
923
|
|
|
831
924
|
Add a border with a specified style.
|
|
832
925
|
If `borderStyle` is `undefined` (which it is by default), no border will be added.
|
|
@@ -870,14 +963,33 @@ Ink uses border styles from [`cli-boxes`](https://github.com/sindresorhus/cli-bo
|
|
|
870
963
|
|
|
871
964
|
<img src="media/box-borderStyle.jpg" width="521">
|
|
872
965
|
|
|
873
|
-
|
|
966
|
+
Alternatively, pass a custom border style like so:
|
|
967
|
+
|
|
968
|
+
```jsx
|
|
969
|
+
<Box
|
|
970
|
+
borderStyle={{
|
|
971
|
+
topLeft: '↘',
|
|
972
|
+
top: '↓',
|
|
973
|
+
topRight: '↙',
|
|
974
|
+
left: '→',
|
|
975
|
+
bottomLeft: '↗',
|
|
976
|
+
bottom: '↑',
|
|
977
|
+
bottomRight: '↖',
|
|
978
|
+
right: '←'
|
|
979
|
+
}}
|
|
980
|
+
>
|
|
981
|
+
<Text>Custom</Text>
|
|
982
|
+
</Box>
|
|
983
|
+
```
|
|
984
|
+
|
|
985
|
+
See example in [examples/borders](examples/borders/borders.tsx).
|
|
874
986
|
|
|
875
987
|
##### borderColor
|
|
876
988
|
|
|
877
989
|
Type: `string`
|
|
878
990
|
|
|
879
991
|
Change border color.
|
|
880
|
-
|
|
992
|
+
Shorthand for setting `borderTopColor`, `borderRightColor`, `borderBottomColor` and `borderLeftColor`.
|
|
881
993
|
|
|
882
994
|
```jsx
|
|
883
995
|
<Box borderStyle="round" borderColor="green">
|
|
@@ -887,6 +999,99 @@ Accepts the same values as [`color`](#color) in `<Text>` component.
|
|
|
887
999
|
|
|
888
1000
|
<img src="media/box-borderColor.jpg" width="228">
|
|
889
1001
|
|
|
1002
|
+
##### borderTopColor
|
|
1003
|
+
|
|
1004
|
+
Type: `string`
|
|
1005
|
+
|
|
1006
|
+
Change top border color.
|
|
1007
|
+
Accepts the same values as [`color`](#color) in `<Text>` component.
|
|
1008
|
+
|
|
1009
|
+
```jsx
|
|
1010
|
+
<Box borderStyle="round" borderTopColor="green">
|
|
1011
|
+
<Text>Hello world</Text>
|
|
1012
|
+
</Box>
|
|
1013
|
+
```
|
|
1014
|
+
|
|
1015
|
+
##### borderRightColor
|
|
1016
|
+
|
|
1017
|
+
Type: `string`
|
|
1018
|
+
|
|
1019
|
+
Change right border color.
|
|
1020
|
+
Accepts the same values as [`color`](#color) in `<Text>` component.
|
|
1021
|
+
|
|
1022
|
+
```jsx
|
|
1023
|
+
<Box borderStyle="round" borderRightColor="green">
|
|
1024
|
+
<Text>Hello world</Text>
|
|
1025
|
+
</Box>
|
|
1026
|
+
```
|
|
1027
|
+
|
|
1028
|
+
##### borderRightColor
|
|
1029
|
+
|
|
1030
|
+
Type: `string`
|
|
1031
|
+
|
|
1032
|
+
Change right border color.
|
|
1033
|
+
Accepts the same values as [`color`](#color) in `<Text>` component.
|
|
1034
|
+
|
|
1035
|
+
```jsx
|
|
1036
|
+
<Box borderStyle="round" borderRightColor="green">
|
|
1037
|
+
<Text>Hello world</Text>
|
|
1038
|
+
</Box>
|
|
1039
|
+
```
|
|
1040
|
+
|
|
1041
|
+
##### borderBottomColor
|
|
1042
|
+
|
|
1043
|
+
Type: `string`
|
|
1044
|
+
|
|
1045
|
+
Change bottom border color.
|
|
1046
|
+
Accepts the same values as [`color`](#color) in `<Text>` component.
|
|
1047
|
+
|
|
1048
|
+
```jsx
|
|
1049
|
+
<Box borderStyle="round" borderBottomColor="green">
|
|
1050
|
+
<Text>Hello world</Text>
|
|
1051
|
+
</Box>
|
|
1052
|
+
```
|
|
1053
|
+
|
|
1054
|
+
##### borderLeftColor
|
|
1055
|
+
|
|
1056
|
+
Type: `string`
|
|
1057
|
+
|
|
1058
|
+
Change left border color.
|
|
1059
|
+
Accepts the same values as [`color`](#color) in `<Text>` component.
|
|
1060
|
+
|
|
1061
|
+
```jsx
|
|
1062
|
+
<Box borderStyle="round" borderLeftColor="green">
|
|
1063
|
+
<Text>Hello world</Text>
|
|
1064
|
+
</Box>
|
|
1065
|
+
```
|
|
1066
|
+
|
|
1067
|
+
##### borderTop
|
|
1068
|
+
|
|
1069
|
+
Type: `boolean`\
|
|
1070
|
+
Default: `true`
|
|
1071
|
+
|
|
1072
|
+
Determines whether top border is visible.
|
|
1073
|
+
|
|
1074
|
+
##### borderRight
|
|
1075
|
+
|
|
1076
|
+
Type: `boolean`\
|
|
1077
|
+
Default: `true`
|
|
1078
|
+
|
|
1079
|
+
Determines whether right border is visible.
|
|
1080
|
+
|
|
1081
|
+
##### borderBottom
|
|
1082
|
+
|
|
1083
|
+
Type: `boolean`\
|
|
1084
|
+
Default: `true`
|
|
1085
|
+
|
|
1086
|
+
Determines whether bottom border is visible.
|
|
1087
|
+
|
|
1088
|
+
##### borderLeft
|
|
1089
|
+
|
|
1090
|
+
Type: `boolean`\
|
|
1091
|
+
Default: `true`
|
|
1092
|
+
|
|
1093
|
+
Determines whether left border is visible.
|
|
1094
|
+
|
|
890
1095
|
### `<Newline>`
|
|
891
1096
|
|
|
892
1097
|
Adds one or more newline (`\n`) characters.
|
|
@@ -1030,7 +1235,7 @@ render(<Example />);
|
|
|
1030
1235
|
that were previously rendered. This means that when you add new items to `items`
|
|
1031
1236
|
array, changes you make to previous items will not trigger a rerender.
|
|
1032
1237
|
|
|
1033
|
-
See [examples/static](examples/static/static.
|
|
1238
|
+
See [examples/static](examples/static/static.tsx) for an example usage of `<Static>` component.
|
|
1034
1239
|
|
|
1035
1240
|
#### items
|
|
1036
1241
|
|
|
@@ -1120,7 +1325,7 @@ This hook is used for handling user input.
|
|
|
1120
1325
|
It's a more convenient alternative to using `useStdin` and listening to `data` events.
|
|
1121
1326
|
The callback you pass to `useInput` is called for each character when user enters any input.
|
|
1122
1327
|
However, if user pastes text and it's more than one character, the callback will be called only once and the whole string will be passed as `input`.
|
|
1123
|
-
You can find a full example of using `useInput` at [examples/use-input](examples/use-input/use-input.
|
|
1328
|
+
You can find a full example of using `useInput` at [examples/use-input](examples/use-input/use-input.tsx).
|
|
1124
1329
|
|
|
1125
1330
|
```jsx
|
|
1126
1331
|
import {useInput} from 'ink';
|
|
@@ -1403,7 +1608,7 @@ const Example = () => {
|
|
|
1403
1608
|
};
|
|
1404
1609
|
```
|
|
1405
1610
|
|
|
1406
|
-
See additional usage example in [examples/use-stdout](examples/use-stdout/use-stdout.
|
|
1611
|
+
See additional usage example in [examples/use-stdout](examples/use-stdout/use-stdout.tsx).
|
|
1407
1612
|
|
|
1408
1613
|
### useStderr()
|
|
1409
1614
|
|
|
@@ -1496,7 +1701,7 @@ const Example = () => {
|
|
|
1496
1701
|
render(<Example />);
|
|
1497
1702
|
```
|
|
1498
1703
|
|
|
1499
|
-
See example in [examples/use-focus](examples/use-focus/use-focus.
|
|
1704
|
+
See example in [examples/use-focus](examples/use-focus/use-focus.tsx) and [examples/use-focus-with-id](examples/use-focus-with-id/use-focus-with-id.tsx).
|
|
1500
1705
|
|
|
1501
1706
|
### useFocusManager()
|
|
1502
1707
|
|
|
@@ -1833,17 +2038,17 @@ npm run example examples/[example name]
|
|
|
1833
2038
|
# e.g. npm run example examples/borders
|
|
1834
2039
|
```
|
|
1835
2040
|
|
|
1836
|
-
- [Jest](examples/jest/jest.
|
|
1837
|
-
- [Counter](examples/counter/counter.
|
|
2041
|
+
- [Jest](examples/jest/jest.tsx) - Implementation of basic Jest UI [(live demo)](https://ink-jest-demo.vadimdemedes.repl.run/).
|
|
2042
|
+
- [Counter](examples/counter/counter.tsx) - Simple counter that increments every 100ms [(live demo)](https://ink-counter-demo.vadimdemedes.repl.run/).
|
|
1838
2043
|
- [Form with validation](https://github.com/final-form/rff-cli-example) - Manage form state using [Final Form](https://github.com/final-form/final-form#-final-form).
|
|
1839
|
-
- [Borders](examples/borders/borders.
|
|
1840
|
-
- [Suspense](examples/suspense/suspense.
|
|
1841
|
-
- [Table](examples/table/table.
|
|
1842
|
-
- [Focus management](examples/use-focus/use-focus.
|
|
1843
|
-
- [User input](examples/use-input/use-input.
|
|
1844
|
-
- [Write to stdout](examples/use-stdout/use-stdout.
|
|
1845
|
-
- [Write to stderr](examples/use-stderr/use-stderr.
|
|
1846
|
-
- [Static](examples/static/static.
|
|
2044
|
+
- [Borders](examples/borders/borders.tsx) - Add borders to `<Box>` component.
|
|
2045
|
+
- [Suspense](examples/suspense/suspense.tsx) - Use React Suspense.
|
|
2046
|
+
- [Table](examples/table/table.tsx) - Render a table with multiple columns and rows.
|
|
2047
|
+
- [Focus management](examples/use-focus/use-focus.tsx) - Use `useFocus` hook to manage focus between components.
|
|
2048
|
+
- [User input](examples/use-input/use-input.tsx) - Listen to user input.
|
|
2049
|
+
- [Write to stdout](examples/use-stdout/use-stdout.tsx) - Write to stdout bypassing main Ink output.
|
|
2050
|
+
- [Write to stderr](examples/use-stderr/use-stderr.tsx) - Write to stderr bypassing main Ink output.
|
|
2051
|
+
- [Static](examples/static/static.tsx) - Use `<Static>` to render permanent output.
|
|
1847
2052
|
- [Child process](examples/subprocess-output) - Render output from a child process.
|
|
1848
2053
|
|
|
1849
2054
|
## Maintainers
|