Skip to content

Commit 6f6911f

Browse files
committed
fix: Fixed exit behaviour
1 parent 086ee77 commit 6f6911f

2 files changed

Lines changed: 13 additions & 21 deletions

File tree

src/ScrollArea.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ export function ScrollArea({height, isStart, children}) {
4141
});
4242
const focusManager = useFocusManager();
4343
const [canScroll, setCanScroll] = useState(true);
44-
45-
focusManager.enableFocus();
46-
4744
const innerRef = React.useRef();
4845

4946
useLayoutEffect(() => {
@@ -58,6 +55,8 @@ export function ScrollArea({height, isStart, children}) {
5855
} else {
5956
setCanScroll(true);
6057
}
58+
59+
focusManager.enableFocus();
6160
}, [height, isStart, children.length]);
6261

6362
React.useEffect(() => {

src/demo/Test.tsx

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import { Box, Text, useInput, useStdout } from "ink";
22
import React, { useEffect, useLayoutEffect } from 'react';
33
import { Form } from '../Form.js';
4-
import { clearInterval } from 'node:timers';
5-
import { FullScreen } from '../FullScreen.js';
6-
7-
let counter = 0;
84

95
export function Test() {
106
const stdout = useStdout();
@@ -14,35 +10,32 @@ export function Test() {
1410

1511
useLayoutEffect(() => {
1612
stdout.write('This is ap revious message\n')
13+
stdout.write('To show that previous messages will still exist...')
14+
stdout.write('The prompt will open shortly')
1715

1816
setTimeout(() => {
1917
process.stdout.write('\x1b[?1049h');
2018
process.stdout.write('\x1b[?1000h');
2119
setShowPrompt(true)
22-
}, 3000);
20+
}, 1000);
2321

22+
process.on('beforeExit', () => {
23+
process.stdout.write('\x1b[?1049l');
24+
process.stdout.write('\x1b[?1000l');
25+
});
2426
}, []);
2527

26-
useEffect(() => {
27-
const id = setInterval(() => {
28-
if (isSubmitted) {
29-
stdout.write('hi\n')
30-
counter++;
31-
}
32-
33-
if (counter >= 1) {
34-
clearInterval(id)
35-
}
36-
}, 1000)
37-
}, [isSubmitted]);
38-
3928
return (<Box flexDirection='column'>
4029
{!isSubmitted && showPrompt && (
4130
<Form
4231
onSubmit={value => {
4332
process.stdout.write('\x1b[?1049l');
4433
process.stdout.write('\x1b[?1000l');
4534
setIsSubmitted(true)
35+
36+
setTimeout(() => {
37+
stdout.write('Hihi\n');
38+
}, 1000)
4639
}}
4740
form={{
4841
title: "Form title",

0 commit comments

Comments
 (0)