Skip to content

Commit 1615f2b

Browse files
author
rblazek
committed
set trap to write history on exit
git-svn-id: http://svn.osgeo.org/qgis/trunk@5270 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 65e0b1c commit 1615f2b

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

src/plugins/grass/qgsgrassshell.cpp

+23-8
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ QgsGrassShell::QgsGrassShell ( QgsGrassTools *tools,
5656
QDialog(parent), QgsGrassShellBase(), mTools(tools)
5757
{
5858
mValid = false;
59+
mSkipLines = 2;
5960

6061
#ifdef WIN32
6162
QMessageBox::warning( 0, "Warning",
@@ -236,6 +237,12 @@ QgsGrassShell::QgsGrassShell ( QgsGrassTools *tools,
236237
mTabStop[i*8] = true;
237238
}
238239

240+
// Set trap to write history on SIGUSR1
241+
//QString trap = "trap 'history -w' SIGUSR1\015\012";
242+
QString trap = "trap 'history -w' SIGUSR1\015";
243+
write( mFdMaster, trap.ascii(), trap.length());
244+
mText->clear();
245+
239246
resizeTerminal();
240247
mValid = true;
241248
#endif // !WIN32
@@ -247,12 +254,10 @@ QgsGrassShell::~QgsGrassShell()
247254
std::cerr << "QgsGrassShell::~QgsGrassShell()" << std::endl;
248255
#endif
249256

250-
// TODO: find signal to write history before exit
251-
// instead of sending 'exit'
252-
253-
write( mFdMaster, "exit\015\012", 6);
254-
255257
#ifndef WIN32
258+
// This was old trick to write history
259+
/*
260+
write( mFdMaster, "exit\015\012", 6);
256261
while ( 1 )
257262
{
258263
readStdout(0);
@@ -265,15 +270,20 @@ QgsGrassShell::~QgsGrassShell()
265270
t.tv_nsec = 10000000; // 0.01 s
266271
nanosleep ( &t, &r );
267272
}
268-
#endif
273+
*/
274+
275+
// Write history
276+
if ( kill(mPid,SIGUSR1) == -1 )
277+
{
278+
std::cerr << "cannot write history (signal SIGUSR1 to pid = " << mPid << ")" << std::endl;
279+
}
269280

270-
/*
271281
std::cerr << "kill shell pid = " << mPid << std::endl;
272282
if ( kill(mPid,SIGTERM ) == -1 )
273283
{
274284
std::cerr << "cannot kill shell pid = " << mPid << std::endl;
275285
}
276-
*/
286+
#endif
277287
}
278288

279289
void QgsGrassShell::keyPressEvent( QKeyEvent * e )
@@ -810,6 +820,11 @@ void QgsGrassShell::insert ( QString s )
810820

811821
void QgsGrassShell::newLine()
812822
{
823+
if ( mSkipLines > 0 )
824+
{
825+
mText->clear();
826+
mSkipLines--;
827+
}
813828
if ( mNewLine )
814829
{
815830
mText->setTextFormat(Qt::PlainText);

src/plugins/grass/qgsgrassshell.h

+3
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,9 @@ public slots:
195195

196196
// Horizontal tabulator stop
197197
std::vector<bool> mTabStop;
198+
199+
// How many lines to skip, used to skip output of first commands sent to shell
200+
int mSkipLines;
198201
};
199202

200203
class QgsGrassShellText : public Q3TextEdit

0 commit comments

Comments
 (0)