X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2Ftterminal%2FECMA48.java;h=5a30d37454af62d5f4c519e31e47924b2dd31593;hb=1d99a38f2b0f1f6674a21ba8b17be28bc7a34035;hp=69a9da12191dc65fad624177c93935488489c9a6;hpb=4bc195601c6c8d59a3937645ed7bda68ec415348;p=nikiroo-utils.git diff --git a/src/jexer/tterminal/ECMA48.java b/src/jexer/tterminal/ECMA48.java index 69a9da1..5a30d37 100644 --- a/src/jexer/tterminal/ECMA48.java +++ b/src/jexer/tterminal/ECMA48.java @@ -204,7 +204,7 @@ public class ECMA48 implements Runnable { * * @param str string to send */ - private void writeRemote(final String str) { + public void writeRemote(final String str) { if (stopReaderThread) { // Reader hit EOF, bail out now. close(); @@ -221,6 +221,7 @@ public class ECMA48 implements Runnable { return; } try { + outputStream.flush(); for (int i = 0; i < str.length(); i++) { outputStream.write(str.charAt(i)); } @@ -235,6 +236,7 @@ public class ECMA48 implements Runnable { return; } try { + output.flush(); output.write(str); output.flush(); } catch (IOException e) { @@ -302,6 +304,21 @@ public class ECMA48 implements Runnable { } } + /** + * The enclosing listening object. + */ + private DisplayListener listener; + + /** + * Set a listening object. + * + * @param listener the object that will have displayChanged() called + * after bytes are received from the remote terminal + */ + public void setListener(final DisplayListener listener) { + this.listener = listener; + } + /** * When true, the reader thread is expected to exit. */ @@ -523,6 +540,22 @@ public class ECMA48 implements Runnable { return width; } + /** + * Set the display width. + * + * @param width the new width + */ + public final void setWidth(final int width) { + this.width = width; + rightMargin = width - 1; + if (currentState.cursorX >= width) { + currentState.cursorX = width - 1; + } + if (savedState.cursorX >= width) { + savedState.cursorX = width - 1; + } + } + /** * Physical display height. We start at 80x24, but the user can resize * us bigger/smaller. @@ -538,6 +571,33 @@ public class ECMA48 implements Runnable { return height; } + /** + * Set the display height. + * + * @param height the new height + */ + public final void setHeight(final int height) { + this.height = height; + scrollRegionBottom = height - 1; + if (scrollRegionTop >= scrollRegionBottom) { + scrollRegionTop = 0; + } + if (currentState.cursorY >= height) { + currentState.cursorY = height - 1; + } + if (savedState.cursorY >= height) { + savedState.cursorY = height - 1; + } + while (display.size() < height) { + DisplayLine line = new DisplayLine(currentState.attr); + line.setReverseColor(reverseVideo); + display.add(line); + } + while (display.size() > height) { + scrollback.add(display.remove(0)); + } + } + /** * Top margin of the scrolling region. */ @@ -6024,6 +6084,10 @@ public class ECMA48 implements Runnable { consume((char)ch); } } + // Permit my enclosing UI to know that I updated. + if (listener != null) { + listener.displayChanged(); + } } // System.err.println("end while loop"); System.err.flush(); } catch (IOException e) {