X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2Ftterminal%2FECMA48.java;h=96f4e4083cc0bba8085d2df1311492214142017d;hb=aa77d68274fff56c0ceca162a687ea70795624ea;hp=03b0543ba75726f279cb9054cd2d9b488f9443c4;hpb=a2018e9964f6c58742cd1e6dd0a0c63e244a89d6;p=fanfix.git diff --git a/src/jexer/tterminal/ECMA48.java b/src/jexer/tterminal/ECMA48.java index 03b0543..96f4e40 100644 --- a/src/jexer/tterminal/ECMA48.java +++ b/src/jexer/tterminal/ECMA48.java @@ -28,6 +28,7 @@ */ package jexer.tterminal; +import java.io.BufferedOutputStream; import java.io.InputStream; import java.io.InputStreamReader; import java.io.IOException; @@ -203,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(); @@ -220,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)); } @@ -234,6 +236,7 @@ public class ECMA48 implements Runnable { return; } try { + output.flush(); output.write(str); output.flush(); } catch (IOException e) { @@ -301,6 +304,11 @@ public class ECMA48 implements Runnable { } } + /** + * The enclosing listening object. + */ + private DisplayListener displayListener; + /** * When true, the reader thread is expected to exit. */ @@ -522,6 +530,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. @@ -537,6 +561,35 @@ 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; + if (scrollRegionBottom >= 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. */ @@ -845,6 +898,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; @@ -883,11 +941,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); @@ -905,12 +966,14 @@ public class ECMA48 implements Runnable { } if (type == DeviceType.XTERM) { this.input = new InputStreamReader(this.inputStream, "UTF-8"); - this.output = new OutputStreamWriter(outputStream, "UTF-8"); + this.output = new OutputStreamWriter(new + BufferedOutputStream(outputStream), "UTF-8"); this.outputStream = null; } else { this.output = null; - this.outputStream = outputStream; + this.outputStream = new BufferedOutputStream(outputStream); } + this.displayListener = displayListener; reset(); for (int i = 0; i < height; i++) { @@ -1796,20 +1859,9 @@ public class ECMA48 implements Runnable { if (keypress.equalsWithoutModifiers(kbPgUp)) { switch (type) { case XTERM: - switch (arrowKeyMode) { - case ANSI: - return xtermBuildKeySequence("\033[", '5', '~', - keypress.isCtrl(), keypress.isAlt(), - keypress.isShift()); - case VT52: - return xtermBuildKeySequence("\033", '5', '~', - keypress.isCtrl(), keypress.isAlt(), - keypress.isShift()); - case VT100: - return xtermBuildKeySequence("\033O", '5', '~', - keypress.isCtrl(), keypress.isAlt(), - keypress.isShift()); - } + return xtermBuildKeySequence("\033[", '5', '~', + keypress.isCtrl(), keypress.isAlt(), + keypress.isShift()); default: return "\033[5~"; } @@ -1818,20 +1870,9 @@ public class ECMA48 implements Runnable { if (keypress.equalsWithoutModifiers(kbPgDn)) { switch (type) { case XTERM: - switch (arrowKeyMode) { - case ANSI: - return xtermBuildKeySequence("\033[", '6', '~', - keypress.isCtrl(), keypress.isAlt(), - keypress.isShift()); - case VT52: - return xtermBuildKeySequence("\033", '6', '~', - keypress.isCtrl(), keypress.isAlt(), - keypress.isShift()); - case VT100: - return xtermBuildKeySequence("\033O", '6', '~', - keypress.isCtrl(), keypress.isAlt(), - keypress.isShift()); - } + return xtermBuildKeySequence("\033[", '6', '~', + keypress.isCtrl(), keypress.isAlt(), + keypress.isShift()); default: return "\033[6~"; } @@ -1840,20 +1881,9 @@ public class ECMA48 implements Runnable { if (keypress.equalsWithoutModifiers(kbIns)) { switch (type) { case XTERM: - switch (arrowKeyMode) { - case ANSI: - return xtermBuildKeySequence("\033[", '2', '~', - keypress.isCtrl(), keypress.isAlt(), - keypress.isShift()); - case VT52: - return xtermBuildKeySequence("\033", '2', '~', - keypress.isCtrl(), keypress.isAlt(), - keypress.isShift()); - case VT100: - return xtermBuildKeySequence("\033O", '2', '~', - keypress.isCtrl(), keypress.isAlt(), - keypress.isShift()); - } + return xtermBuildKeySequence("\033[", '2', '~', + keypress.isCtrl(), keypress.isAlt(), + keypress.isShift()); default: return "\033[2~"; } @@ -1862,20 +1892,9 @@ public class ECMA48 implements Runnable { if (keypress.equalsWithoutModifiers(kbDel)) { switch (type) { case XTERM: - switch (arrowKeyMode) { - case ANSI: - return xtermBuildKeySequence("\033[", '3', '~', - keypress.isCtrl(), keypress.isAlt(), - keypress.isShift()); - case VT52: - return xtermBuildKeySequence("\033", '3', '~', - keypress.isCtrl(), keypress.isAlt(), - keypress.isShift()); - case VT100: - return xtermBuildKeySequence("\033O", '3', '~', - keypress.isCtrl(), keypress.isAlt(), - keypress.isShift()); - } + return xtermBuildKeySequence("\033[", '3', '~', + keypress.isCtrl(), keypress.isAlt(), + keypress.isShift()); default: // Delete sends real delete for VTxxx return "\177"; @@ -2485,9 +2504,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); @@ -6066,6 +6094,10 @@ public class ECMA48 implements Runnable { consume((char)ch); } } + // Permit my enclosing UI to know that I updated. + if (displayListener != null) { + displayListener.displayChanged(); + } } // System.err.println("end while loop"); System.err.flush(); } catch (IOException e) {