Skip to content

Commit

Permalink
set trap to write history on exit
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@5270 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek committed Apr 12, 2006
1 parent 65e0b1c commit 1615f2b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
31 changes: 23 additions & 8 deletions src/plugins/grass/qgsgrassshell.cpp
Expand Up @@ -56,6 +56,7 @@ QgsGrassShell::QgsGrassShell ( QgsGrassTools *tools,
QDialog(parent), QgsGrassShellBase(), mTools(tools)
{
mValid = false;
mSkipLines = 2;

#ifdef WIN32
QMessageBox::warning( 0, "Warning",
Expand Down Expand Up @@ -236,6 +237,12 @@ QgsGrassShell::QgsGrassShell ( QgsGrassTools *tools,
mTabStop[i*8] = true;
}

// Set trap to write history on SIGUSR1
//QString trap = "trap 'history -w' SIGUSR1\015\012";
QString trap = "trap 'history -w' SIGUSR1\015";
write( mFdMaster, trap.ascii(), trap.length());
mText->clear();

resizeTerminal();
mValid = true;
#endif // !WIN32
Expand All @@ -247,12 +254,10 @@ QgsGrassShell::~QgsGrassShell()
std::cerr << "QgsGrassShell::~QgsGrassShell()" << std::endl;
#endif

// TODO: find signal to write history before exit
// instead of sending 'exit'

write( mFdMaster, "exit\015\012", 6);

#ifndef WIN32
// This was old trick to write history
/*
write( mFdMaster, "exit\015\012", 6);
while ( 1 )
{
readStdout(0);
Expand All @@ -265,15 +270,20 @@ QgsGrassShell::~QgsGrassShell()
t.tv_nsec = 10000000; // 0.01 s
nanosleep ( &t, &r );
}
#endif
*/

// Write history
if ( kill(mPid,SIGUSR1) == -1 )
{
std::cerr << "cannot write history (signal SIGUSR1 to pid = " << mPid << ")" << std::endl;
}

/*
std::cerr << "kill shell pid = " << mPid << std::endl;
if ( kill(mPid,SIGTERM ) == -1 )
{
std::cerr << "cannot kill shell pid = " << mPid << std::endl;
}
*/
#endif
}

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

void QgsGrassShell::newLine()
{
if ( mSkipLines > 0 )
{
mText->clear();
mSkipLines--;
}
if ( mNewLine )
{
mText->setTextFormat(Qt::PlainText);
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/grass/qgsgrassshell.h
Expand Up @@ -195,6 +195,9 @@ public slots:

// Horizontal tabulator stop
std::vector<bool> mTabStop;

// How many lines to skip, used to skip output of first commands sent to shell
int mSkipLines;
};

class QgsGrassShellText : public Q3TextEdit
Expand Down

0 comments on commit 1615f2b

Please sign in to comment.