diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2019-03-29 14:22:23 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2019-03-29 14:22:23 (GMT) |
commit | 8ac5057a32d3241ca2ca4a353b1cb650c09e3eb0 (patch) | |
tree | 19957440700ce8c1a49124767a865303bd931eae /unix | |
parent | 5624496889a065617fbded91ff512c4066b51f64 (diff) | |
download | tcl-8ac5057a32d3241ca2ca4a353b1cb650c09e3eb0.zip tcl-8ac5057a32d3241ca2ca4a353b1cb650c09e3eb0.tar.gz tcl-8ac5057a32d3241ca2ca4a353b1cb650c09e3eb0.tar.bz2 |
Support -winsize read-only option
Diffstat (limited to 'unix')
-rw-r--r-- | unix/tclUnixChan.c | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/unix/tclUnixChan.c b/unix/tclUnixChan.c index 152de88..ffeb0a7 100644 --- a/unix/tclUnixChan.c +++ b/unix/tclUnixChan.c @@ -1119,11 +1119,37 @@ TtyGetOptionProc( } #endif /* TIOCMGET */ +#if defined(TIOCGWINSZ) + /* + * Get option -winsize + * Option is readonly and returned by [fconfigure chan -winsize] but not + * returned by [fconfigure chan] without explicit option name. + */ + + if ((len > 1) && (strncmp(optionName, "-winsize", len) == 0)) { + struct winsize ws; + + valid = 1; + if (ioctl(fsPtr->fileState.fd, TIOCGWINSZ, &ws) < 0) { + if (interp != NULL) { + Tcl_SetObjResult(interp, Tcl_ObjPrintf( + "couldn't read terminal size: %s", + Tcl_PosixError(interp))); + } + return TCL_ERROR; + } + sprintf(buf, "%d", ws.ws_col); + Tcl_DStringAppendElement(dsPtr, buf); + sprintf(buf, "%d", ws.ws_row); + Tcl_DStringAppendElement(dsPtr, buf); + } +#endif /* TIOCGWINSZ */ + if (valid) { return TCL_OK; } return Tcl_BadChannelOption(interp, optionName, - "closemode inputmode mode queue ttystatus xchar"); + "closemode inputmode mode queue ttystatus winsize xchar"); } static const struct {int baud; speed_t speed;} speeds[] = { |