1
0
mirror of https://github.com/taigrr/arduinolibs synced 2025-01-18 04:33:12 -08:00

Fixes to telnet window size handling

This commit is contained in:
Rhys Weatherley 2016-03-11 06:16:41 +10:00
parent e9e48c0703
commit 57fb8f2fe3
2 changed files with 18 additions and 17 deletions

View File

@ -679,7 +679,7 @@ int Terminal::readKey()
break;
}
if (utf8len < sizeof(sb))
sb[utf8len++] = 0xFF;
sb[utf8len++] = ch;
break;
case STATE_SB_IAC:
@ -699,17 +699,11 @@ int Terminal::readKey()
width = ncols;
if (!height)
height = nrows;
// Filter out obviously bogus values.
if (width >= 1 && height >= 1 && width <= 10000 && height <= 10000) {
if (width != ncols || height != nrows) {
// The window size has changed; notify the caller.
ncols = width;
nrows = height;
ucode = -1;
state = STATE_INIT;
return KEY_WINSIZE;
}
if (setWindowSize(width, height)) {
// The window size has changed; notify the caller.
ucode = -1;
state = STATE_INIT;
return KEY_WINSIZE;
}
}
}
@ -781,6 +775,8 @@ size_t Terminal::writeUnicode(long code)
* \param columns The number of columns between 1 and 10000.
* \param rows The number of rows between 1 and 10000.
*
* \return Returns true if the window size has changed.
*
* This function should be used if the application has some information
* about the actual window size. For serial ports, this usually isn't
* available but telnet and ssh sessions can get the window size from
@ -794,7 +790,7 @@ size_t Terminal::writeUnicode(long code)
*
* \sa columns(), rows(), readKey()
*/
void Terminal::setWindowSize(int columns, int rows)
bool Terminal::setWindowSize(int columns, int rows)
{
// Sanity-check the range first.
if (columns < 1)
@ -805,8 +801,13 @@ void Terminal::setWindowSize(int columns, int rows)
rows = 1;
else if (rows > 10000)
rows = 10000;
ncols = columns;
nrows = rows;
if (ncols != columns || nrows != rows) {
ncols = columns;
nrows = rows;
return true;
} else {
return false;
}
}
/**

View File

@ -71,7 +71,7 @@ public:
int columns() const { return ncols; }
int rows() const { return nrows; }
void setWindowSize(int columns, int rows);
bool setWindowSize(int columns, int rows);
void clear();
void clearToEOL();
@ -135,7 +135,7 @@ private:
uint8_t state;
uint8_t utf8len;
uint8_t mod;
uint8_t sb[16];
uint8_t sb[8];
uint8_t flags;
int matchEscape(int ch);