X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2Ftterminal%2FECMA48.java;h=caa295ad47776ce242557359407ab18b2d7dacf5;hb=be9987235887cb73637b91ab6921158ecaef9d95;hp=5a30d37454af62d5f4c519e31e47924b2dd31593;hpb=1d99a38f2b0f1f6674a21ba8b17be28bc7a34035;p=fanfix.git diff --git a/src/jexer/tterminal/ECMA48.java b/src/jexer/tterminal/ECMA48.java index 5a30d37..caa295a 100644 --- a/src/jexer/tterminal/ECMA48.java +++ b/src/jexer/tterminal/ECMA48.java @@ -307,17 +307,7 @@ 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; - } + private DisplayListener displayListener; /** * When true, the reader thread is expected to exit. @@ -577,8 +567,12 @@ public class ECMA48 implements Runnable { * @param height the new height */ public final void setHeight(final int height) { + int delta = height - this.height; this.height = height; - scrollRegionBottom = height - 1; + scrollRegionBottom += delta; + if (scrollRegionBottom < 0) { + scrollRegionBottom = height; + } if (scrollRegionTop >= scrollRegionBottom) { scrollRegionTop = 0; } @@ -906,6 +900,11 @@ public class ECMA48 implements Runnable { arrowKeyMode = ArrowKeyMode.ANSI; keypadMode = KeypadMode.Numeric; wrapLineFlag = false; + if (displayListener != null) { + width = displayListener.getDisplayWidth(); + height = displayListener.getDisplayHeight(); + rightMargin = width - 1; + } // Flags shiftOut = false; @@ -944,11 +943,14 @@ public class ECMA48 implements Runnable { * @param outputStream an OutputStream connected to the remote user. For * type == XTERM, outputStream is converted to a Writer with UTF-8 * encoding. + * @param displayListener a callback to the outer display, or null for + * default VT100 behavior * @throws UnsupportedEncodingException if an exception is thrown when * creating the InputStreamReader */ public ECMA48(final DeviceType type, final InputStream inputStream, - final OutputStream outputStream) throws UnsupportedEncodingException { + final OutputStream outputStream, final DisplayListener displayListener) + throws UnsupportedEncodingException { assert (inputStream != null); assert (outputStream != null); @@ -973,6 +975,7 @@ public class ECMA48 implements Runnable { this.output = null; this.outputStream = new BufferedOutputStream(outputStream); } + this.displayListener = displayListener; reset(); for (int i = 0; i < height; i++) { @@ -1382,7 +1385,7 @@ public class ECMA48 implements Runnable { return sb.toString(); } - if (keypress.equals(kbBackspace)) { + if (keypress.equals(kbBackspaceDel)) { switch (type) { case VT100: return "\010"; @@ -2503,9 +2506,18 @@ public class ECMA48 implements Runnable { } else { // 80 columns columns132 = false; - rightMargin = 79; + if ((displayListener != null) + && (type == DeviceType.XTERM) + ) { + // For xterms, reset to the actual width, not 80 + // columns. + width = displayListener.getDisplayWidth(); + rightMargin = width - 1; + } else { + rightMargin = 79; + width = rightMargin + 1; + } } - width = rightMargin + 1; // Entire screen is cleared, and scrolling region is // reset eraseScreen(0, 0, height - 1, width - 1, false); @@ -6071,22 +6083,22 @@ public class ECMA48 implements Runnable { // This is EOF done = true; } else { - for (int i = 0; i < rc; i++) { - int ch = 0; - if (utf8) { - ch = readBufferUTF8[i]; - } else { - ch = readBuffer[i]; - } + // Don't step on UI events + synchronized (this) { + for (int i = 0; i < rc; i++) { + int ch = 0; + if (utf8) { + ch = readBufferUTF8[i]; + } else { + ch = readBuffer[i]; + } - synchronized (this) { - // Don't step on UI events consume((char)ch); } } // Permit my enclosing UI to know that I updated. - if (listener != null) { - listener.displayChanged(); + if (displayListener != null) { + displayListener.displayChanged(); } } // System.err.println("end while loop"); System.err.flush(); @@ -6114,6 +6126,11 @@ public class ECMA48 implements Runnable { // SQUASH } + // Permit my enclosing UI to know that I updated. + if (displayListener != null) { + displayListener.displayChanged(); + } + // System.err.println("*** run() exiting..."); System.err.flush(); }