Fixed scrolling in windows so that the screen is clipped (as per the

specification)
This commit is contained in:
nathan 2016-05-29 21:42:02 +02:00
parent f48272588c
commit f67c073867
2 changed files with 13 additions and 9 deletions

View File

@ -93,6 +93,9 @@ public final class WindowsAnsiOutputStream extends AnsiOutputStream {
private volatile short savedX = (short) -1;
private volatile short savedY = (short) -1;
// reused vars
private IntByReference written = new IntByReference();
public
WindowsAnsiOutputStream(final OutputStream os, int fileHandle) throws IOException {
super(os);
@ -166,7 +169,7 @@ public final class WindowsAnsiOutputStream extends AnsiOutputStream {
protected
void processEraseScreen(final int eraseOption) throws IOException {
getConsoleInfo();
int[] written = new int[1];
switch (eraseOption) {
case ERASE_ALL:
COORD topLeft = new COORD();
@ -198,7 +201,7 @@ public final class WindowsAnsiOutputStream extends AnsiOutputStream {
protected
void processEraseLine(final int eraseOption) throws IOException {
getConsoleInfo();
int[] written = new int[1];
switch (eraseOption) {
case ERASE_ALL:
COORD currentRow = info.cursorPosition.asValue();
@ -407,18 +410,18 @@ public final class WindowsAnsiOutputStream extends AnsiOutputStream {
SMALL_RECT.ByReference scrollRect = new SMALL_RECT.ByReference();
COORD.ByValue coordDest = new COORD.ByValue();
// the content that will be scrolled
scrollRect.top = (short) (0);
scrollRect.bottom = Short.MAX_VALUE;
// the content that will be scrolled (just what is visible in the window)
scrollRect.top = (short) (info.cursorPosition.y - info.window.height());
scrollRect.bottom = (short) (info.cursorPosition.y);
scrollRect.left = (short) 0;
scrollRect.right = (short) (info.size.x - 1);
// The destination for the scroll rectangle is xxx row up/down.
coordDest.x = (short) 0;
coordDest.y = (short) (-rowsToScroll);
coordDest.y = (short) (scrollRect.top - rowsToScroll);
// fill the space with whatever color was already there with spaces
IntByReference attribs = new IntByReference();
IntByReference attribs = written;
attribs.setValue(info.attributes);
// The clipping rectangle is the same as the scrolling rectangle, so we pass NULL

View File

@ -113,13 +113,13 @@ public class Kernel32 {
* https://msdn.microsoft.com/en-us/library/ms682662%28VS.85%29.aspx
*/
public static native
int FillConsoleOutputAttribute(HANDLE consoleOutput, short attribute, int length, COORD.ByValue writeCoord, int[] numberOfAttrsWritten);
int FillConsoleOutputAttribute(HANDLE consoleOutput, short attribute, int length, COORD.ByValue writeCoord, IntByReference numberOfAttrsWritten);
/**
* https://msdn.microsoft.com/en-us/library/ms682663%28VS.85%29.aspx
*/
public static native
int FillConsoleOutputCharacterW(HANDLE consoleOutput, char character, int length, COORD.ByValue writeCoord, int[] numberOfCharsWritten);
int FillConsoleOutputCharacterW(HANDLE consoleOutput, char character, int length, COORD.ByValue writeCoord, IntByReference numberOfCharsWritten);
@ -135,6 +135,7 @@ public class Kernel32 {
public static native
int SetConsoleMode(HANDLE handle, int mode);
/**
* https://msdn.microsoft.com/en-us/library/ms684961(v=VS.85).aspx
*/