Skip to content

Commit e863190

Browse files
author
rblazek
committed
fix for ticket 104 (GRASS-PAGER not set)
git-svn-id: http://svn.osgeo.org/qgis/trunk@5680 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 6e48f22 commit e863190

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/providers/grass/qgsgrass.cpp

+42
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "qsettings.h"
2828
#include <QMessageBox>
2929
#include <QCoreApplication>
30+
#include <QProcess>
3031

3132
#include "qgsapplication.h"
3233
#include "qgsgrass.h"
@@ -180,6 +181,47 @@ void QgsGrass::init( void )
180181
strcpy ( pathEnvChar, const_cast<char *>(path.ascii()) );
181182
putenv( pathEnvChar );
182183

184+
// Set GRASS_PAGER if not set, it is necessary for some
185+
// modules printing to terminal, e.g. g.list
186+
// We use 'cat' because 'more' is not present in MSYS (Win)
187+
// and it doesn't work well in built in shell (Unix/Mac)
188+
// and 'less' is not user friendly (for example user must press
189+
// 'q' to quit which is definitely difficult for normal user)
190+
// Also scroling can be don in scrollable window in both
191+
// MSYS terminal and built in shell.
192+
if ( !getenv ("GRASS_PAGER") )
193+
{
194+
QString pager;
195+
QStringList pagers;
196+
//pagers << "more" << "less" << "cat"; // se notes above
197+
pagers << "cat";
198+
199+
for ( int i = 0; i < pagers.size(); i++ )
200+
{
201+
int state;
202+
203+
QProcess p;
204+
p.start ( pagers.at(i) );
205+
p.waitForStarted();
206+
state = p.state();
207+
p.kill();
208+
209+
if ( state == QProcess::Running )
210+
{
211+
pager = pagers.at(i);
212+
break;
213+
}
214+
}
215+
216+
if ( pager.length() > 0 )
217+
{
218+
pager.prepend ( "GRASS_PAGER=" );
219+
char *pagerEnvChar = new char[pager.length()+1];
220+
strcpy ( pagerEnvChar, const_cast<char *>(pager.ascii()) );
221+
putenv( pagerEnvChar );
222+
}
223+
}
224+
183225
initialized = 1;
184226
}
185227

0 commit comments

Comments
 (0)