Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output terminal isn't cleared when second to last frame is taller than terminal #585

Open
matteodepalo opened this issue May 3, 2023 · 2 comments · May be fixed by #586
Open

Output terminal isn't cleared when second to last frame is taller than terminal #585

matteodepalo opened this issue May 3, 2023 · 2 comments · May be fixed by #586
Labels

Comments

@matteodepalo
Copy link
Contributor

matteodepalo commented May 3, 2023

Hi,
As per description, I noticed that the terminal is correctly cleared if the last frame output is taller than the terminal window, however, if the last frame is shorter, the second to last frame isn't cleared. Here's a video to demonstrate this:

03-50-xck1w-29hr6.mp4

I would expect ink to not show the list after pressing enter. Is this expected behavior?

For now I've littered my code with things like this, but I would expect Ink to handle such scenarios.

if (stdout && wrapperHeight >= stdout.rows - 1) {
  stdout.write(ansiEscapes.clearTerminal)
}

setSomething(false)

Where wrapperHeight is the height of the Box containing everything.

Code to reproduce (make your terminal window height less than 20 lines):

import React, { useState } from 'react';
import { render, Text, Box, useInput } from 'ink';

function ClearTerminalBug() {
  const lines = [];

  for (let i = 1; i <= 20; i++) {
    lines.push(`line ${i}`);
  }

  const [done, setDone] = useState(false)

  useInput((_input, key) => {
    if (key.return) {
      setDone(true)
    }
  });

  return done ? <Text>done</Text> : <Box flexDirection="column">
    {lines.map((line, index) => (
      <Text key={index}>{line}</Text>
    ))}
  </Box>
}

render(
  <ClearTerminalBug />
)

Reproduction repo https://github.com/matteodepalo/clear-terminal

@matteodepalo matteodepalo changed the title Output terminal isn't cleared on exit when second to last frame is taller than terminal Output terminal isn't cleared when second to last frame is taller than terminal May 3, 2023
@matteodepalo
Copy link
Contributor Author

After creating this issue I noticed that this doesn't happen just on exit, it happens even without it. I've updated the issue.

@vadimdemedes
Copy link
Owner

Thanks for a detailed bug report! Submitted a fix over here → #586.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants