Repository: terminal
Issue: Rewriting last console output line dynamically breaks when resizing window
Labels: Area-Output,Issue-Bug,Product-Terminal

### Windows Terminal version (or Windows build number)

Windows Terminal Preview Version: 1.9.1523.0

### Other Software

- DISM.exe

- Example code that outputs to the console:
```
public class ClearConsoleOutput {
    public static void main(String[] args) throws Exception {
        // text to output to the console
        String text = "Hello World ";
        for(int i=0; i<10000; i++) {
            // prints String = "[text][i]" and places the cursor on the line below  String
            System.out.println(text + i);
            // Pause execution of the code below so that the text is visible for 10ms
            Thread.sleep(10);
            // [count] = [lines_printed_to_console] + [new_lines_created_after_output] - 1
            int count = 1; 
            // Erase only the lines printed to the console
            System.out.print(String.format("\033[%dA",count)); // Move up [count] lines
            System.out.print("\033[2K"); // Erase line content
            // OR Erase all content printed to the console
            //System.out.print(String.format("\033[2J")); // Erase all content
        }
    }
}
```

### Steps to reproduce

 > Disclaimer: if you run DISM.exe do not close the console until the process finishes.
>
 > ELSE compile and run ClearConsoleOutput java class above using:
 > 
 > * `javac --release 8 ClearConsoleOutput.java`
 >  * `java ClearConsoleOutput`
 > 
 > in Windows Terminal application running an instance of PowerShell or cmd

Run DISM command or ClearConsoleOutput class above in Windows Terminal application (PowerShell or cmd) , and when text is being written to the console, resize Windows Terminal window by dragging from one of the edges. Pressing `Ctrl + Scroll_Wheel_Up/Down` or `Ctrl + '+'/'-'` produces a similar result.

*The terminal needs to be resized such that while text is printed, the window height is smaller than the content height.* The pictures below show the result after the window has been resized to a normal viewing mode.

### Expected Behavior

#### For DISM.exe

The "`[====  {x}%  ====]`" progress bar should appear only once, as last line in the terminal, being updated as needed by the process it is attached to.

#### For ClearConsoleOutput class

The string "`Hello World {x}`" should be visible as a single line of text when being updated once every 10 milliseconds.

### Actual Behavior

#### In both cases
The line containing the updating text should appear only once and display exactly the information it needs to provide, even if it I decide in the exact moment the command/program is running to resize the window dimensions or increase/decrease the font size. Below are the results of running DISM.exe and ClearConsoleOutput class after the window was returned to its regular size.

![image](https://user-images.githubusercontent.com/33447471/122635009-10571800-d0ea-11eb-9e87-6a9a9e4d2a2e.png)

![image](https://user-images.githubusercontent.com/33447471/122635651-e1db3c00-d0ed-11eb-8a9b-73d0914a8268.png)

#### Conclusion:

Depending on the way the window is being resized, the output can appear: concatenated, incomplete, on separate lines, multiple times on the same line, even in the wrong order.
As seen in the updated version below, which includes a timestamp for each statement printed, the expected  output is one continuously updating line counting from 0 to 9999, but the actual output is unreadable.

  #### Desired behavior:
 
![image](https://user-images.githubusercontent.com/33447471/122683550-96698080-d208-11eb-9336-22790e259e0e.png)