ink icon indicating copy to clipboard operation
ink copied to clipboard

Terminal scrolls if a box is rendered with full height

Open fpintos opened this issue 3 years ago • 3 comments

OS: Windows 10

When I create a box with the full size returned by useStdoutDimensions the terminal ends up scrolling and each frame that was rendered is visible by scrolling it up. If I render with one less row, then there is no scrolling and previous frames are not visible.

This also causes lots of flashing when rendered by Git Bash, very noticeable (unusable) on Windows Terminal. If I run just in the plain cmd, flashing is not an issue but you still see the scroll bar filling up.

I'm doing something like this at the top of my application, then adding a box with 100% height inside:

import { Box } from "ink";
import React from "react";
import useStdoutDimensions from "ink-use-stdout-dimensions";

export default function FullTerminal({
  children,
}: {
  children?: JSX.Element | JSX.Element[];
}) {
  const [columns, rows] = useStdoutDimensions();
  return (
    <Box width={columns} height={rows}>
      {children}
    </Box>
  );
}

fpintos avatar May 18 '21 10:05 fpintos

Could you execute process.stdout.write('x\n'.repeat(process.stdout.rows)) in a separate script (without Ink) and see how your terminal handles it? I suspect it's the last newline (\n) at the end that could cause this.

vadimdemedes avatar Jul 19 '21 14:07 vadimdemedes

Hi @vadimdemedes,

I noticed the following difference between running the suggested script in Windows Git Bash and Ubuntu (WSL):

  • I've put the script in a file and invoked as node test.js
  • Windows Git Bash printed the lines and ended with an empty line, before returning to the prompt (node version v14.17.3). Same results in conhost and in Windows Terminal.
  • In WSL bash printed the lines and NO empty line before the prompt (node version v14.17.5)
  • CMD also printed the extra empty line (both in conhost and windows terminal)
  • Powershell did NOT print the extra empty line.

The repeat call was not needed to repro; a script with just process.stdout.write("x"); didn't have a new line in all cases but write("x\n") gave the same repro.

Similarly, by invoking a test.sh file with just echo "x" as content I get the extra new line in Git Bash on Windows but not in WSL.

fpintos avatar Aug 30 '21 19:08 fpintos

A little poking around and I noticed my PS1 had new lines on it. After removing, the extra new line is gone. Nevertheless, that has no effect while running the application, as far as I can tell.

fpintos avatar Aug 30 '21 19:08 fpintos