From 87f3afcdd0b7a4d3efbbff5ff68605e573f58578 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Sun, 17 Jun 2007 18:53:59 +0000 Subject: [PATCH] copy some methods from KPty - they are used only here, so they will be deleted from kdelibs. svn path=/trunk/KDE/kdebase/apps/konsole/; revision=676799 --- src/Emulation.h | 2 -- src/Pty.cpp | 67 ++++++++++++++++++++++++++++++++++++++++--------- src/Pty.h | 8 +++--- src/Session.cpp | 2 +- 4 files changed, 60 insertions(+), 19 deletions(-) diff --git a/src/Emulation.h b/src/Emulation.h index 5daf40e5f..773c50adf 100644 --- a/src/Emulation.h +++ b/src/Emulation.h @@ -267,8 +267,6 @@ signals: * Requests that the pty used by the terminal process * be set to UTF 8 mode. * - * See KPty::setUtf8Mode() - * * TODO: More documentation */ void useUtf8Request(bool); diff --git a/src/Pty.cpp b/src/Pty.cpp index b7c4cb9e1..bacb73886 100644 --- a/src/Pty.cpp +++ b/src/Pty.cpp @@ -46,32 +46,57 @@ void Pty::donePty() void Pty::setWindowSize(int lines, int cols) { - pty()->setWinSize(lines, cols); + wsX = cols; + wsY = lines; + if (pty()->masterFd() >= 0) + pty()->setWinSize(lines, cols); } void Pty::setXonXoff(bool on) { - pty()->setXonXoff(on); + xonXoff = on; + if (pty()->masterFd() >= 0) + { + struct ::termios ttmode; + pty()->tcGetAttr(&ttmode); + if (!on) + ttmode.c_iflag &= ~(IXOFF | IXON); + else + ttmode.c_iflag |= (IXOFF | IXON); + if (!pty()->tcSetAttr(&ttmode)) + qWarning("Unable to set terminal attributes."); + } } void Pty::setUtf8Mode(bool on) { - pty()->setUtf8Mode(on); +#ifdef IUTF8 // XXX not a reasonable place to check it. + utf8 = on; + if (pty()->masterFd() >= 0) + { + struct ::termios ttmode; + pty()->tcGetAttr(&ttmode); + if (!on) + ttmode.c_iflag &= ~IUTF8; + else + ttmode.c_iflag |= IUTF8; + if (!pty()->tcSetAttr(&ttmode)) + qWarning("Unable to set terminal attributes."); + } +#endif } void Pty::setErase(char erase) { - struct termios tios; - int fd = pty()->slaveFd(); - - if(tcgetattr(fd, &tios)) + this->erase = erase; + if (pty()->masterFd() >= 0) { - qWarning("Unable to get terminal attributes."); - return; + struct ::termios ttmode; + pty()->tcGetAttr(&ttmode); + ttmode.c_cc[VERASE] = erase; + if (!pty()->tcSetAttr(&ttmode)) + qWarning("Unable to set terminal attributes."); } - tios.c_cc[VERASE] = erase; - if(tcsetattr(fd, TCSANOW, &tios)) - qWarning("Unable to set terminal attributes."); } int Pty::start(const QString& program, @@ -101,6 +126,24 @@ int Pty::start(const QString& program, setUsePty(All, addToUtmp); + pty()->open(); + struct ::termios ttmode; + pty()->tcGetAttr(&ttmode); + if (!xonXoff) + ttmode.c_iflag &= ~(IXOFF | IXON); + else + ttmode.c_iflag |= (IXOFF | IXON); +#ifdef IUTF8 // XXX not a reasonable place to check it. + if (!utf8) + ttmode.c_iflag &= ~IUTF8; + else + ttmode.c_iflag |= IUTF8; +#endif + ttmode.c_cc[VERASE] = erase; + if (!pty()->tcSetAttr(&ttmode)) + qWarning("Unable to set terminal attributes."); + pty()->setWinSize(wsY, wsX); + if ( K3Process::start(NotifyOnExit, (Communication) (Stdin | Stdout)) == false ) return -1; diff --git a/src/Pty.h b/src/Pty.h index 97680557b..9775ff236 100644 --- a/src/Pty.h +++ b/src/Pty.h @@ -98,8 +98,6 @@ Q_OBJECT /** * Enables or disables Xon/Xoff flow control. - * - * See KPty::setXonXoff() */ void setXonXoff(bool on); @@ -129,8 +127,6 @@ Q_OBJECT /** * Put the pty into UTF-8 mode on systems which support it. - * - * See KPty::setUtf8Mode() */ void setUtf8Mode(bool on); @@ -213,6 +209,10 @@ Q_OBJECT QList _pendingSendJobs; bool _bufferFull; + + int wsX, wsY; + char erase; + bool xonXoff, utf8; }; } diff --git a/src/Session.cpp b/src/Session.cpp index cdc65abfe..cf7e18aff 100644 --- a/src/Session.cpp +++ b/src/Session.cpp @@ -272,6 +272,7 @@ void Session::run() if (!_initialWorkingDir.isEmpty()) QDir::setCurrent(_initialWorkingDir); _shellProcess->setXonXoff(_flowControl); + _shellProcess->setErase(_emulation->getErase()); int result = _shellProcess->start(QFile::encodeName(_program), arguments, @@ -287,7 +288,6 @@ void Session::run() return; //QTimer::singleShot(0, this, SLOT(ptyError())); } - _shellProcess->setErase(_emulation->getErase()); if (!_initialWorkingDir.isEmpty()) QDir::setCurrent(cwd_save);