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 savedX = (short) -1;
private volatile short savedY = (short) -1; private volatile short savedY = (short) -1;
// reused vars
private IntByReference written = new IntByReference();
public public
WindowsAnsiOutputStream(final OutputStream os, int fileHandle) throws IOException { WindowsAnsiOutputStream(final OutputStream os, int fileHandle) throws IOException {
super(os); super(os);
@ -166,7 +169,7 @@ public final class WindowsAnsiOutputStream extends AnsiOutputStream {
protected protected
void processEraseScreen(final int eraseOption) throws IOException { void processEraseScreen(final int eraseOption) throws IOException {
getConsoleInfo(); getConsoleInfo();
int[] written = new int[1];
switch (eraseOption) { switch (eraseOption) {
case ERASE_ALL: case ERASE_ALL:
COORD topLeft = new COORD(); COORD topLeft = new COORD();
@ -198,7 +201,7 @@ public final class WindowsAnsiOutputStream extends AnsiOutputStream {
protected protected
void processEraseLine(final int eraseOption) throws IOException { void processEraseLine(final int eraseOption) throws IOException {
getConsoleInfo(); getConsoleInfo();
int[] written = new int[1];
switch (eraseOption) { switch (eraseOption) {
case ERASE_ALL: case ERASE_ALL:
COORD currentRow = info.cursorPosition.asValue(); COORD currentRow = info.cursorPosition.asValue();
@ -407,18 +410,18 @@ public final class WindowsAnsiOutputStream extends AnsiOutputStream {
SMALL_RECT.ByReference scrollRect = new SMALL_RECT.ByReference(); SMALL_RECT.ByReference scrollRect = new SMALL_RECT.ByReference();
COORD.ByValue coordDest = new COORD.ByValue(); COORD.ByValue coordDest = new COORD.ByValue();
// the content that will be scrolled // the content that will be scrolled (just what is visible in the window)
scrollRect.top = (short) (0); scrollRect.top = (short) (info.cursorPosition.y - info.window.height());
scrollRect.bottom = Short.MAX_VALUE; scrollRect.bottom = (short) (info.cursorPosition.y);
scrollRect.left = (short) 0; scrollRect.left = (short) 0;
scrollRect.right = (short) (info.size.x - 1); scrollRect.right = (short) (info.size.x - 1);
// The destination for the scroll rectangle is xxx row up/down. // The destination for the scroll rectangle is xxx row up/down.
coordDest.x = (short) 0; 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 // fill the space with whatever color was already there with spaces
IntByReference attribs = new IntByReference(); IntByReference attribs = written;
attribs.setValue(info.attributes); attribs.setValue(info.attributes);
// The clipping rectangle is the same as the scrolling rectangle, so we pass NULL // 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 * https://msdn.microsoft.com/en-us/library/ms682662%28VS.85%29.aspx
*/ */
public static native 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 * https://msdn.microsoft.com/en-us/library/ms682663%28VS.85%29.aspx
*/ */
public static native 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 public static native
int SetConsoleMode(HANDLE handle, int mode); int SetConsoleMode(HANDLE handle, int mode);
/** /**
* https://msdn.microsoft.com/en-us/library/ms684961(v=VS.85).aspx * https://msdn.microsoft.com/en-us/library/ms684961(v=VS.85).aspx
*/ */