X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2Fnet%2FTelnetInputStream.java;h=3e74561a40c20e6ea9b166dea9de4d2e24e00f1c;hb=1dac6b8d395e2bf3c1b58915f8f4f481d9e46793;hp=9ae77476de7d5d39305ce356149d58494fd6e2d3;hpb=d36057dfab8def933a64be042b039d76708ac5ba;p=fanfix.git diff --git a/src/jexer/net/TelnetInputStream.java b/src/jexer/net/TelnetInputStream.java index 9ae7747..3e74561 100644 --- a/src/jexer/net/TelnetInputStream.java +++ b/src/jexer/net/TelnetInputStream.java @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (C) 2017 Kevin Lamonte + * Copyright (C) 2019 Kevin Lamonte * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -40,8 +40,7 @@ import static jexer.net.TelnetSocket.*; /** * TelnetInputStream works with TelnetSocket to perform the telnet protocol. */ -public final class TelnetInputStream extends InputStream - implements SessionInfo { +public class TelnetInputStream extends InputStream implements SessionInfo { // ------------------------------------------------------------------------ // Constants -------------------------------------------------------------- @@ -200,6 +199,15 @@ public final class TelnetInputStream extends InputStream this.language = language; } + /** + * Get the terminal type as reported by the telnet Terminal Type option. + * + * @return the terminal type + */ + public String getTerminalType() { + return master.terminalType; + } + /** * Text window width getter. * @@ -312,6 +320,7 @@ public final class TelnetInputStream extends InputStream // If we got something, return it. if (rc > 0) { + readBufferEnd += rc; readBufferStart++; return readBuffer[readBufferStart - 1]; } @@ -927,25 +936,41 @@ public final class TelnetInputStream extends InputStream if (subnegBuffer.get(i) == (byte)TELNET_IAC) { i++; } - windowWidth = subnegBuffer.get(i) * 256; + int width = subnegBuffer.get(i); + if (width < 0) { + width += 256; + } + windowWidth = width * 256; i++; if (subnegBuffer.get(i) == (byte)TELNET_IAC) { i++; } - windowWidth += subnegBuffer.get(i); + width = subnegBuffer.get(i); + windowWidth += width; + if (width < 0) { + windowWidth += 256; + } i++; if (subnegBuffer.get(i) == (byte)TELNET_IAC) { i++; } - windowHeight = subnegBuffer.get(i) * 256; + int height = subnegBuffer.get(i); + if (height < 0) { + height += 256; + } + windowHeight = height * 256; i++; if (subnegBuffer.get(i) == (byte)TELNET_IAC) { i++; } - windowHeight += subnegBuffer.get(i); + height = subnegBuffer.get(i); + windowHeight += height; + if (height < 0) { + windowHeight += 256; + } } break;